@salmonui/rich-text 0.0.0-stage → 0.2.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 +79 -2
- package/dist/blocks/find.d.ts +4 -0
- package/dist/blocks/find.d.ts.map +1 -0
- package/dist/blocks/find.js +14 -0
- package/dist/blocks/find.js.map +1 -0
- package/dist/blocks/from-html.d.ts +10 -0
- package/dist/blocks/from-html.d.ts.map +1 -0
- package/dist/blocks/from-html.js +459 -0
- package/dist/blocks/from-html.js.map +1 -0
- package/dist/blocks/index.d.ts +5 -0
- package/dist/blocks/index.d.ts.map +1 -0
- package/dist/blocks/index.js +4 -0
- package/dist/blocks/index.js.map +1 -0
- package/dist/blocks/ops.d.ts +27 -0
- package/dist/blocks/ops.d.ts.map +1 -0
- package/dist/blocks/ops.js +172 -0
- package/dist/blocks/ops.js.map +1 -0
- package/dist/blocks/to-html.d.ts +18 -0
- package/dist/blocks/to-html.d.ts.map +1 -0
- package/dist/blocks/to-html.js +207 -0
- package/dist/blocks/to-html.js.map +1 -0
- package/dist/blocks/types.d.ts +76 -0
- package/dist/blocks/types.d.ts.map +1 -0
- package/dist/blocks/types.js +4 -0
- package/dist/blocks/types.js.map +1 -0
- package/dist/collab.d.ts +43 -0
- package/dist/collab.d.ts.map +1 -0
- package/dist/collab.js +45 -0
- package/dist/collab.js.map +1 -0
- package/dist/content/RichTextContent.d.ts +19 -0
- package/dist/content/RichTextContent.d.ts.map +1 -0
- package/dist/content/RichTextContent.js +20 -0
- package/dist/content/RichTextContent.js.map +1 -0
- package/dist/content/index.d.ts +2 -0
- package/dist/content/index.d.ts.map +1 -0
- package/dist/content/index.js +3 -0
- package/dist/content/index.js.map +1 -0
- package/dist/engine/commands.d.ts +19 -0
- package/dist/engine/commands.d.ts.map +1 -0
- package/dist/engine/commands.js +457 -0
- package/dist/engine/commands.js.map +1 -0
- package/dist/engine/core.d.ts +113 -0
- package/dist/engine/core.d.ts.map +1 -0
- package/dist/engine/core.js +444 -0
- package/dist/engine/core.js.map +1 -0
- package/dist/engine/dom-shim.d.ts +47 -0
- package/dist/engine/dom-shim.d.ts.map +1 -0
- package/dist/engine/dom-shim.js +128 -0
- package/dist/engine/dom-shim.js.map +1 -0
- package/dist/engine/html-out.d.ts +12 -0
- package/dist/engine/html-out.d.ts.map +1 -0
- package/dist/engine/html-out.js +24 -0
- package/dist/engine/html-out.js.map +1 -0
- package/dist/engine/index.d.ts +6 -0
- package/dist/engine/index.d.ts.map +1 -0
- package/dist/engine/index.js +5 -0
- package/dist/engine/index.js.map +1 -0
- package/dist/engine/keymap.d.ts +18 -0
- package/dist/engine/keymap.d.ts.map +1 -0
- package/dist/engine/keymap.js +85 -0
- package/dist/engine/keymap.js.map +1 -0
- package/dist/engine/load.d.ts +10 -0
- package/dist/engine/load.d.ts.map +1 -0
- package/dist/engine/load.js +11 -0
- package/dist/engine/load.js.map +1 -0
- package/dist/engine/nodeviews.d.ts +11 -0
- package/dist/engine/nodeviews.d.ts.map +1 -0
- package/dist/engine/nodeviews.js +236 -0
- package/dist/engine/nodeviews.js.map +1 -0
- package/dist/engine/plugins.d.ts +76 -0
- package/dist/engine/plugins.d.ts.map +1 -0
- package/dist/engine/plugins.js +311 -0
- package/dist/engine/plugins.js.map +1 -0
- package/dist/engine/schema.d.ts +11 -0
- package/dist/engine/schema.d.ts.map +1 -0
- package/dist/engine/schema.js +350 -0
- package/dist/engine/schema.js.map +1 -0
- package/dist/engine/serialize.d.ts +13 -0
- package/dist/engine/serialize.d.ts.map +1 -0
- package/dist/engine/serialize.js +119 -0
- package/dist/engine/serialize.js.map +1 -0
- package/dist/engine/snapshot.d.ts +4 -0
- package/dist/engine/snapshot.d.ts.map +1 -0
- package/dist/engine/snapshot.js +62 -0
- package/dist/engine/snapshot.js.map +1 -0
- package/dist/engine/types.d.ts +215 -0
- package/dist/engine/types.d.ts.map +1 -0
- package/dist/engine/types.js +2 -0
- package/dist/engine/types.js.map +1 -0
- package/dist/html/entities.d.ts +7 -0
- package/dist/html/entities.d.ts.map +1 -0
- package/dist/html/entities.js +69 -0
- package/dist/html/entities.js.map +1 -0
- package/dist/html/index.d.ts +7 -0
- package/dist/html/index.d.ts.map +1 -0
- package/dist/html/index.js +9 -0
- package/dist/html/index.js.map +1 -0
- package/dist/html/parse.d.ts +30 -0
- package/dist/html/parse.d.ts.map +1 -0
- package/dist/html/parse.js +394 -0
- package/dist/html/parse.js.map +1 -0
- package/dist/html/paste.d.ts +47 -0
- package/dist/html/paste.d.ts.map +1 -0
- package/dist/html/paste.js +373 -0
- package/dist/html/paste.js.map +1 -0
- package/dist/html/policy.d.ts +56 -0
- package/dist/html/policy.d.ts.map +1 -0
- package/dist/html/policy.js +245 -0
- package/dist/html/policy.js.map +1 -0
- package/dist/html/sanitize.d.ts +60 -0
- package/dist/html/sanitize.d.ts.map +1 -0
- package/dist/html/sanitize.js +699 -0
- package/dist/html/sanitize.js.map +1 -0
- package/dist/html/serialize.d.ts +16 -0
- package/dist/html/serialize.d.ts.map +1 -0
- package/dist/html/serialize.js +68 -0
- package/dist/html/serialize.js.map +1 -0
- package/dist/html/text.d.ts +18 -0
- package/dist/html/text.d.ts.map +1 -0
- package/dist/html/text.js +96 -0
- package/dist/html/text.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +22 -0
- package/dist/index.js.map +1 -0
- package/dist/mention/editable.d.ts +15 -0
- package/dist/mention/editable.d.ts.map +1 -0
- package/dist/mention/editable.js +167 -0
- package/dist/mention/editable.js.map +1 -0
- package/dist/mention/index.d.ts +2 -0
- package/dist/mention/index.d.ts.map +1 -0
- package/dist/mention/index.js +3 -0
- package/dist/mention/index.js.map +1 -0
- package/dist/react/RichTextEditor.d.ts +15 -0
- package/dist/react/RichTextEditor.d.ts.map +1 -0
- package/dist/react/RichTextEditor.js +494 -0
- package/dist/react/RichTextEditor.js.map +1 -0
- package/dist/react/block-editor/BlockEditor.d.ts +5 -0
- package/dist/react/block-editor/BlockEditor.d.ts.map +1 -0
- package/dist/react/block-editor/BlockEditor.js +103 -0
- package/dist/react/block-editor/BlockEditor.js.map +1 -0
- package/dist/react/block-editor/controller.d.ts +91 -0
- package/dist/react/block-editor/controller.d.ts.map +1 -0
- package/dist/react/block-editor/controller.js +757 -0
- package/dist/react/block-editor/controller.js.map +1 -0
- package/dist/react/block-editor/index.d.ts +4 -0
- package/dist/react/block-editor/index.d.ts.map +1 -0
- package/dist/react/block-editor/index.js +5 -0
- package/dist/react/block-editor/index.js.map +1 -0
- package/dist/react/block-editor/locale.d.ts +65 -0
- package/dist/react/block-editor/locale.d.ts.map +1 -0
- package/dist/react/block-editor/locale.js +63 -0
- package/dist/react/block-editor/locale.js.map +1 -0
- package/dist/react/block-editor/transforms.d.ts +26 -0
- package/dist/react/block-editor/transforms.d.ts.map +1 -0
- package/dist/react/block-editor/transforms.js +233 -0
- package/dist/react/block-editor/transforms.js.map +1 -0
- package/dist/react/block-editor/types.d.ts +180 -0
- package/dist/react/block-editor/types.d.ts.map +1 -0
- package/dist/react/block-editor/types.js +2 -0
- package/dist/react/block-editor/types.js.map +1 -0
- package/dist/react/block-editor/ui.d.ts +21 -0
- package/dist/react/block-editor/ui.d.ts.map +1 -0
- package/dist/react/block-editor/ui.js +601 -0
- package/dist/react/block-editor/ui.js.map +1 -0
- package/dist/react/client.d.ts +28 -0
- package/dist/react/client.d.ts.map +1 -0
- package/dist/react/client.js +109 -0
- package/dist/react/client.js.map +1 -0
- package/dist/react/dialogs.d.ts +44 -0
- package/dist/react/dialogs.d.ts.map +1 -0
- package/dist/react/dialogs.js +312 -0
- package/dist/react/dialogs.js.map +1 -0
- package/dist/react/emoji-data.d.ts +3 -0
- package/dist/react/emoji-data.d.ts.map +1 -0
- package/dist/react/emoji-data.js +6 -0
- package/dist/react/emoji-data.js.map +1 -0
- package/dist/react/icons.d.ts +5 -0
- package/dist/react/icons.d.ts.map +1 -0
- package/dist/react/icons.js +69 -0
- package/dist/react/icons.js.map +1 -0
- package/dist/react/index.d.ts +5 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +5 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/items.d.ts +68 -0
- package/dist/react/items.d.ts.map +1 -0
- package/dist/react/items.js +253 -0
- package/dist/react/items.js.map +1 -0
- package/dist/react/locale.d.ts +130 -0
- package/dist/react/locale.d.ts.map +1 -0
- package/dist/react/locale.js +131 -0
- package/dist/react/locale.js.map +1 -0
- package/dist/react/overlay.d.ts +41 -0
- package/dist/react/overlay.d.ts.map +1 -0
- package/dist/react/overlay.js +162 -0
- package/dist/react/overlay.js.map +1 -0
- package/dist/react/store.d.ts +23 -0
- package/dist/react/store.d.ts.map +1 -0
- package/dist/react/store.js +84 -0
- package/dist/react/store.js.map +1 -0
- package/dist/react/types.d.ts +205 -0
- package/dist/react/types.d.ts.map +1 -0
- package/dist/react/types.js +2 -0
- package/dist/react/types.js.map +1 -0
- package/dist/rich-text.css +1555 -0
- package/package.json +61 -4
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// Derived toolbar state (`onToolbarStateChange`): a small plain
|
|
2
|
+
// object computed after each transaction; React reads it through
|
|
3
|
+
// useSyncExternalStore with narrow selectors.
|
|
4
|
+
import { redoDepth } from 'prosemirror-history';
|
|
5
|
+
import { NodeSelection } from 'prosemirror-state';
|
|
6
|
+
import { isInTable } from 'prosemirror-tables';
|
|
7
|
+
import { ancestor, markActive, markValue } from './commands.js';
|
|
8
|
+
import { canUndo, characterCount, isEmptyDoc, painterKey } from './plugins.js';
|
|
9
|
+
const MARKS = ['bold', 'italic', 'underline', 'strike', 'subscript', 'superscript', 'code'];
|
|
10
|
+
export function toolbarState(engine) {
|
|
11
|
+
const state = engine.state;
|
|
12
|
+
const { schema, selection } = state;
|
|
13
|
+
const marks = {};
|
|
14
|
+
for (const name of MARKS)
|
|
15
|
+
marks[name] = schema.marks[name] ? markActive(state, schema.marks[name]) : false;
|
|
16
|
+
const parent = selection.$from.parent;
|
|
17
|
+
const block = parent.type.name === 'heading' ? `h${parent.attrs['level']}` : parent.type.name === 'code_block' ? 'code' : ancestor(state, (n) => n.type.name === 'blockquote') ? 'blockquote' : 'p';
|
|
18
|
+
const list = ancestor(state, (n) => /^(bullet|ordered|task)_list$/.test(n.type.name));
|
|
19
|
+
const node = selection instanceof NodeSelection ? selection.node.type.name : ancestor(state, (n) => n.type.name === 'figure') ? 'figure' : null;
|
|
20
|
+
const find = engine.findState;
|
|
21
|
+
const suggest = engine.suggest;
|
|
22
|
+
return {
|
|
23
|
+
marks: marks,
|
|
24
|
+
fontFamily: markValue(state, schema.marks['fontFamily']),
|
|
25
|
+
fontSize: markValue(state, schema.marks['fontSize']),
|
|
26
|
+
color: markValue(state, schema.marks['color']),
|
|
27
|
+
backgroundColor: markValue(state, schema.marks['backgroundColor']),
|
|
28
|
+
block,
|
|
29
|
+
textAlign: parent.attrs['textAlign'] ?? null,
|
|
30
|
+
lineHeight: parent.attrs['lineHeight'] ?? null,
|
|
31
|
+
list: list ? list.node.type.name.split('_')[0] : null,
|
|
32
|
+
link: linkHref(engine),
|
|
33
|
+
inTable: isInTable(state),
|
|
34
|
+
node: node,
|
|
35
|
+
canUndo: engine.historyCommands ? engine.historyCommands.undo(state) : canUndo(state),
|
|
36
|
+
canRedo: engine.historyCommands ? engine.historyCommands.redo(state) : redoDepth(state) > 0,
|
|
37
|
+
count: characterCount(state.doc),
|
|
38
|
+
empty: isEmptyDoc(state.doc),
|
|
39
|
+
selectionEmpty: selection.empty,
|
|
40
|
+
painter: Boolean(painterKey.getState(state)),
|
|
41
|
+
findCount: find?.matches.length ?? 0,
|
|
42
|
+
findIndex: find?.index ?? -1,
|
|
43
|
+
suggest: suggest ? { id: suggest.id, query: suggest.query, from: suggest.from } : null,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function linkHref(engine) {
|
|
47
|
+
const state = engine.state;
|
|
48
|
+
const type = state.schema.marks['link'];
|
|
49
|
+
const { $from, from, to, empty } = state.selection;
|
|
50
|
+
const mark = type.isInSet(empty ? $from.marks() : ($from.nodeAfter?.marks ?? [])) ?? (empty ? type.isInSet($from.nodeBefore?.marks ?? []) : null);
|
|
51
|
+
if (mark)
|
|
52
|
+
return mark.attrs['href'];
|
|
53
|
+
if (!empty && state.doc.rangeHasMark(from, to, type)) {
|
|
54
|
+
let href = null;
|
|
55
|
+
state.doc.nodesBetween(from, to, (n) => {
|
|
56
|
+
href ??= type.isInSet(n.marks)?.attrs['href'] ?? null;
|
|
57
|
+
});
|
|
58
|
+
return href;
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=snapshot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snapshot.js","sourceRoot":"","sources":["../../src/engine/snapshot.ts"],"names":[],"mappings":"AAAA,gEAAgE;AAChE,iEAAiE;AACjE,8CAA8C;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAChE,OAAO,EAAE,OAAO,EAAE,cAAc,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAI/E,MAAM,KAAK,GAAG,CAAC,MAAM,EAAE,QAAQ,EAAE,WAAW,EAAE,QAAQ,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,CAAU,CAAC;AAErG,MAAM,UAAU,YAAY,CAAC,MAAsB;IACjD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC;IAC3B,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IACpC,MAAM,KAAK,GAA4B,EAAE,CAAC;IAC1C,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EAAE,EAAE,CAAC,CAAC,EAAE,EAAE;YACrC,IAAI,KAAM,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,MAAM,CAAwB,IAAI,IAAI,CAAC;QAChF,CAAC,CAAC,CAAC;QACH,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
import type { MarkSpec, NodeSpec, Schema } from 'prosemirror-model';
|
|
2
|
+
import type { Command, EditorState, Plugin } from 'prosemirror-state';
|
|
3
|
+
import type { InputRule } from 'prosemirror-inputrules';
|
|
4
|
+
import type { EditorView } from 'prosemirror-view';
|
|
5
|
+
export type RichTextTextAlign = 'left' | 'center' | 'right' | 'justify';
|
|
6
|
+
export type RichTextBulletStyle = 'disc' | 'circle' | 'square';
|
|
7
|
+
export type RichTextOrderedStyle = 'decimal' | 'lower-alpha' | 'upper-alpha' | 'lower-roman' | 'upper-roman';
|
|
8
|
+
export type RichTextTableStyle = 'bordered' | 'striped';
|
|
9
|
+
export interface RichTextLinkInput {
|
|
10
|
+
readonly href: string;
|
|
11
|
+
/** Link text inserted when the selection is empty (default the URL). */
|
|
12
|
+
readonly text?: string | undefined;
|
|
13
|
+
readonly title?: string | undefined;
|
|
14
|
+
/** `'_blank'` opens in a new window (`rel="noopener noreferrer"` is added). */
|
|
15
|
+
readonly target?: '_blank' | null | undefined;
|
|
16
|
+
}
|
|
17
|
+
export interface RichTextImageInput {
|
|
18
|
+
readonly src: string;
|
|
19
|
+
readonly alt?: string | undefined;
|
|
20
|
+
readonly title?: string | undefined;
|
|
21
|
+
readonly width?: number | null | undefined;
|
|
22
|
+
readonly height?: number | null | undefined;
|
|
23
|
+
/** A caption wraps the image in `<figure>` with `<figcaption>`. */
|
|
24
|
+
readonly caption?: string | undefined;
|
|
25
|
+
}
|
|
26
|
+
export interface RichTextMediaInput {
|
|
27
|
+
readonly src: string;
|
|
28
|
+
readonly width?: number | null | undefined;
|
|
29
|
+
readonly height?: number | null | undefined;
|
|
30
|
+
}
|
|
31
|
+
export interface RichTextFindOptions {
|
|
32
|
+
readonly matchCase?: boolean | undefined;
|
|
33
|
+
readonly wholeWord?: boolean | undefined;
|
|
34
|
+
}
|
|
35
|
+
/** Typed commands (`actionsRef.current.commands`); each returns whether it applied. */
|
|
36
|
+
export interface RichTextCommands {
|
|
37
|
+
bold(): boolean;
|
|
38
|
+
italic(): boolean;
|
|
39
|
+
underline(): boolean;
|
|
40
|
+
strike(): boolean;
|
|
41
|
+
subscript(): boolean;
|
|
42
|
+
superscript(): boolean;
|
|
43
|
+
code(): boolean;
|
|
44
|
+
uppercase(): boolean;
|
|
45
|
+
lowercase(): boolean;
|
|
46
|
+
fontFamily(value: string | null): boolean;
|
|
47
|
+
fontSize(value: string | null): boolean;
|
|
48
|
+
color(value: string | null): boolean;
|
|
49
|
+
backgroundColor(value: string | null): boolean;
|
|
50
|
+
paragraph(): boolean;
|
|
51
|
+
heading(level: 1 | 2 | 3 | 4 | 5 | 6): boolean;
|
|
52
|
+
blockquote(): boolean;
|
|
53
|
+
codeBlock(language?: string | null): boolean;
|
|
54
|
+
setCodeLanguage(language: string | null): boolean;
|
|
55
|
+
textAlign(align: RichTextTextAlign | null): boolean;
|
|
56
|
+
lineHeight(value: string | null): boolean;
|
|
57
|
+
indent(): boolean;
|
|
58
|
+
outdent(): boolean;
|
|
59
|
+
bulletList(style?: RichTextBulletStyle | null): boolean;
|
|
60
|
+
orderedList(style?: RichTextOrderedStyle | null): boolean;
|
|
61
|
+
taskList(): boolean;
|
|
62
|
+
toggleTask(): boolean;
|
|
63
|
+
horizontalRule(): boolean;
|
|
64
|
+
clearFormat(): boolean;
|
|
65
|
+
setLink(link: RichTextLinkInput): boolean;
|
|
66
|
+
unsetLink(): boolean;
|
|
67
|
+
insertImage(image: RichTextImageInput): boolean;
|
|
68
|
+
updateImage(image: Partial<RichTextImageInput>): boolean;
|
|
69
|
+
insertAudio(media: RichTextMediaInput): boolean;
|
|
70
|
+
insertVideo(media: RichTextMediaInput): boolean;
|
|
71
|
+
insertEmbed(media: RichTextMediaInput): boolean;
|
|
72
|
+
deleteNode(): boolean;
|
|
73
|
+
insertTable(size: {
|
|
74
|
+
readonly rows: number;
|
|
75
|
+
readonly cols: number;
|
|
76
|
+
readonly headerRow?: boolean | undefined;
|
|
77
|
+
}): boolean;
|
|
78
|
+
addRowBefore(): boolean;
|
|
79
|
+
addRowAfter(): boolean;
|
|
80
|
+
deleteRow(): boolean;
|
|
81
|
+
addColumnBefore(): boolean;
|
|
82
|
+
addColumnAfter(): boolean;
|
|
83
|
+
deleteColumn(): boolean;
|
|
84
|
+
mergeCells(): boolean;
|
|
85
|
+
splitCell(): boolean;
|
|
86
|
+
toggleHeaderRow(): boolean;
|
|
87
|
+
setTableStyle(style: RichTextTableStyle | null): boolean;
|
|
88
|
+
deleteTable(): boolean;
|
|
89
|
+
insertText(text: string): boolean;
|
|
90
|
+
/**
|
|
91
|
+
* Sanitized and parsed through the schema, replacing the selection like a
|
|
92
|
+
* paste; `{ blocks: true }` inserts whole blocks after splitting the
|
|
93
|
+
* current one (imports).
|
|
94
|
+
*/
|
|
95
|
+
insertHtml(html: string, options?: {
|
|
96
|
+
readonly blocks?: boolean;
|
|
97
|
+
}): boolean;
|
|
98
|
+
selectAll(): boolean;
|
|
99
|
+
undo(): boolean;
|
|
100
|
+
redo(): boolean;
|
|
101
|
+
/** Highlights matches and selects the first; returns the match count. */
|
|
102
|
+
find(query: string, options?: RichTextFindOptions): number;
|
|
103
|
+
findNext(): boolean;
|
|
104
|
+
findPrevious(): boolean;
|
|
105
|
+
/** Replaces the current match and moves to the next. */
|
|
106
|
+
replace(text: string): boolean;
|
|
107
|
+
/** Returns the number of replaced matches. */
|
|
108
|
+
replaceAll(text: string): number;
|
|
109
|
+
clearFind(): boolean;
|
|
110
|
+
/** Format painter: copy the format at the selection (`sticky` keeps applying until `cancelFormatPainter`). */
|
|
111
|
+
copyFormat(sticky?: boolean): boolean;
|
|
112
|
+
applyFormat(): boolean;
|
|
113
|
+
cancelFormatPainter(): boolean;
|
|
114
|
+
}
|
|
115
|
+
export type RichTextCommandName = keyof RichTextCommands;
|
|
116
|
+
export interface RichTextSelection {
|
|
117
|
+
readonly anchor: number;
|
|
118
|
+
readonly head: number;
|
|
119
|
+
readonly from: number;
|
|
120
|
+
readonly to: number;
|
|
121
|
+
readonly empty: boolean;
|
|
122
|
+
/** Selected plain text. */
|
|
123
|
+
readonly text: string;
|
|
124
|
+
}
|
|
125
|
+
/** What an extension's plugin factory receives. */
|
|
126
|
+
export interface RichTextExtensionContext {
|
|
127
|
+
readonly schema: Schema;
|
|
128
|
+
/** The engine's current state (after mount the view's state). */
|
|
129
|
+
getState(): EditorState;
|
|
130
|
+
/** The view once mounted. */
|
|
131
|
+
getView(): EditorView | null;
|
|
132
|
+
}
|
|
133
|
+
/** A toolbar item an extension contributes (`toolbar` refers to it by `id`). */
|
|
134
|
+
export interface RichTextExtensionToolbarItem {
|
|
135
|
+
readonly id: string;
|
|
136
|
+
readonly label: string;
|
|
137
|
+
/** Command id (an extension or built-in command) run on click. */
|
|
138
|
+
readonly command: string;
|
|
139
|
+
readonly icon?: unknown;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* An editor extension: schema nodes and marks, ProseMirror plugins
|
|
143
|
+
* (a factory may be async, for example the `/collab` Yjs binding), key
|
|
144
|
+
* bindings, input rules, commands and toolbar items. Keep the array stable.
|
|
145
|
+
*/
|
|
146
|
+
export interface RichTextExtension {
|
|
147
|
+
readonly name: string;
|
|
148
|
+
readonly nodes?: Readonly<Record<string, NodeSpec>>;
|
|
149
|
+
readonly marks?: Readonly<Record<string, MarkSpec>>;
|
|
150
|
+
readonly plugins?: (context: RichTextExtensionContext) => readonly Plugin[] | Promise<readonly Plugin[]>;
|
|
151
|
+
/** Key -> command id or ProseMirror command, before the built-in table (ProseMirror key names, `Mod-` for Ctrl/Cmd). */
|
|
152
|
+
readonly keyBindings?: Readonly<Record<string, string | Command>>;
|
|
153
|
+
readonly inputRules?: (schema: Schema) => readonly InputRule[];
|
|
154
|
+
/** Command id -> factory of a ProseMirror command; run with `actionsRef.current.run(id, ...args)`. */
|
|
155
|
+
readonly commands?: Readonly<Record<string, (...args: never[]) => Command>>;
|
|
156
|
+
readonly toolbarItems?: readonly RichTextExtensionToolbarItem[];
|
|
157
|
+
/**
|
|
158
|
+
* Elements and attributes the extension's nodes and marks write, added to
|
|
159
|
+
* the always-on sanitizer for value in, paste and HTML out. Active content
|
|
160
|
+
* (script, style, iframe, object, embed, forms), `on*` handlers, `style` and
|
|
161
|
+
* URL attributes other than href / cite / src / poster are never allowed;
|
|
162
|
+
* those four are checked by the URL rules.
|
|
163
|
+
*/
|
|
164
|
+
readonly html?: {
|
|
165
|
+
readonly tags?: readonly string[];
|
|
166
|
+
readonly attributes?: Readonly<Record<string, readonly string[]>>;
|
|
167
|
+
};
|
|
168
|
+
/** Turns off history in the engine (the Yjs undo manager replaces it). */
|
|
169
|
+
readonly replacesHistory?: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* The undo and redo that replace the engine's (with `replacesHistory`):
|
|
172
|
+
* `commands.undo` / `redo`, the toolbar and its enabled state use them.
|
|
173
|
+
* Called without `dispatch` they answer whether a step is available.
|
|
174
|
+
*/
|
|
175
|
+
readonly history?: {
|
|
176
|
+
readonly undo: Command;
|
|
177
|
+
readonly redo: Command;
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
/** Derived toolbar state (`onToolbarStateChange`). */
|
|
181
|
+
export interface RichTextToolbarState {
|
|
182
|
+
readonly marks: Readonly<Record<'bold' | 'italic' | 'underline' | 'strike' | 'subscript' | 'superscript' | 'code', boolean>>;
|
|
183
|
+
readonly fontFamily: string | null;
|
|
184
|
+
readonly fontSize: string | null;
|
|
185
|
+
readonly color: string | null;
|
|
186
|
+
readonly backgroundColor: string | null;
|
|
187
|
+
/** `'p'`, `'h1'`..`'h6'`, `'code'` or `'blockquote'`. */
|
|
188
|
+
readonly block: string;
|
|
189
|
+
readonly textAlign: RichTextTextAlign | null;
|
|
190
|
+
readonly lineHeight: string | null;
|
|
191
|
+
readonly list: 'bullet' | 'ordered' | 'task' | null;
|
|
192
|
+
/** The href of the link at the selection. */
|
|
193
|
+
readonly link: string | null;
|
|
194
|
+
readonly inTable: boolean;
|
|
195
|
+
/** The selected node (or the figure around the caret). */
|
|
196
|
+
readonly node: 'image' | 'figure' | 'audio' | 'video' | 'embed' | 'horizontal_rule' | null;
|
|
197
|
+
readonly canUndo: boolean;
|
|
198
|
+
readonly canRedo: boolean;
|
|
199
|
+
/** Character count (text and inline atoms, no block separators). */
|
|
200
|
+
readonly count: number;
|
|
201
|
+
readonly empty: boolean;
|
|
202
|
+
readonly selectionEmpty: boolean;
|
|
203
|
+
readonly painter: boolean;
|
|
204
|
+
readonly findCount: number;
|
|
205
|
+
readonly findIndex: number;
|
|
206
|
+
/** The active slash or emoji trigger. */
|
|
207
|
+
readonly suggest: {
|
|
208
|
+
readonly id: string;
|
|
209
|
+
readonly query: string;
|
|
210
|
+
readonly from: number;
|
|
211
|
+
} | null;
|
|
212
|
+
}
|
|
213
|
+
/** `keyBindings` prop: key -> command or action id, a function, or `false` to remove a default. */
|
|
214
|
+
export type RichTextKeyBindings = Readonly<Record<string, string | false | (() => boolean)>>;
|
|
215
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/engine/types.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,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;IAC7C,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IAC7B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,0DAA0D;IAC1D,QAAQ,CAAC,IAAI,EAAE,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,OAAO,GAAG,OAAO,GAAG,iBAAiB,GAAG,IAAI,CAAC;IAC3F,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,yCAAyC;IACzC,QAAQ,CAAC,OAAO,EAAE;QAAE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAC;CACjG;AAED,mGAAmG;AACnG,MAAM,MAAM,mBAAmB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,CAAC,MAAM,OAAO,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/engine/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Decodes HTML character references. `inAttribute` applies the attribute
|
|
3
|
+
* rule: a legacy reference without `;` followed by `=` or an alphanumeric is
|
|
4
|
+
* left literal (`?a=1©=2` keeps `©`).
|
|
5
|
+
*/
|
|
6
|
+
export declare function decodeEntities(text: string, inAttribute?: boolean): string;
|
|
7
|
+
//# sourceMappingURL=entities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.d.ts","sourceRoot":"","sources":["../../src/html/entities.ts"],"names":[],"mappings":"AAuCA;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,UAAQ,GAAG,MAAM,CAsBxE"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
// HTML character references: numeric
|
|
2
|
+
// references with the HTML replacement rules, and the named references that
|
|
3
|
+
// editors, Word and Google Docs actually write (they emit other characters
|
|
4
|
+
// as UTF-8). The table is deliberately short: an unknown name stays literal
|
|
5
|
+
// text, which is always safe, because the serializer re-escapes every `&`
|
|
6
|
+
// and a URL with a literal `:` has no scheme.
|
|
7
|
+
const NAMED = {
|
|
8
|
+
amp: '&', lt: '<', gt: '>', quot: '"', apos: "'", nbsp: '\u00a0', AMP: '&', LT: '<', GT: '>', QUOT: '"',
|
|
9
|
+
Tab: '\t', NewLine: '\n', colon: ':', lpar: '(', rpar: ')', sol: '/',
|
|
10
|
+
copy: '\u00a9', reg: '\u00ae', trade: '\u2122', hellip: '\u2026', mdash: '\u2014', ndash: '\u2013',
|
|
11
|
+
lsquo: '\u2018', rsquo: '\u2019', sbquo: '\u201a', ldquo: '\u201c', rdquo: '\u201d', bdquo: '\u201e',
|
|
12
|
+
laquo: '\u00ab', raquo: '\u00bb', bull: '\u2022', middot: '\u00b7', deg: '\u00b0', plusmn: '\u00b1',
|
|
13
|
+
times: '\u00d7', divide: '\u00f7', para: '\u00b6', sect: '\u00a7', euro: '\u20ac', pound: '\u00a3',
|
|
14
|
+
yen: '\u00a5', cent: '\u00a2', iexcl: '\u00a1', iquest: '\u00bf', shy: '\u00ad', ensp: '\u2002',
|
|
15
|
+
emsp: '\u2003', thinsp: '\u2009', zwnj: '\u200c', zwj: '\u200d', lrm: '\u200e', rlm: '\u200f',
|
|
16
|
+
frac12: '\u00bd', frac14: '\u00bc', frac34: '\u00be', rarr: '\u2192', larr: '\u2190',
|
|
17
|
+
};
|
|
18
|
+
// Legacy references the HTML tokenizer also accepts without the semicolon.
|
|
19
|
+
const LEGACY = new Set(['amp', 'lt', 'gt', 'quot', 'nbsp', 'copy', 'reg', 'AMP', 'LT', 'GT', 'QUOT']);
|
|
20
|
+
// Windows-1252 remapping of numeric references 0x80..0x9F (HTML spec).
|
|
21
|
+
const C1 = {
|
|
22
|
+
0x80: 0x20ac, 0x82: 0x201a, 0x83: 0x0192, 0x84: 0x201e, 0x85: 0x2026, 0x86: 0x2020,
|
|
23
|
+
0x87: 0x2021, 0x88: 0x02c6, 0x89: 0x2030, 0x8a: 0x0160, 0x8b: 0x2039, 0x8c: 0x0152,
|
|
24
|
+
0x8e: 0x017d, 0x91: 0x2018, 0x92: 0x2019, 0x93: 0x201c, 0x94: 0x201d, 0x95: 0x2022,
|
|
25
|
+
0x96: 0x2013, 0x97: 0x2014, 0x98: 0x02dc, 0x99: 0x2122, 0x9a: 0x0161, 0x9b: 0x203a,
|
|
26
|
+
0x9c: 0x0153, 0x9e: 0x017e, 0x9f: 0x0178,
|
|
27
|
+
};
|
|
28
|
+
function fromCodePoint(code) {
|
|
29
|
+
if (code === 0 || code > 0x10ffff || (code >= 0xd800 && code <= 0xdfff))
|
|
30
|
+
return '\ufffd';
|
|
31
|
+
const mapped = C1[code];
|
|
32
|
+
return String.fromCodePoint(mapped ?? code);
|
|
33
|
+
}
|
|
34
|
+
const REF = /&(?:#[xX]([0-9a-fA-F]{1,8});?|#([0-9]{1,8});?|([A-Za-z][A-Za-z0-9]{0,31});?)/g;
|
|
35
|
+
/**
|
|
36
|
+
* Decodes HTML character references. `inAttribute` applies the attribute
|
|
37
|
+
* rule: a legacy reference without `;` followed by `=` or an alphanumeric is
|
|
38
|
+
* left literal (`?a=1©=2` keeps `©`).
|
|
39
|
+
*/
|
|
40
|
+
export function decodeEntities(text, inAttribute = false) {
|
|
41
|
+
if (text.indexOf('&') < 0)
|
|
42
|
+
return text;
|
|
43
|
+
return text.replace(REF, (match, hex, dec, name, offset) => {
|
|
44
|
+
if (hex !== undefined)
|
|
45
|
+
return fromCodePoint(Number.parseInt(hex, 16));
|
|
46
|
+
if (dec !== undefined)
|
|
47
|
+
return fromCodePoint(Number.parseInt(dec, 10));
|
|
48
|
+
const terminated = match.endsWith(';');
|
|
49
|
+
const n = name;
|
|
50
|
+
if (terminated) {
|
|
51
|
+
const value = NAMED[n];
|
|
52
|
+
if (value !== undefined)
|
|
53
|
+
return value;
|
|
54
|
+
// Longest legacy prefix (`¬it;` is `\u00acit;` in browsers): only for legacy names.
|
|
55
|
+
}
|
|
56
|
+
// Without `;` (or unknown with `;`): try the longest legacy prefix.
|
|
57
|
+
for (let len = Math.min(n.length, 4); len >= 2; len--) {
|
|
58
|
+
const prefix = n.slice(0, len);
|
|
59
|
+
if (!LEGACY.has(prefix))
|
|
60
|
+
continue;
|
|
61
|
+
const rest = match.slice(1 + len);
|
|
62
|
+
if (inAttribute && (rest.length > 0 && /^[=A-Za-z0-9]/.test(rest) || (rest.length === 0 && /^[=A-Za-z0-9]/.test(text.charAt(offset + match.length)))))
|
|
63
|
+
return match;
|
|
64
|
+
return NAMED[prefix] + rest;
|
|
65
|
+
}
|
|
66
|
+
return match;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=entities.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entities.js","sourceRoot":"","sources":["../../src/html/entities.ts"],"names":[],"mappings":"AAAA,qCAAqC;AACrC,4EAA4E;AAC5E,2EAA2E;AAC3E,4EAA4E;AAC5E,0EAA0E;AAC1E,oDAAoD;AAEpD,MAAM,KAAK,GAAqC;IAC9C,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,GA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M,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,CAAC,CAAC;YAClC,IAAI,WAAW,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,KAAK,CAAC,IAAI,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;gBAAE,OAAO,KAAK,CAAC;YACpK,OAAQ,KAAK,CAAC,MAAM,CAAY,GAAG,IAAI,CAAC;QAC1C,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { parseHtml, type HtmlElement, type HtmlText, type HtmlComment, type HtmlNode } from './parse.js';
|
|
2
|
+
export { serializeHtml, escapeHtml, escapeAttribute, type SerializeHtmlOptions } from './serialize.js';
|
|
3
|
+
export { sanitizeHtml, sanitizeNodes, type SanitizeHtmlOptions, type SanitizeHook, type SanitizeHookResult, type SanitizeElement, } from './sanitize.js';
|
|
4
|
+
export { cleanUrl as sanitizeUrl, embedAllowed, type SanitizeAllow, type UrlUse } from './policy.js';
|
|
5
|
+
export { htmlToText, plainTextToHtml, type HtmlToTextOptions } from './text.js';
|
|
6
|
+
export { cleanPastedHtml, detectPasteSource, pasteNeedsPrompt, type PasteCleanupMode, type ResolvedPasteCleanupMode, type PasteCleanupOptions, type PasteSource, } from './paste.js';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/html/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,KAAK,WAAW,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AACzG,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAAE,KAAK,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACvG,OAAO,EACL,YAAY,EACZ,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,YAAY,EAAE,KAAK,aAAa,EAAE,KAAK,MAAM,EAAE,MAAM,aAAa,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,KAAK,iBAAiB,EAAE,MAAM,WAAW,CAAC;AAChF,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,EAChB,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,KAAK,mBAAmB,EACxB,KAAK,WAAW,GACjB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// Barrel of src/html (see ../index.ts): the server-safe, DOM-free HTML layer
|
|
2
|
+
// (parser, serializer, sanitizer, paste cleanup, text conversion).
|
|
3
|
+
export { parseHtml } from './parse.js';
|
|
4
|
+
export { serializeHtml, escapeHtml, escapeAttribute } from './serialize.js';
|
|
5
|
+
export { sanitizeHtml, sanitizeNodes, } from './sanitize.js';
|
|
6
|
+
export { cleanUrl as sanitizeUrl, embedAllowed } from './policy.js';
|
|
7
|
+
export { htmlToText, plainTextToHtml } from './text.js';
|
|
8
|
+
export { cleanPastedHtml, detectPasteSource, pasteNeedsPrompt, } from './paste.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/html/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,mEAAmE;AACnE,OAAO,EAAE,SAAS,EAAoE,MAAM,YAAY,CAAC;AACzG,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,eAAe,EAA6B,MAAM,gBAAgB,CAAC;AACvG,OAAO,EACL,YAAY,EACZ,aAAa,GAKd,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,IAAI,WAAW,EAAE,YAAY,EAAmC,MAAM,aAAa,CAAC;AACrG,OAAO,EAAE,UAAU,EAAE,eAAe,EAA0B,MAAM,WAAW,CAAC;AAChF,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,gBAAgB,GAKjB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/** An element of a parsed HTML fragment. Tag and attribute names are lowercase. */
|
|
2
|
+
export interface HtmlElement {
|
|
3
|
+
type: 'element';
|
|
4
|
+
tag: string;
|
|
5
|
+
attrs: Record<string, string>;
|
|
6
|
+
children: HtmlNode[];
|
|
7
|
+
}
|
|
8
|
+
/** A text node; `value` is decoded text (never markup). */
|
|
9
|
+
export interface HtmlText {
|
|
10
|
+
type: 'text';
|
|
11
|
+
value: string;
|
|
12
|
+
}
|
|
13
|
+
/** A comment (`<!-- -->` or a bogus comment such as `<![if ...]>`). */
|
|
14
|
+
export interface HtmlComment {
|
|
15
|
+
type: 'comment';
|
|
16
|
+
value: string;
|
|
17
|
+
}
|
|
18
|
+
export type HtmlNode = HtmlElement | HtmlText | HtmlComment;
|
|
19
|
+
/** Elements without content or end tag. */
|
|
20
|
+
export declare const VOID_ELEMENTS: ReadonlySet<string>;
|
|
21
|
+
/** Raw-text elements: content is literal text up to the matching end tag. */
|
|
22
|
+
export declare const RAW_TEXT_ELEMENTS: ReadonlySet<string>;
|
|
23
|
+
/** Nesting deeper than this is flattened (bounds every scope walk and the recursion depth). */
|
|
24
|
+
export declare const MAX_DEPTH = 256;
|
|
25
|
+
/**
|
|
26
|
+
* Parses an HTML fragment into a tree. Never throws; malformed input yields
|
|
27
|
+
* the closest well-formed tree. `<!DOCTYPE>` is skipped, CDATA becomes text.
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseHtml(input: string): HtmlNode[];
|
|
30
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../src/html/parse.ts"],"names":[],"mappings":"AAkBA,mFAAmF;AACnF,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,SAAS,CAAC;IAChB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,QAAQ,EAAE,QAAQ,EAAE,CAAC;CACtB;AAED,2DAA2D;AAC3D,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;CACf;AAED,uEAAuE;AACvE,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,SAAS,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,CAAC;AAE5D,2CAA2C;AAC3C,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,MAAM,CAE5C,CAAC;AAEH,6EAA6E;AAC7E,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAAoF,CAAC;AAgBvI,+FAA+F;AAC/F,eAAO,MAAM,SAAS,MAAM,CAAC;AA0M7B;;;GAGG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,QAAQ,EAAE,CA6HnD"}
|