@domternal/extension-markdown 0.12.0
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/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/index.cjs +1123 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +201 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.js +1102 -0
- package/dist/index.js.map +1 -0
- package/package.json +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Domternal contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# @domternal/extension-markdown
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@domternal/extension-markdown)
|
|
4
|
+
[](https://github.com/domternal/domternal/blob/main/LICENSE)
|
|
5
|
+
|
|
6
|
+
Bidirectional Markdown for the [Domternal](https://domternal.dev) editor: parse GitHub-flavored Markdown into the document and serialize the document back to Markdown, covering the full Notion-style schema.
|
|
7
|
+
|
|
8
|
+
- **Import**: `insertMarkdown` / `setMarkdownContent` commands, plus automatic conversion of Markdown-looking plain-text pastes (opt-out).
|
|
9
|
+
- **Export**: `getMarkdown(editor)` and a `downloadMarkdown` helper, with a warning channel for anything Markdown cannot express (alignment, colors, merged table cells).
|
|
10
|
+
- **Headless**: `parseMarkdown` / `serializeMarkdown` work against any schema without an editor instance.
|
|
11
|
+
- Coverage: headings, lists (bullet, ordered with start, GFM task lists), blockquotes, fenced code with language, tables with column alignment, images, links and autolinks, bold/italic/strike/inline code, hard breaks, LaTeX math (`$...$`, `$$` blocks), emoji glyphs.
|
|
12
|
+
|
|
13
|
+
## Links
|
|
14
|
+
|
|
15
|
+
<u>[Website](https://domternal.dev)</u> • <u>[Documentation](https://domternal.dev/v1/extensions/markdown)</u> • <u>[Live examples](https://domternal.dev/examples)</u>
|
|
16
|
+
|
|
17
|
+
## Install
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @domternal/extension-markdown
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
`@domternal/core` and `@domternal/pm` are peer dependencies.
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { Editor } from '@domternal/core';
|
|
29
|
+
import { Markdown, getMarkdown, downloadMarkdown } from '@domternal/extension-markdown';
|
|
30
|
+
|
|
31
|
+
const editor = new Editor({
|
|
32
|
+
extensions: [/* your extensions */, Markdown],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// Import
|
|
36
|
+
editor.commands.insertMarkdown('## Hello\n\n- [x] done\n- [ ] open');
|
|
37
|
+
editor.commands.setMarkdownContent('# Fresh document');
|
|
38
|
+
|
|
39
|
+
// Export
|
|
40
|
+
const { markdown, warnings } = getMarkdown(editor);
|
|
41
|
+
downloadMarkdown(editor, 'notes.md');
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Markdown-looking plain-text pastes convert automatically. Pastes that carry an HTML flavor, plain prose, and pastes into code blocks are never touched. Disable with `Markdown.configure({ paste: false })`.
|
|
45
|
+
|
|
46
|
+
## Options
|
|
47
|
+
|
|
48
|
+
| Option | Default | Description |
|
|
49
|
+
| --- | --- | --- |
|
|
50
|
+
| `paste` | `true` | Convert Markdown-looking plain-text pastes into rich content. |
|
|
51
|
+
| `tightLists` | `true` | Serialize lists without blank lines between items. |
|
|
52
|
+
| `specs` | `null` | Extra or replacement Markdown mappings for custom nodes and marks. |
|
|
53
|
+
|
|
54
|
+
## Headless usage
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
import { parseMarkdown, serializeMarkdown } from '@domternal/extension-markdown';
|
|
58
|
+
|
|
59
|
+
const doc = parseMarkdown('# Title', schema);
|
|
60
|
+
const { markdown, warnings } = serializeMarkdown(doc);
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
Custom nodes without a mapping degrade gracefully: content is preserved as plain text and a warning is reported instead of failing. Custom mappings plug in via `Markdown.configure({ specs })` or the `specs` option of `serializeMarkdown`.
|
|
64
|
+
|
|
65
|
+
## Fidelity notes
|
|
66
|
+
|
|
67
|
+
Markdown cannot express everything the editor can. The serializer keeps the content and reports a warning for: text alignment and line height, text and background colors, underline, merged table cells, multi-block table cells, image resize dimensions, toggle (details) structure, and mentions. Round trips of the supported subset are exact and covered by tests.
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
MIT
|