@futaba-soft/mbox 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 +80 -2
- package/dist/create-editor-BKTpQ8TK.js +2866 -0
- package/dist/editor/create-editor.d.ts +100 -0
- package/dist/editor/document-cache.d.ts +20 -0
- package/dist/editor/focused-line.d.ts +14 -0
- package/dist/editor/plugin.d.ts +191 -0
- package/dist/editor/test-context.d.ts +28 -0
- package/dist/gfm.d.ts +34 -0
- package/dist/gfm.js +1719 -0
- package/dist/hatena.d.ts +32 -0
- package/dist/hatena.js +856 -0
- package/dist/index.d.ts +34 -0
- package/dist/index.js +77 -0
- package/dist/plugin-DI0ubB-M.js +297 -0
- package/dist/plugins/bracket-pair-kit.d.ts +9 -0
- package/dist/plugins/code-block-kit.d.ts +77 -0
- package/dist/plugins/code-block-language-loader.d.ts +33 -0
- package/dist/plugins/gfm/active-lines.d.ts +11 -0
- package/dist/plugins/gfm/code-block.d.ts +28 -0
- package/dist/plugins/gfm/footnote.d.ts +17 -0
- package/dist/plugins/gfm/heading.d.ts +12 -0
- package/dist/plugins/gfm/image.d.ts +30 -0
- package/dist/plugins/gfm/index.d.ts +19 -0
- package/dist/plugins/gfm/inline-code.d.ts +4 -0
- package/dist/plugins/gfm/inline.d.ts +4 -0
- package/dist/plugins/gfm/link.d.ts +34 -0
- package/dist/plugins/gfm/list.d.ts +32 -0
- package/dist/plugins/gfm/math.d.ts +39 -0
- package/dist/plugins/gfm/parser-cache.d.ts +3 -0
- package/dist/plugins/gfm/parser.d.ts +355 -0
- package/dist/plugins/gfm/quote.d.ts +3 -0
- package/dist/plugins/gfm/table.d.ts +34 -0
- package/dist/plugins/gfm/thematic-break.d.ts +9 -0
- package/dist/plugins/hatena/blockquote.d.ts +12 -0
- package/dist/plugins/hatena/definition.d.ts +5 -0
- package/dist/plugins/hatena/footnote.d.ts +15 -0
- package/dist/plugins/hatena/heading.d.ts +8 -0
- package/dist/plugins/hatena/index.d.ts +12 -0
- package/dist/plugins/hatena/link.d.ts +16 -0
- package/dist/plugins/hatena/list.d.ts +24 -0
- package/dist/plugins/hatena/parser-cache.d.ts +5 -0
- package/dist/plugins/hatena/parser.d.ts +129 -0
- package/dist/plugins/hatena/pre.d.ts +3 -0
- package/dist/plugins/hatena/shared.d.ts +31 -0
- package/dist/plugins/hatena/super-pre.d.ts +23 -0
- package/dist/plugins/hatena/table.d.ts +12 -0
- package/dist/plugins/image-kit.d.ts +84 -0
- package/dist/plugins/inline-notation-kit.d.ts +39 -0
- package/dist/plugins/inline-style-kit.d.ts +38 -0
- package/dist/plugins/link-url.d.ts +1 -0
- package/dist/plugins/logical-lines.d.ts +18 -0
- package/dist/plugins/mbox/bracket.d.ts +4 -0
- package/dist/plugins/mbox/code-block.d.ts +32 -0
- package/dist/plugins/mbox/complete.d.ts +33 -0
- package/dist/plugins/mbox/default.d.ts +13 -0
- package/dist/plugins/mbox/emoji.d.ts +3 -0
- package/dist/plugins/mbox/footnote.d.ts +14 -0
- package/dist/plugins/mbox/heading.d.ts +10 -0
- package/dist/plugins/mbox/inline-code.d.ts +6 -0
- package/dist/plugins/mbox/inline-style.d.ts +7 -0
- package/dist/plugins/mbox/inline-visitor.d.ts +8 -0
- package/dist/plugins/mbox/list.d.ts +13 -0
- package/dist/plugins/mbox/markdown-image.d.ts +13 -0
- package/dist/plugins/mbox/page-link.d.ts +19 -0
- package/dist/plugins/mbox/paragraph.d.ts +6 -0
- package/dist/plugins/mbox/parser-cache.d.ts +3 -0
- package/dist/plugins/mbox/parser.d.ts +2 -0
- package/dist/plugins/mbox/quote.d.ts +5 -0
- package/dist/plugins/mbox/table.d.ts +13 -0
- package/dist/plugins/mbox/task-list.d.ts +19 -0
- package/dist/plugins/mbox/types.d.ts +172 -0
- package/dist/plugins/mbox/url-link.d.ts +3 -0
- package/dist/plugins/mbox/vertical-motion.d.ts +3 -0
- package/dist/plugins/pipe-table-row.d.ts +18 -0
- package/dist/plugins/scrapbox/bracket.d.ts +20 -0
- package/dist/plugins/scrapbox/code-block.d.ts +37 -0
- package/dist/plugins/scrapbox/command-line.d.ts +9 -0
- package/dist/plugins/scrapbox/complete.d.ts +58 -0
- package/dist/plugins/scrapbox/decoration.d.ts +16 -0
- package/dist/plugins/scrapbox/formula.d.ts +43 -0
- package/dist/plugins/scrapbox/image.d.ts +62 -0
- package/dist/plugins/scrapbox/indent.d.ts +40 -0
- package/dist/plugins/scrapbox/index.d.ts +41 -0
- package/dist/plugins/scrapbox/inline-code-highlight.d.ts +16 -0
- package/dist/plugins/scrapbox/inline-code.d.ts +7 -0
- package/dist/plugins/scrapbox/inline-scanner-kit.d.ts +66 -0
- package/dist/plugins/scrapbox/inline-walker.d.ts +2 -0
- package/dist/plugins/scrapbox/inline.d.ts +86 -0
- package/dist/plugins/scrapbox/link.d.ts +110 -0
- package/dist/plugins/scrapbox/list.d.ts +21 -0
- package/dist/plugins/scrapbox/parser-cache.d.ts +5 -0
- package/dist/plugins/scrapbox/parser.d.ts +65 -0
- package/dist/plugins/scrapbox/quote.d.ts +7 -0
- package/dist/plugins/scrapbox/table.d.ts +22 -0
- package/dist/plugins/scrapbox/title.d.ts +3 -0
- package/dist/plugins/scrapbox/visible-lines.d.ts +34 -0
- package/dist/plugins/table-kit.d.ts +142 -0
- package/dist/plugins/task-checkbox-kit.d.ts +18 -0
- package/dist/scrapbox.d.ts +42 -0
- package/dist/scrapbox.js +1903 -0
- package/dist/testing.d.ts +2 -0
- package/dist/testing.js +13 -0
- package/dist/themes/code-token-presentation.d.ts +6 -0
- package/dist/themes/default-presentation.d.ts +4 -0
- package/dist/themes/gfm-presentation.d.ts +15 -0
- package/dist/themes/hatena-presentation.d.ts +10 -0
- package/dist/themes/heading-presentation.d.ts +18 -0
- package/dist/themes/scrapbox-presentation.d.ts +10 -0
- package/docs/guide.md +297 -0
- package/package.json +121 -4
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { WidgetType } from "@codemirror/view";
|
|
2
|
+
import type { MboxPlugin } from "../../editor/plugin.js";
|
|
3
|
+
import type { GfmLinkLabelNode } from "./parser.js";
|
|
4
|
+
export declare const gfmLinkClassName = "mbox-gfm-link";
|
|
5
|
+
export declare const gfmUnsafeLinkClassName = "mbox-gfm-link-unsafe";
|
|
6
|
+
/** Options for rendered Markdown links and GFM autolinks. */
|
|
7
|
+
export interface GfmLinkOptions {
|
|
8
|
+
/**
|
|
9
|
+
* Adds host-specific URL schemes to the default `http`, `https`, `mailto`,
|
|
10
|
+
* and `tel` allowlist. Values must be ASCII scheme names without a colon.
|
|
11
|
+
* Invalid values are ignored, and `javascript`, `vbscript`, `data`, `file`,
|
|
12
|
+
* and `blob` can never be enabled.
|
|
13
|
+
*/
|
|
14
|
+
additionalAllowedProtocols?: readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* Resolves a parsed destination before it is validated and rendered. The
|
|
17
|
+
* returned string is preserved as the anchor's `href`.
|
|
18
|
+
*/
|
|
19
|
+
linkUrl?: (url: string) => string;
|
|
20
|
+
}
|
|
21
|
+
export declare class GfmLinkWidget extends WidgetType {
|
|
22
|
+
readonly text: string;
|
|
23
|
+
readonly href: string;
|
|
24
|
+
readonly autolink: boolean;
|
|
25
|
+
readonly external: boolean;
|
|
26
|
+
readonly label?: readonly GfmLinkLabelNode[] | undefined;
|
|
27
|
+
readonly source?: string | undefined;
|
|
28
|
+
readonly renderImages: boolean;
|
|
29
|
+
constructor(text: string, href: string, autolink: boolean, external: boolean, label?: readonly GfmLinkLabelNode[] | undefined, source?: string | undefined, renderImages?: boolean);
|
|
30
|
+
eq(other: WidgetType): boolean;
|
|
31
|
+
toDOM(): HTMLElement;
|
|
32
|
+
private labelSignature;
|
|
33
|
+
}
|
|
34
|
+
export declare function gfmLinkPlugin(options?: GfmLinkOptions): MboxPlugin;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { WidgetType, type EditorView } from "@codemirror/view";
|
|
2
|
+
import { type MboxPlugin } from "../../editor/plugin.js";
|
|
3
|
+
export declare const gfmListLineClassName = "mbox-gfm-list-line";
|
|
4
|
+
export declare const gfmTaskLineClassName = "mbox-gfm-task-line";
|
|
5
|
+
export declare const gfmBulletClassName = "mbox-gfm-bullet";
|
|
6
|
+
export declare const gfmTaskCheckboxClassName = "mbox-gfm-task-checkbox";
|
|
7
|
+
export declare const gfmListDepthClassName: (depth: number) => string;
|
|
8
|
+
export declare class GfmBulletWidget extends WidgetType {
|
|
9
|
+
readonly width: number;
|
|
10
|
+
/** The glyph shown in the box: a dot for bullets, the raw "1." for ordered. */
|
|
11
|
+
readonly label: string;
|
|
12
|
+
constructor(width: number,
|
|
13
|
+
/** The glyph shown in the box: a dot for bullets, the raw "1." for ordered. */
|
|
14
|
+
label: string);
|
|
15
|
+
eq(other: WidgetType): boolean;
|
|
16
|
+
toDOM(): HTMLElement;
|
|
17
|
+
}
|
|
18
|
+
export declare class GfmTaskCheckboxWidget extends WidgetType {
|
|
19
|
+
readonly checked: boolean;
|
|
20
|
+
/** Document range of the `[ ]` / `[x]` bracket, for the toggle dispatch. */
|
|
21
|
+
readonly from: number;
|
|
22
|
+
readonly to: number;
|
|
23
|
+
readonly readOnly: boolean;
|
|
24
|
+
constructor(checked: boolean,
|
|
25
|
+
/** Document range of the `[ ]` / `[x]` bracket, for the toggle dispatch. */
|
|
26
|
+
from: number, to: number, readOnly?: boolean);
|
|
27
|
+
eq(other: WidgetType): boolean;
|
|
28
|
+
toDOM(view: EditorView): HTMLElement;
|
|
29
|
+
updateDOM(dom: HTMLElement, view: EditorView): boolean;
|
|
30
|
+
ignoreEvent(): boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare function gfmListPlugin(): MboxPlugin;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { WidgetType } from "@codemirror/view";
|
|
2
|
+
import type { MboxPlugin } from "../../editor/plugin.js";
|
|
3
|
+
export declare const gfmMathClassName = "mbox-gfm-math";
|
|
4
|
+
/**
|
|
5
|
+
* Render a KaTeX/MathJax-style expression into a DOM node (pluggable).
|
|
6
|
+
*
|
|
7
|
+
* Returned DOM is trusted input: it must be created from trusted content or
|
|
8
|
+
* sanitized by the renderer. mbox deliberately does not apply a generic HTML
|
|
9
|
+
* sanitizer, because that could break legitimate MathML/HTML from renderers
|
|
10
|
+
* such as KaTeX.
|
|
11
|
+
*
|
|
12
|
+
* Every call must return a newly created, parentless `HTMLElement`. A renderer
|
|
13
|
+
* must never return the same `Node` more than once: mbox appends the result to
|
|
14
|
+
* the widget that owns it, and DOM insertion moves an already-parented node.
|
|
15
|
+
*
|
|
16
|
+
* By default, mbox adds a visually hidden TeX source fallback so assistive
|
|
17
|
+
* technology always has an equivalent representation. Set
|
|
18
|
+
* `providesAccessibleMath` when every DOM node this renderer returns already
|
|
19
|
+
* exposes an accessible mathematical equivalent (for example, KaTeX's MathML).
|
|
20
|
+
* That declaration suppresses the fallback and avoids duplicate announcements.
|
|
21
|
+
*
|
|
22
|
+
* If rendering throws, mbox displays the TeX source as visible text instead.
|
|
23
|
+
*/
|
|
24
|
+
export interface GfmMathRenderer {
|
|
25
|
+
(expression: string): HTMLElement;
|
|
26
|
+
providesAccessibleMath?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface GfmMathPluginOptions {
|
|
29
|
+
render?: GfmMathRenderer;
|
|
30
|
+
}
|
|
31
|
+
export declare class GfmMathWidget extends WidgetType {
|
|
32
|
+
private readonly expression;
|
|
33
|
+
private readonly render;
|
|
34
|
+
private readonly inline;
|
|
35
|
+
constructor(expression: string, render: GfmMathRenderer, inline?: boolean);
|
|
36
|
+
eq(other: WidgetType): boolean;
|
|
37
|
+
toDOM(): HTMLElement;
|
|
38
|
+
}
|
|
39
|
+
export declare function gfmMathPlugin(options?: GfmMathPluginOptions): MboxPlugin;
|
|
@@ -0,0 +1,355 @@
|
|
|
1
|
+
import type { Root } from "mdast";
|
|
2
|
+
export interface GfmRange {
|
|
3
|
+
from: number;
|
|
4
|
+
to: number;
|
|
5
|
+
}
|
|
6
|
+
export interface GfmHeading {
|
|
7
|
+
/** 1-based line of the heading. */
|
|
8
|
+
line: number;
|
|
9
|
+
/** Offset of the line start (== the first `#`). */
|
|
10
|
+
from: number;
|
|
11
|
+
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
12
|
+
/** The `#`..`###### ` marker including its trailing space(s). */
|
|
13
|
+
marker: GfmRange;
|
|
14
|
+
/** Present for a setext heading: the complete physical underline line,
|
|
15
|
+
* including any blockquote or list prefix that mdast omits from the heading
|
|
16
|
+
* node's content range. */
|
|
17
|
+
setextUnderline?: GfmRange & {
|
|
18
|
+
line: number;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export interface GfmTask {
|
|
22
|
+
/** The `[ ] ` / `[x] ` checkbox including its trailing space. */
|
|
23
|
+
marker: GfmRange;
|
|
24
|
+
checked: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface GfmListItem {
|
|
27
|
+
/** 1-based line of the item's first line. */
|
|
28
|
+
line: number;
|
|
29
|
+
/** Offset of the bullet marker (indentation is BEFORE this). */
|
|
30
|
+
from: number;
|
|
31
|
+
/** 0-based nesting depth (top-level items are depth 0). */
|
|
32
|
+
depth: number;
|
|
33
|
+
ordered: boolean;
|
|
34
|
+
/** The `- ` / `1. ` bullet marker including its trailing space(s). */
|
|
35
|
+
bullet: GfmRange;
|
|
36
|
+
/** Present only for GFM task-list items. */
|
|
37
|
+
task: GfmTask | null;
|
|
38
|
+
}
|
|
39
|
+
export interface GfmCodeBlock {
|
|
40
|
+
/** Whole-block offsets, fence to fence — feed straight to a `lineRange` spec. */
|
|
41
|
+
from: number;
|
|
42
|
+
to: number;
|
|
43
|
+
firstLine: number;
|
|
44
|
+
lastLine: number;
|
|
45
|
+
/** False for an indented code block (no fences, no header dressing). */
|
|
46
|
+
fenced: boolean;
|
|
47
|
+
/** The opening ```` ``` ````/`~~~` run (empty range for an indented block). */
|
|
48
|
+
openingFence: GfmRange;
|
|
49
|
+
/** The rest of the opening fence line (the info string) and its trimmed text. */
|
|
50
|
+
info: GfmRange;
|
|
51
|
+
/** Fenced-code language and metadata as parsed by mdast. */
|
|
52
|
+
lang: string | null;
|
|
53
|
+
meta: string | null;
|
|
54
|
+
/** Raw info source, retained solely for source-range presentation. */
|
|
55
|
+
infoValue: string;
|
|
56
|
+
/** The one GFM info-string decision shared by labels and language consumers. */
|
|
57
|
+
language: GfmCodeBlockLanguage | null;
|
|
58
|
+
/** The contiguous raw source interior, from the opening line break through
|
|
59
|
+
* the closing fence's start. This is not the range that spells `value`:
|
|
60
|
+
* mdast removes container prefixes and fence indentation from `value`, so
|
|
61
|
+
* the two differ. Use `contentSegments` when line correspondence to `value`
|
|
62
|
+
* is needed. */
|
|
63
|
+
content: GfmRange;
|
|
64
|
+
/** Source segments whose `text` values, joined with `"\\n"`, exactly equal
|
|
65
|
+
* `value`. Empty lines are represented by zero-width segments. These are
|
|
66
|
+
* separate from `content` because a list/blockquote prefix is absent from
|
|
67
|
+
* mdast's normalized code value. `value === ""` has no segments: mdast uses
|
|
68
|
+
* that same value for a block with no value lines and for one containing only
|
|
69
|
+
* empty physical lines, so those source forms cannot be distinguished here. */
|
|
70
|
+
contentSegments: GfmCodeBlockContentSegment[];
|
|
71
|
+
value: string;
|
|
72
|
+
/** The closing fence run, or null when the block is left unterminated. */
|
|
73
|
+
closingFence: GfmRange | null;
|
|
74
|
+
}
|
|
75
|
+
export interface GfmCodeBlockLanguage {
|
|
76
|
+
/** The decoded first info token, split as GitHub splits it. */
|
|
77
|
+
id: string;
|
|
78
|
+
/** The absolute document span of the raw source spelling that token. */
|
|
79
|
+
span: GfmRange;
|
|
80
|
+
}
|
|
81
|
+
/** Whether this fenced code-block record represents GitHub's `math` fence. */
|
|
82
|
+
export declare function isGfmMathFence(block: GfmCodeBlock): boolean;
|
|
83
|
+
export interface GfmCodeBlockContentSegment extends GfmRange {
|
|
84
|
+
text: string;
|
|
85
|
+
}
|
|
86
|
+
export interface GfmBlockquote {
|
|
87
|
+
/** Whole-container offsets — feed to a `lineRange` spec. Nested quotes nest. */
|
|
88
|
+
from: number;
|
|
89
|
+
to: number;
|
|
90
|
+
/** 1-based nesting depth (outermost quote is depth 1). */
|
|
91
|
+
depth: number;
|
|
92
|
+
}
|
|
93
|
+
export interface GfmQuoteMarker {
|
|
94
|
+
/** 1-based line the `>` sits on. */
|
|
95
|
+
line: number;
|
|
96
|
+
from: number;
|
|
97
|
+
to: number;
|
|
98
|
+
/** 1-based nesting depth this particular `>` opens. */
|
|
99
|
+
depth: number;
|
|
100
|
+
}
|
|
101
|
+
export type GfmInlineStyleType = "emphasis" | "strong" | "delete";
|
|
102
|
+
export interface GfmInlineStyle {
|
|
103
|
+
type: GfmInlineStyleType;
|
|
104
|
+
/** 1-based lines the span starts / ends on (differ when it crosses a break). */
|
|
105
|
+
startLine: number;
|
|
106
|
+
endLine: number;
|
|
107
|
+
/** The opening marker (`*`, `**`, `~~`, ...). */
|
|
108
|
+
open: GfmRange;
|
|
109
|
+
/** The styled content between the markers. */
|
|
110
|
+
content: GfmRange;
|
|
111
|
+
/** The closing marker. */
|
|
112
|
+
close: GfmRange;
|
|
113
|
+
}
|
|
114
|
+
export interface GfmLink {
|
|
115
|
+
from: number;
|
|
116
|
+
to: number;
|
|
117
|
+
/** The visible label range (for a bracketed link, the text inside `[...]`). */
|
|
118
|
+
textFrom: number;
|
|
119
|
+
textTo: number;
|
|
120
|
+
/** Text rendered by the link widget, with nested inline markdown projected. */
|
|
121
|
+
text: string;
|
|
122
|
+
/** A label-relative range tree for the link widget. It is deliberately
|
|
123
|
+
* narrower than mdast: rendering this projection cannot accidentally turn
|
|
124
|
+
* parsed HTML or a nested link into DOM. */
|
|
125
|
+
label: readonly GfmLinkLabelNode[];
|
|
126
|
+
/** Raw source for the label range only. The widget uses it with label-node
|
|
127
|
+
* source ranges; keeping this local avoids handing it the mdast tree or the
|
|
128
|
+
* surrounding document. */
|
|
129
|
+
labelSource: string;
|
|
130
|
+
url: string;
|
|
131
|
+
/** True for a bare/`www.` GFM autolink (no `[label](url)` brackets). */
|
|
132
|
+
autolink: boolean;
|
|
133
|
+
startLine: number;
|
|
134
|
+
endLine: number;
|
|
135
|
+
/** True when the whole widget belongs to a GFM table cell. */
|
|
136
|
+
inTableCell: boolean;
|
|
137
|
+
}
|
|
138
|
+
export type GfmLinkLabelNode = GfmLinkLabelTextNode | GfmLinkLabelContainerNode | GfmLinkLabelCodeNode | GfmLinkLabelBreakNode | GfmLinkLabelDisplayTextNode | GfmLinkLabelUnknownNode;
|
|
139
|
+
interface GfmLinkLabelTextNode extends GfmRange {
|
|
140
|
+
kind: "text";
|
|
141
|
+
}
|
|
142
|
+
interface GfmLinkLabelContainerNode extends GfmRange {
|
|
143
|
+
kind: "emphasis" | "strong" | "delete";
|
|
144
|
+
children: readonly GfmLinkLabelNode[];
|
|
145
|
+
}
|
|
146
|
+
interface GfmLinkLabelCodeNode extends GfmRange {
|
|
147
|
+
kind: "inlineCode";
|
|
148
|
+
content: GfmRange;
|
|
149
|
+
}
|
|
150
|
+
interface GfmLinkLabelBreakNode extends GfmRange {
|
|
151
|
+
kind: "break";
|
|
152
|
+
}
|
|
153
|
+
/** A whole-source widget whose displayed label is intentionally not its raw
|
|
154
|
+
* Markdown spelling. */
|
|
155
|
+
interface GfmLinkLabelDisplayTextNode extends GfmRange {
|
|
156
|
+
kind: "image" | "footnoteReference";
|
|
157
|
+
text: string;
|
|
158
|
+
/**
|
|
159
|
+
* An image's source URL. Present only for `kind: "image"`, so a renderer that
|
|
160
|
+
* draws pictures can build one; a renderer that does not still has `text`,
|
|
161
|
+
* which is the alt.
|
|
162
|
+
*
|
|
163
|
+
* This is a URL out of the document and is NOT checked here. The renderer
|
|
164
|
+
* decides whether to fetch it, exactly as it decides for a standalone image.
|
|
165
|
+
* The link's own destination stays on its separate, allowlist-checked path.
|
|
166
|
+
*/
|
|
167
|
+
url?: string;
|
|
168
|
+
}
|
|
169
|
+
/** Any mdast kind outside the allowlist. Renderers must append its label-local source as
|
|
170
|
+
* text, including a nested link; never interpret it as HTML or another DOM
|
|
171
|
+
* element. */
|
|
172
|
+
interface GfmLinkLabelUnknownNode extends GfmRange {
|
|
173
|
+
kind: "unknown";
|
|
174
|
+
}
|
|
175
|
+
export interface GfmInlineCode {
|
|
176
|
+
open: GfmRange;
|
|
177
|
+
content: GfmRange;
|
|
178
|
+
close: GfmRange;
|
|
179
|
+
startLine: number;
|
|
180
|
+
endLine: number;
|
|
181
|
+
}
|
|
182
|
+
/** GitHub's `$`-wrapped code-span math escape hatch: `` $`…`$ ``. */
|
|
183
|
+
export interface GfmInlineMath {
|
|
184
|
+
/** Whole delimiter run, including the adjacent dollar characters. */
|
|
185
|
+
from: number;
|
|
186
|
+
to: number;
|
|
187
|
+
expression: string;
|
|
188
|
+
/** The source spelling that introduced this math expression. */
|
|
189
|
+
delimiter: "backtick" | "dollar";
|
|
190
|
+
/** The inline-code source span this backtick-form math record replaced.
|
|
191
|
+
* Absent for dollar-form math, which did not promote an inline-code span. */
|
|
192
|
+
sourceCodeSpan?: GfmRange;
|
|
193
|
+
/** Inline math replaces one line; display math owns one or more whole lines. */
|
|
194
|
+
display: "inline" | "block";
|
|
195
|
+
startLine: number;
|
|
196
|
+
endLine: number;
|
|
197
|
+
/** True when the whole widget belongs to a GFM table cell. */
|
|
198
|
+
inTableCell: boolean;
|
|
199
|
+
}
|
|
200
|
+
export interface GfmImage {
|
|
201
|
+
/** Whole `` run — feed to the image-kit as one replace target. */
|
|
202
|
+
from: number;
|
|
203
|
+
to: number;
|
|
204
|
+
url: string;
|
|
205
|
+
alt: string;
|
|
206
|
+
/** 1-based line the image sits on (images are single-line inline nodes). */
|
|
207
|
+
line: number;
|
|
208
|
+
/** True when the whole widget belongs to a GFM table cell. */
|
|
209
|
+
inTableCell: boolean;
|
|
210
|
+
}
|
|
211
|
+
export interface GfmThematicBreak {
|
|
212
|
+
line: number;
|
|
213
|
+
from: number;
|
|
214
|
+
to: number;
|
|
215
|
+
}
|
|
216
|
+
export interface GfmHardBreak {
|
|
217
|
+
line: number;
|
|
218
|
+
from: number;
|
|
219
|
+
backslash: boolean;
|
|
220
|
+
}
|
|
221
|
+
/** One backslash escape: the range of the `\` itself (the escaped char stays). */
|
|
222
|
+
export interface GfmEscape {
|
|
223
|
+
line: number;
|
|
224
|
+
from: number;
|
|
225
|
+
to: number;
|
|
226
|
+
}
|
|
227
|
+
/** One inline `[^label]` reference. `from`..`to` covers the whole bracket run. */
|
|
228
|
+
export interface GfmFootnoteReference {
|
|
229
|
+
line: number;
|
|
230
|
+
from: number;
|
|
231
|
+
to: number;
|
|
232
|
+
identifier: string;
|
|
233
|
+
label: string;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* One `[^label]: body` definition block (the body may continue over indented
|
|
237
|
+
* lines). `marker` is the `[^label]:` prefix; `text` is the flattened body,
|
|
238
|
+
* for use as the reference chip's tooltip.
|
|
239
|
+
*/
|
|
240
|
+
export interface GfmFootnoteDefinition {
|
|
241
|
+
identifier: string;
|
|
242
|
+
label: string;
|
|
243
|
+
from: number;
|
|
244
|
+
to: number;
|
|
245
|
+
startLine: number;
|
|
246
|
+
endLine: number;
|
|
247
|
+
marker: GfmRange;
|
|
248
|
+
text: string;
|
|
249
|
+
}
|
|
250
|
+
export interface GfmTableCell {
|
|
251
|
+
from: number;
|
|
252
|
+
to: number;
|
|
253
|
+
/** The trimmed cell text (padding stripped) — the run rendered in the column. */
|
|
254
|
+
content: GfmRange;
|
|
255
|
+
value: string;
|
|
256
|
+
/** Exact text shown after text-shaped inline syntax inside the cell is hidden. */
|
|
257
|
+
displayValue?: string;
|
|
258
|
+
/**
|
|
259
|
+
* This cell holds at least one image that will be drawn as a picture when a
|
|
260
|
+
* consumer renders pictures.
|
|
261
|
+
*
|
|
262
|
+
* A fact about the SOURCE, deliberately: whether it is then drawn as a
|
|
263
|
+
* picture or as its alt text is a plugin option, and the parser is cached per
|
|
264
|
+
* state and never sees plugin options. A consumer that wants the column to
|
|
265
|
+
* make room for a picture reads this and decides for itself.
|
|
266
|
+
*
|
|
267
|
+
* An image inside a link label counts. It is drawn inside the link's anchor
|
|
268
|
+
* rather than on its own, but it still occupies the cell as a picture, so the
|
|
269
|
+
* column needs the same room. (It did not count while such an image was
|
|
270
|
+
* flattened to its alt text.)
|
|
271
|
+
*/
|
|
272
|
+
hasImage?: boolean;
|
|
273
|
+
}
|
|
274
|
+
export interface GfmTableRow {
|
|
275
|
+
from: number;
|
|
276
|
+
to: number;
|
|
277
|
+
cells: GfmTableCell[];
|
|
278
|
+
}
|
|
279
|
+
export type GfmTableAlign = "left" | "right" | "center" | null;
|
|
280
|
+
export interface GfmTable {
|
|
281
|
+
/** 1-based line of the header row. Delimiter is line+1, body rows follow. */
|
|
282
|
+
line: number;
|
|
283
|
+
from: number;
|
|
284
|
+
to: number;
|
|
285
|
+
align: GfmTableAlign[];
|
|
286
|
+
header: GfmTableRow;
|
|
287
|
+
delimiter: GfmTableRow;
|
|
288
|
+
rows: GfmTableRow[];
|
|
289
|
+
}
|
|
290
|
+
export interface GfmDocument {
|
|
291
|
+
headings: GfmHeading[];
|
|
292
|
+
listItems: GfmListItem[];
|
|
293
|
+
codeBlocks: GfmCodeBlock[];
|
|
294
|
+
blockquotes: GfmBlockquote[];
|
|
295
|
+
quoteMarkers: GfmQuoteMarker[];
|
|
296
|
+
inlineStyles: GfmInlineStyle[];
|
|
297
|
+
inlineCodes: GfmInlineCode[];
|
|
298
|
+
inlineMath: GfmInlineMath[];
|
|
299
|
+
links: GfmLink[];
|
|
300
|
+
images: GfmImage[];
|
|
301
|
+
tables: GfmTable[];
|
|
302
|
+
thematicBreaks: GfmThematicBreak[];
|
|
303
|
+
hardBreaks: GfmHardBreak[];
|
|
304
|
+
escapes: GfmEscape[];
|
|
305
|
+
footnoteReferences: GfmFootnoteReference[];
|
|
306
|
+
footnoteDefinitions: GfmFootnoteDefinition[];
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Recovers the source ranges of an mdast inline-code node. mdast retains the
|
|
310
|
+
* node's whole source range but not its opening/closing backtick run lengths,
|
|
311
|
+
* so every source-to-display consumer must derive these same boundaries.
|
|
312
|
+
*
|
|
313
|
+
* When CommonMark's single-line ASCII-space padding rule applies, the removed
|
|
314
|
+
* spaces are absorbed by the fence ranges. This lets callers hide them with
|
|
315
|
+
* their markers while leaving the content range as the visible code text.
|
|
316
|
+
*
|
|
317
|
+
* The result says nothing about whether that happened. A boolean would be the
|
|
318
|
+
* wrong shape for the multiline half anyway: a line ending becomes a single
|
|
319
|
+
* space, which no boundary move can express -- that needs a display string and
|
|
320
|
+
* a widget, not a flag.
|
|
321
|
+
*/
|
|
322
|
+
export interface GfmInlineCodeFenceRanges {
|
|
323
|
+
open: GfmRange;
|
|
324
|
+
content: GfmRange;
|
|
325
|
+
close: GfmRange;
|
|
326
|
+
}
|
|
327
|
+
/** Shared GFM code-span source-to-display projection. */
|
|
328
|
+
export declare function recoverGfmInlineCodeFences(range: GfmRange, input: string): GfmInlineCodeFenceRanges;
|
|
329
|
+
/**
|
|
330
|
+
* Projects mdast's already padding-normalized inline-code value to GitHub's
|
|
331
|
+
* displayed code-span text. This is deliberately separate from fence recovery:
|
|
332
|
+
* ranges describe source geometry, while a folded line ending needs a widget
|
|
333
|
+
* text string and cannot be represented by moving a boundary.
|
|
334
|
+
*/
|
|
335
|
+
export declare function projectGfmInlineCodeDisplay(value: string): string;
|
|
336
|
+
export declare function removeGfmEscapeBackslashes(raw: string): string;
|
|
337
|
+
/**
|
|
338
|
+
* The adapter: project one mdast tree onto the flat GfmDocument. Exported next to
|
|
339
|
+
* `parseGfmDocument` because it is the load-bearing seam of this notation — a host
|
|
340
|
+
* that already holds an mdast tree can reuse it directly.
|
|
341
|
+
*/
|
|
342
|
+
export declare function adaptGfmDocument(tree: Root, input: string): GfmDocument;
|
|
343
|
+
/** @internal Collect raw HTML ranges excluded from bare-dollar math scanning. */
|
|
344
|
+
export declare function collectRawHtmlElementRanges(input: string): ProtectedRange[];
|
|
345
|
+
/** @internal Range excluded from bare-dollar math scanning; not a package export. */
|
|
346
|
+
export interface ProtectedRange {
|
|
347
|
+
from: number;
|
|
348
|
+
to: number;
|
|
349
|
+
}
|
|
350
|
+
/** @internal Return the one-based physical line containing an input offset. */
|
|
351
|
+
export declare function lineAtOffset(lineStarts: readonly number[], offset: number): number;
|
|
352
|
+
export declare function intersectsProtected(protectedRanges: readonly ProtectedRange[], from: number, to: number): boolean;
|
|
353
|
+
/** Parse GFM text into the flat GfmDocument the decoration plugins read. */
|
|
354
|
+
export declare function parseGfmDocument(input: string): GfmDocument;
|
|
355
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { MboxPlugin } from "../../editor/plugin.js";
|
|
2
|
+
export declare const gfmTableRenderedClassName = "mbox-gfm-table-rendered";
|
|
3
|
+
export declare const gfmTableRawCellClassName = "mbox-gfm-table-raw-cell";
|
|
4
|
+
export declare const gfmTableClassNames: {
|
|
5
|
+
table: string;
|
|
6
|
+
header: string;
|
|
7
|
+
delimiter: string;
|
|
8
|
+
row: string;
|
|
9
|
+
cell: string;
|
|
10
|
+
rendered: string;
|
|
11
|
+
rawCell: string;
|
|
12
|
+
};
|
|
13
|
+
export interface GfmTablePluginOptions {
|
|
14
|
+
/**
|
|
15
|
+
* How wide a column holding an image should be, in GRID UNITS -- the same
|
|
16
|
+
* units the fixed `ch` grid is measured in, not characters and not pixels.
|
|
17
|
+
* Defaults to 32. `0` reserves nothing, which restores the previous
|
|
18
|
+
* behaviour of an image cell being as narrow as its alt text.
|
|
19
|
+
*
|
|
20
|
+
* Fractions are kept as given: a unit is a grid step, so half a step is a
|
|
21
|
+
* meaningful request. Anything that is not a finite number at or above zero
|
|
22
|
+
* -- negative, infinite, NaN, not a number at all -- falls back to the
|
|
23
|
+
* default WITHOUT throwing. A constructor that throws takes the whole editor
|
|
24
|
+
* down over a stylistic option, and this repository normalises quietly
|
|
25
|
+
* instead (see `normalizeAdditionalProtocols` in link.ts).
|
|
26
|
+
*
|
|
27
|
+
* The reservation is a floor on the COLUMN, not a size for the picture. How
|
|
28
|
+
* large the image itself ends up is the host's CSS to decide; the library
|
|
29
|
+
* only guarantees the column is wide enough for one to be worth looking at,
|
|
30
|
+
* and that it stays inside the cell.
|
|
31
|
+
*/
|
|
32
|
+
imageMinimumColumnWidth?: number;
|
|
33
|
+
}
|
|
34
|
+
export declare function gfmTablePlugin(options?: GfmTablePluginOptions): MboxPlugin;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { WidgetType } from "@codemirror/view";
|
|
2
|
+
import type { MboxPlugin } from "../../editor/plugin.js";
|
|
3
|
+
export declare const gfmThematicBreakLineClassName = "mbox-gfm-hr-line";
|
|
4
|
+
export declare const gfmThematicBreakClassName = "mbox-gfm-hr";
|
|
5
|
+
export declare class GfmThematicBreakWidget extends WidgetType {
|
|
6
|
+
eq(other: WidgetType): boolean;
|
|
7
|
+
toDOM(): HTMLElement;
|
|
8
|
+
}
|
|
9
|
+
export declare function gfmThematicBreakPlugin(): MboxPlugin;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WidgetType } from "@codemirror/view";
|
|
2
|
+
import type { MboxPlugin } from "../../editor/plugin.js";
|
|
3
|
+
export declare const hatenaQuoteBlockClassName = "mbox-hatena-quote-block";
|
|
4
|
+
export declare const hatenaQuoteClassName = "mbox-hatena-quote";
|
|
5
|
+
export declare const hatenaQuoteCiteClassName = "mbox-hatena-quote-cite";
|
|
6
|
+
export declare class HatenaQuoteCiteWidget extends WidgetType {
|
|
7
|
+
readonly url: string;
|
|
8
|
+
constructor(url: string);
|
|
9
|
+
eq(other: WidgetType): boolean;
|
|
10
|
+
toDOM(): HTMLElement;
|
|
11
|
+
}
|
|
12
|
+
export declare function hatenaBlockquotePlugin(): MboxPlugin;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type MboxPlugin } from "../../editor/plugin.js";
|
|
2
|
+
export declare const hatenaDefinitionLineClassName = "mbox-hatena-deflist";
|
|
3
|
+
export declare const hatenaDefinitionContinuationClassName = "mbox-hatena-deflist-cont";
|
|
4
|
+
export declare const hatenaDefinitionTermClassName = "mbox-hatena-deflist-term";
|
|
5
|
+
export declare function hatenaDefinitionPlugin(): MboxPlugin;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { WidgetType } from "@codemirror/view";
|
|
2
|
+
import type { MboxPlugin } from "../../editor/plugin.js";
|
|
3
|
+
export declare const hatenaFootnoteClassName = "mbox-hatena-footnote";
|
|
4
|
+
export declare const hatenaFootnoteLineClassName = "mbox-hatena-footnote-line";
|
|
5
|
+
export declare class HatenaFootnoteWidget extends WidgetType {
|
|
6
|
+
readonly number: number;
|
|
7
|
+
/** The footnote body, shown as the superscript's tooltip. */
|
|
8
|
+
readonly note: string;
|
|
9
|
+
constructor(number: number,
|
|
10
|
+
/** The footnote body, shown as the superscript's tooltip. */
|
|
11
|
+
note: string);
|
|
12
|
+
eq(other: WidgetType): boolean;
|
|
13
|
+
toDOM(): HTMLElement;
|
|
14
|
+
}
|
|
15
|
+
export declare function hatenaFootnotePlugin(): MboxPlugin;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MboxPlugin } from "../../editor/plugin.js";
|
|
2
|
+
export declare const hatenaHeadingLineClassName = "mbox-hatena-heading";
|
|
3
|
+
export declare const hatenaHeadingClassNames: {
|
|
4
|
+
h3: string;
|
|
5
|
+
h4: string;
|
|
6
|
+
h5: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function hatenaHeadingPlugin(): MboxPlugin;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MboxPlugin } from "../../editor/plugin.js";
|
|
2
|
+
import { type HatenaLinkOptions } from "./link.js";
|
|
3
|
+
import { type HatenaSuperPreHighlightPluginOptions } from "./super-pre.js";
|
|
4
|
+
export interface HatenaPluginsOptions {
|
|
5
|
+
link?: HatenaLinkOptions;
|
|
6
|
+
/** `true` adds the super-pre syntax highlighter with its zero-dependency
|
|
7
|
+
* JS/TS default; pass a HatenaSuperPreHighlightPluginOptions object instead
|
|
8
|
+
* to also set `languages`/`onLoadError`. Omitted or falsy adds no
|
|
9
|
+
* highlighter at all. */
|
|
10
|
+
codeHighlight?: boolean | HatenaSuperPreHighlightPluginOptions;
|
|
11
|
+
}
|
|
12
|
+
export declare function hatenaPlugins(options?: HatenaPluginsOptions): MboxPlugin[];
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WidgetType } from "@codemirror/view";
|
|
2
|
+
import type { MboxPlugin } from "../../editor/plugin.js";
|
|
3
|
+
import type { HatenaLinkKind } from "./parser.js";
|
|
4
|
+
export declare const hatenaLinkClassName = "mbox-hatena-link";
|
|
5
|
+
export interface HatenaLinkOptions {
|
|
6
|
+
idUrl?: (name: string) => string;
|
|
7
|
+
}
|
|
8
|
+
export declare class HatenaLinkWidget extends WidgetType {
|
|
9
|
+
private readonly href;
|
|
10
|
+
private readonly label;
|
|
11
|
+
private readonly kind;
|
|
12
|
+
constructor(href: string, label: string, kind: HatenaLinkKind);
|
|
13
|
+
eq(other: WidgetType): boolean;
|
|
14
|
+
toDOM(): HTMLElement;
|
|
15
|
+
}
|
|
16
|
+
export declare function hatenaLinkPlugin(options?: HatenaLinkOptions): MboxPlugin;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WidgetType } from "@codemirror/view";
|
|
2
|
+
import type { MboxPlugin } from "../../editor/plugin.js";
|
|
3
|
+
export declare const hatenaListLineClassName = "mbox-hatena-list";
|
|
4
|
+
export declare const hatenaListActiveClassName = "mbox-hatena-list-active";
|
|
5
|
+
export declare const hatenaListCollapsedClassName = "mbox-hatena-list-collapsed";
|
|
6
|
+
export declare const hatenaListMarkerClassName = "mbox-hatena-list-marker";
|
|
7
|
+
export declare const hatenaListIndentClassName = "mbox-hatena-list-indent";
|
|
8
|
+
export declare const hatenaListMarkerSlotClassName = "mbox-hatena-list-marker-slot";
|
|
9
|
+
export declare const hatenaListMarkerSlotActiveClassName = "mbox-hatena-list-marker-slot-active";
|
|
10
|
+
export declare const hatenaListMarkerSlotCollapsedClassName = "mbox-hatena-list-marker-slot-collapsed";
|
|
11
|
+
export declare const hatenaListMarkerSlotOrderedClassName = "mbox-hatena-list-marker-slot-ordered";
|
|
12
|
+
export declare class HatenaListMarkerWidget extends WidgetType {
|
|
13
|
+
private readonly depth;
|
|
14
|
+
private readonly active;
|
|
15
|
+
/** 1-based number for an ordered (`+`) item; null renders a bullet dot. */
|
|
16
|
+
private readonly ordinal;
|
|
17
|
+
constructor(depth: number, active: boolean,
|
|
18
|
+
/** 1-based number for an ordered (`+`) item; null renders a bullet dot. */
|
|
19
|
+
ordinal: number | null);
|
|
20
|
+
eq(other: WidgetType): boolean;
|
|
21
|
+
toDOM(): HTMLElement;
|
|
22
|
+
ignoreEvent(): boolean;
|
|
23
|
+
}
|
|
24
|
+
export declare function hatenaListPlugin(): MboxPlugin;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { EditorState } from "@codemirror/state";
|
|
2
|
+
import { type DocumentCacheEntry } from "../../editor/document-cache.js";
|
|
3
|
+
import { type HatenaDocument } from "./parser.js";
|
|
4
|
+
export declare function getHatenaDocumentCacheEntryFromState(state: EditorState): DocumentCacheEntry<HatenaDocument>;
|
|
5
|
+
export declare function getHatenaDocumentFromState(state: EditorState): HatenaDocument;
|