@lexion-rte/tools 0.1.1 → 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/CHANGELOG.md +8 -0
- package/README.md +42 -9
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -1,29 +1,62 @@
|
|
|
1
1
|
# @lexion-rte/tools
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Conversion utilities for Lexion editor documents.
|
|
4
4
|
|
|
5
|
-
##
|
|
5
|
+
## Overview
|
|
6
6
|
|
|
7
|
-
`@lexion-rte/tools` provides
|
|
7
|
+
`@lexion-rte/tools` provides:
|
|
8
|
+
|
|
9
|
+
- `toText(editor)`
|
|
10
|
+
- `fromText(editor, text)`
|
|
11
|
+
- `toHTML(editor, context?)`
|
|
12
|
+
- `fromHTML(editor, html, context?)`
|
|
8
13
|
|
|
9
14
|
## Install
|
|
10
15
|
|
|
16
|
+
```bash
|
|
17
|
+
pnpm add @lexion-rte/tools @lexion-rte/core
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Typical pairing:
|
|
21
|
+
|
|
11
22
|
```bash
|
|
12
23
|
pnpm add @lexion-rte/tools @lexion-rte/core @lexion-rte/extensions
|
|
13
24
|
```
|
|
14
25
|
|
|
15
|
-
##
|
|
26
|
+
## Browser Example
|
|
16
27
|
|
|
17
28
|
```ts
|
|
18
29
|
import { LexionEditor } from "@lexion-rte/core";
|
|
19
30
|
import { starterKitExtension } from "@lexion-rte/extensions";
|
|
20
|
-
import { fromText, toText } from "@lexion-rte/tools";
|
|
31
|
+
import { fromText, toHTML, toText } from "@lexion-rte/tools";
|
|
21
32
|
|
|
22
|
-
const editor = new LexionEditor({
|
|
23
|
-
extensions: [starterKitExtension]
|
|
24
|
-
});
|
|
33
|
+
const editor = new LexionEditor({ extensions: [starterKitExtension] });
|
|
25
34
|
|
|
26
|
-
fromText(editor, "Line
|
|
35
|
+
fromText(editor, "Line one\n\nLine two");
|
|
27
36
|
console.log(toText(editor));
|
|
37
|
+
console.log(toHTML(editor));
|
|
28
38
|
```
|
|
29
39
|
|
|
40
|
+
## Server / Node Example
|
|
41
|
+
|
|
42
|
+
`toHTML` and `fromHTML` require a DOM `Document` when not running in the browser.
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
import { JSDOM } from "jsdom";
|
|
46
|
+
import { LexionEditor } from "@lexion-rte/core";
|
|
47
|
+
import { starterKitExtension } from "@lexion-rte/extensions";
|
|
48
|
+
import { fromHTML, toHTML } from "@lexion-rte/tools";
|
|
49
|
+
|
|
50
|
+
const dom = new JSDOM("<!doctype html><html><body></body></html>");
|
|
51
|
+
const editor = new LexionEditor({ extensions: [starterKitExtension] });
|
|
52
|
+
|
|
53
|
+
fromHTML(editor, "<p><strong>Hello</strong> world</p>", { document: dom.window.document });
|
|
54
|
+
const html = toHTML(editor, { document: dom.window.document });
|
|
55
|
+
console.log(html);
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Notes
|
|
59
|
+
|
|
60
|
+
- `fromText` creates paragraph blocks separated by blank lines.
|
|
61
|
+
- Single newlines inside a paragraph map to `hard_break` when supported by schema.
|
|
62
|
+
- Conversions depend on the active editor schema.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lexion-rte/tools",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Document conversion tools for the Lexion editor platform.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"type": "module",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"prosemirror-model": "^1.22.3",
|
|
37
|
-
"@lexion-rte/core": "0.1.
|
|
37
|
+
"@lexion-rte/core": "0.1.2"
|
|
38
38
|
},
|
|
39
39
|
"scripts": {
|
|
40
40
|
"build": "tsc -p tsconfig.json",
|