htmltoadf 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +131 -0
- package/htmltoadf.js +2 -0
- package/htmltoadf_bg.js +109 -0
- package/htmltoadf_bg.wasm +0 -0
- package/package.json +25 -0
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# htmltoadf [![Latest Version]][crates.io] [![Rustc Version 1.58+]][rustc] ![htmltoadf]
|
|
2
|
+
|
|
3
|
+
[Latest Version]: https://img.shields.io/crates/v/htmltoadf.svg
|
|
4
|
+
[crates.io]: https://crates.io/crates/htmltoadf
|
|
5
|
+
[Rustc Version 1.58+]: https://img.shields.io/badge/rustc-1.58+-lightgray.svg
|
|
6
|
+
[rustc]: https://blog.rust-lang.org/2022/01/13/Rust-1.58.0.html
|
|
7
|
+
[htmltoadf]: https://img.shields.io/badge/htmltoadf--green.svg
|
|
8
|
+
|
|
9
|
+
**htmltoadf is an HTML to Atlassian Document Format (ADF) converter written in Rust.**
|
|
10
|
+
|
|
11
|
+
The library can be used in several different ways:
|
|
12
|
+
* As a command line binary (either directly on a compatible host or using Docker)
|
|
13
|
+
* Included as a library within a Rust project
|
|
14
|
+
* Called from a different language or environment (e.g. C, JavaScript, Ruby, PHP, .NET etc.) using [FFI](https://doc.rust-lang.org/nomicon/ffi.html)
|
|
15
|
+
* Called as a Web Assembly (wasm) module
|
|
16
|
+
|
|
17
|
+
----
|
|
18
|
+
|
|
19
|
+
```toml
|
|
20
|
+
[dependencies]
|
|
21
|
+
htmltoadf = "0.1.2"
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## CLI
|
|
25
|
+
### Binaries
|
|
26
|
+
### Install Binary from Crates.io with `cargo install`
|
|
27
|
+
```
|
|
28
|
+
$ cargo install htmltoadf
|
|
29
|
+
installing htmltoadf v0.1.2 (/usr/src/html2adf)
|
|
30
|
+
Updating crates.io index
|
|
31
|
+
Downloading crates ...
|
|
32
|
+
Downloaded lock_api v0.4.6
|
|
33
|
+
--snip--
|
|
34
|
+
Compiling htmltoadf v0.1.2
|
|
35
|
+
Finished release [optimized] target(s) in 1m 42s
|
|
36
|
+
Installing ~/.cargo/bin/htmltoadf
|
|
37
|
+
Installed package `htmltoadf v0.1.2` (executable `htmltoadf`)
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
### Download Binary file from Github
|
|
41
|
+
Pre-built binaries can be downloaded from here:
|
|
42
|
+
https://github.com/wouterken/htmltoadf/releases/tag/0.1.2
|
|
43
|
+
|
|
44
|
+
### Docker Image
|
|
45
|
+
**Docker Repo:**
|
|
46
|
+
|
|
47
|
+
https://hub.docker.com/repository/docker/wouterken/html2adf
|
|
48
|
+
|
|
49
|
+
**Usage**
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
$ echo "<h1>Hello world<p>Test</p></h1>" | docker run --rm -i wouterken/html2adf:0.1.2
|
|
53
|
+
{"version":1,"type":"doc","content":[{"type":"heading","attrs":{"level":1},"content":[{"type":"text","text":"Hello world"},{"type":"text","text":"Test"}]}]}
|
|
54
|
+
|
|
55
|
+
$ echo "<h1>Hello world<p>Test</p></h1>" | docker run --rm -i wouterken/html2adf:0.1.2 | jq
|
|
56
|
+
{
|
|
57
|
+
"version": 1,
|
|
58
|
+
"type": "doc",
|
|
59
|
+
"content": [
|
|
60
|
+
{
|
|
61
|
+
"type": "heading",
|
|
62
|
+
"attrs": {
|
|
63
|
+
"level": 1
|
|
64
|
+
},
|
|
65
|
+
"content": [
|
|
66
|
+
{
|
|
67
|
+
"type": "text",
|
|
68
|
+
"text": "Hello world"
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
"type": "text",
|
|
72
|
+
"text": "Test"
|
|
73
|
+
}
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
}
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Lib
|
|
81
|
+
|
|
82
|
+
### Example Code
|
|
83
|
+
```rust
|
|
84
|
+
use htmltoadf::convert_html_str_to_adf_str;
|
|
85
|
+
use serde_json::json;
|
|
86
|
+
|
|
87
|
+
let converted = convert_html_str_to_adf_str("<h1>Hello World</h1>".to_string());
|
|
88
|
+
let expected = json!({
|
|
89
|
+
"version": 1,
|
|
90
|
+
"type": "doc",
|
|
91
|
+
"content": [
|
|
92
|
+
{
|
|
93
|
+
"type": "heading",
|
|
94
|
+
"attrs": {
|
|
95
|
+
"level": 1
|
|
96
|
+
},
|
|
97
|
+
"content": [
|
|
98
|
+
{
|
|
99
|
+
"type": "text",
|
|
100
|
+
"text": "Hello World"
|
|
101
|
+
}
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
}).to_string();
|
|
106
|
+
|
|
107
|
+
assert_eq!(expected, converted);
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### WASM
|
|
111
|
+
*TODO*
|
|
112
|
+
### FFI
|
|
113
|
+
*TODO*
|
|
114
|
+
|
|
115
|
+
## Implemented features
|
|
116
|
+
This converter only implements a subset of possible mappings between HTML and ADF.
|
|
117
|
+
The following conversions are implemented:
|
|
118
|
+
* Headings
|
|
119
|
+
* Images
|
|
120
|
+
* Lists (ordered and unordered)
|
|
121
|
+
* Tables
|
|
122
|
+
* Text and Paragraphs
|
|
123
|
+
* Code
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
## Testing
|
|
127
|
+
Run `cargo test` from the repository root.
|
|
128
|
+
|
|
129
|
+
## Contributing
|
|
130
|
+
|
|
131
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/wouterken/htmltoadf. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
package/htmltoadf.js
ADDED
package/htmltoadf_bg.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import * as wasm from './htmltoadf_bg.wasm';
|
|
2
|
+
|
|
3
|
+
const lTextDecoder = typeof TextDecoder === 'undefined' ? (0, module.require)('util').TextDecoder : TextDecoder;
|
|
4
|
+
|
|
5
|
+
let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true });
|
|
6
|
+
|
|
7
|
+
cachedTextDecoder.decode();
|
|
8
|
+
|
|
9
|
+
let cachegetUint8Memory0 = null;
|
|
10
|
+
function getUint8Memory0() {
|
|
11
|
+
if (cachegetUint8Memory0 === null || cachegetUint8Memory0.buffer !== wasm.memory.buffer) {
|
|
12
|
+
cachegetUint8Memory0 = new Uint8Array(wasm.memory.buffer);
|
|
13
|
+
}
|
|
14
|
+
return cachegetUint8Memory0;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function getStringFromWasm0(ptr, len) {
|
|
18
|
+
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let WASM_VECTOR_LEN = 0;
|
|
22
|
+
|
|
23
|
+
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
|
|
24
|
+
|
|
25
|
+
let cachedTextEncoder = new lTextEncoder('utf-8');
|
|
26
|
+
|
|
27
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
28
|
+
? function (arg, view) {
|
|
29
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
30
|
+
}
|
|
31
|
+
: function (arg, view) {
|
|
32
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
33
|
+
view.set(buf);
|
|
34
|
+
return {
|
|
35
|
+
read: arg.length,
|
|
36
|
+
written: buf.length
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
41
|
+
|
|
42
|
+
if (typeof(arg) !== 'string') throw new Error('expected a string argument');
|
|
43
|
+
|
|
44
|
+
if (realloc === undefined) {
|
|
45
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
46
|
+
const ptr = malloc(buf.length);
|
|
47
|
+
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
48
|
+
WASM_VECTOR_LEN = buf.length;
|
|
49
|
+
return ptr;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
let len = arg.length;
|
|
53
|
+
let ptr = malloc(len);
|
|
54
|
+
|
|
55
|
+
const mem = getUint8Memory0();
|
|
56
|
+
|
|
57
|
+
let offset = 0;
|
|
58
|
+
|
|
59
|
+
for (; offset < len; offset++) {
|
|
60
|
+
const code = arg.charCodeAt(offset);
|
|
61
|
+
if (code > 0x7F) break;
|
|
62
|
+
mem[ptr + offset] = code;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (offset !== len) {
|
|
66
|
+
if (offset !== 0) {
|
|
67
|
+
arg = arg.slice(offset);
|
|
68
|
+
}
|
|
69
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3);
|
|
70
|
+
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
|
|
71
|
+
const ret = encodeString(arg, view);
|
|
72
|
+
if (ret.read !== arg.length) throw new Error('failed to pass whole string');
|
|
73
|
+
offset += ret.written;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
WASM_VECTOR_LEN = offset;
|
|
77
|
+
return ptr;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
let cachegetInt32Memory0 = null;
|
|
81
|
+
function getInt32Memory0() {
|
|
82
|
+
if (cachegetInt32Memory0 === null || cachegetInt32Memory0.buffer !== wasm.memory.buffer) {
|
|
83
|
+
cachegetInt32Memory0 = new Int32Array(wasm.memory.buffer);
|
|
84
|
+
}
|
|
85
|
+
return cachegetInt32Memory0;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* @param {string} html
|
|
89
|
+
* @returns {string}
|
|
90
|
+
*/
|
|
91
|
+
export function convert(html) {
|
|
92
|
+
try {
|
|
93
|
+
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
94
|
+
var ptr0 = passStringToWasm0(html, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
95
|
+
var len0 = WASM_VECTOR_LEN;
|
|
96
|
+
wasm.convert(retptr, ptr0, len0);
|
|
97
|
+
var r0 = getInt32Memory0()[retptr / 4 + 0];
|
|
98
|
+
var r1 = getInt32Memory0()[retptr / 4 + 1];
|
|
99
|
+
return getStringFromWasm0(r0, r1);
|
|
100
|
+
} finally {
|
|
101
|
+
wasm.__wbindgen_add_to_stack_pointer(16);
|
|
102
|
+
wasm.__wbindgen_free(r0, r1);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function __wbindgen_throw(arg0, arg1) {
|
|
107
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
108
|
+
};
|
|
109
|
+
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "htmltoadf",
|
|
3
|
+
"description": "An HTML to Atlassian Document Format (ADF) converter",
|
|
4
|
+
"version": "0.1.2",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/wouterken/htmltoadf"
|
|
9
|
+
},
|
|
10
|
+
"files": [
|
|
11
|
+
"htmltoadf_bg.wasm",
|
|
12
|
+
"htmltoadf.js",
|
|
13
|
+
"htmltoadf_bg.js"
|
|
14
|
+
],
|
|
15
|
+
"module": "htmltoadf.js",
|
|
16
|
+
"homepage": "https://github.com/wouterken/htmltoadf",
|
|
17
|
+
"sideEffects": false,
|
|
18
|
+
"keywords": [
|
|
19
|
+
"html",
|
|
20
|
+
"adf",
|
|
21
|
+
"atlassian",
|
|
22
|
+
"converter",
|
|
23
|
+
"cli"
|
|
24
|
+
]
|
|
25
|
+
}
|