nizel 0.1.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/dist/blocks/define-block.d.ts +6 -0
- package/dist/blocks/define-block.d.ts.map +1 -0
- package/dist/blocks/define-block.js +7 -0
- package/dist/blocks/define-block.js.map +1 -0
- package/dist/collect.d.ts +16 -0
- package/dist/collect.d.ts.map +1 -0
- package/dist/collect.js +155 -0
- package/dist/collect.js.map +1 -0
- package/dist/defaults.d.ts +10 -0
- package/dist/defaults.d.ts.map +1 -0
- package/dist/defaults.js +147 -0
- package/dist/defaults.js.map +1 -0
- package/dist/frontmatter.d.ts +8 -0
- package/dist/frontmatter.d.ts.map +1 -0
- package/dist/frontmatter.js +76 -0
- package/dist/frontmatter.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +7 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +78 -0
- package/dist/options.js.map +1 -0
- package/dist/parse/autolink.d.ts +14 -0
- package/dist/parse/autolink.d.ts.map +1 -0
- package/dist/parse/autolink.js +19 -0
- package/dist/parse/autolink.js.map +1 -0
- package/dist/parse/block.d.ts +25 -0
- package/dist/parse/block.d.ts.map +1 -0
- package/dist/parse/block.js +39 -0
- package/dist/parse/block.js.map +1 -0
- package/dist/parse/blockquote.d.ts +16 -0
- package/dist/parse/blockquote.d.ts.map +1 -0
- package/dist/parse/blockquote.js +46 -0
- package/dist/parse/blockquote.js.map +1 -0
- package/dist/parse/code.d.ts +32 -0
- package/dist/parse/code.d.ts.map +1 -0
- package/dist/parse/code.js +74 -0
- package/dist/parse/code.js.map +1 -0
- package/dist/parse/common.d.ts +33 -0
- package/dist/parse/common.d.ts.map +1 -0
- package/dist/parse/common.js +80 -0
- package/dist/parse/common.js.map +1 -0
- package/dist/parse/custom.d.ts +29 -0
- package/dist/parse/custom.d.ts.map +1 -0
- package/dist/parse/custom.js +80 -0
- package/dist/parse/custom.js.map +1 -0
- package/dist/parse/emphasis.d.ts +70 -0
- package/dist/parse/emphasis.d.ts.map +1 -0
- package/dist/parse/emphasis.js +234 -0
- package/dist/parse/emphasis.js.map +1 -0
- package/dist/parse/html.d.ts +46 -0
- package/dist/parse/html.d.ts.map +1 -0
- package/dist/parse/html.js +169 -0
- package/dist/parse/html.js.map +1 -0
- package/dist/parse/inline-links.d.ts +57 -0
- package/dist/parse/inline-links.d.ts.map +1 -0
- package/dist/parse/inline-links.js +223 -0
- package/dist/parse/inline-links.js.map +1 -0
- package/dist/parse/inline-text.d.ts +10 -0
- package/dist/parse/inline-text.d.ts.map +1 -0
- package/dist/parse/inline-text.js +30 -0
- package/dist/parse/inline-text.js.map +1 -0
- package/dist/parse/inline.d.ts +26 -0
- package/dist/parse/inline.d.ts.map +1 -0
- package/dist/parse/inline.js +287 -0
- package/dist/parse/inline.js.map +1 -0
- package/dist/parse/lines.d.ts +25 -0
- package/dist/parse/lines.d.ts.map +1 -0
- package/dist/parse/lines.js +90 -0
- package/dist/parse/lines.js.map +1 -0
- package/dist/parse/list-items.d.ts +21 -0
- package/dist/parse/list-items.d.ts.map +1 -0
- package/dist/parse/list-items.js +93 -0
- package/dist/parse/list-items.js.map +1 -0
- package/dist/parse/list.d.ts +32 -0
- package/dist/parse/list.d.ts.map +1 -0
- package/dist/parse/list.js +79 -0
- package/dist/parse/list.js.map +1 -0
- package/dist/parse/references.d.ts +45 -0
- package/dist/parse/references.d.ts.map +1 -0
- package/dist/parse/references.js +228 -0
- package/dist/parse/references.js.map +1 -0
- package/dist/parse/table.d.ts +18 -0
- package/dist/parse/table.d.ts.map +1 -0
- package/dist/parse/table.js +52 -0
- package/dist/parse/table.js.map +1 -0
- package/dist/parse.d.ts +14 -0
- package/dist/parse.d.ts.map +1 -0
- package/dist/parse.js +264 -0
- package/dist/parse.js.map +1 -0
- package/dist/plugins/define-nizel-plugin.d.ts +6 -0
- package/dist/plugins/define-nizel-plugin.d.ts.map +1 -0
- package/dist/plugins/define-nizel-plugin.js +7 -0
- package/dist/plugins/define-nizel-plugin.js.map +1 -0
- package/dist/render.d.ts +6 -0
- package/dist/render.d.ts.map +1 -0
- package/dist/render.js +245 -0
- package/dist/render.js.map +1 -0
- package/dist/template.d.ts +6 -0
- package/dist/template.d.ts.map +1 -0
- package/dist/template.js +85 -0
- package/dist/template.js.map +1 -0
- package/dist/types.d.ts +245 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/use-nizel.d.ts +3 -0
- package/dist/use-nizel.d.ts.map +1 -0
- package/dist/use-nizel.js +214 -0
- package/dist/use-nizel.js.map +1 -0
- package/dist/utils.d.ts +21 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +51 -0
- package/dist/utils.js.map +1 -0
- package/package.json +31 -0
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether a line is a simple raw HTML block tag.
|
|
3
|
+
*/
|
|
4
|
+
export declare const isRawHtmlBlockLine: (line: string) => boolean;
|
|
5
|
+
/**
|
|
6
|
+
* Checks CommonMark thematic break marker runs with optional spaces.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isThematicBreak: (line: string) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Matches a valid setext heading underline.
|
|
11
|
+
*/
|
|
12
|
+
export declare const isSetextUnderline: (line: string) => RegExpExecArray | null;
|
|
13
|
+
/**
|
|
14
|
+
* Removes optional closing hash markers from an ATX heading.
|
|
15
|
+
*/
|
|
16
|
+
export declare const trimClosingHeadingHashes: (source: string) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Removes up to three leading spaces from paragraph lines and preserves hard-break markers.
|
|
19
|
+
*/
|
|
20
|
+
export declare const normalizeParagraphLine: (line: string) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Joins paragraph lines and removes spaces that only trail the paragraph.
|
|
23
|
+
*/
|
|
24
|
+
export declare const normalizeParagraphSource: (lines: string[]) => string;
|
|
25
|
+
//# sourceMappingURL=block.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.d.ts","sourceRoot":"","sources":["../../src/parse/block.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,MAAM,MAAM,KAAG,OAEjD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,MAAM,MAAM,KAAG,OAE9C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,eAAe,GAAG,IAElE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,QAAQ,MAAM,KAAG,MAGzD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAI,MAAM,MAAM,KAAG,MAErD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,OAAO,MAAM,EAAE,KAAG,MAE1D,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checks whether a line is a simple raw HTML block tag.
|
|
3
|
+
*/
|
|
4
|
+
export const isRawHtmlBlockLine = (line) => {
|
|
5
|
+
return /^<\/?[A-Za-z][A-Za-z0-9-]*(?=[\s>/])[\s\S]*>$/.test(line.trim());
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Checks CommonMark thematic break marker runs with optional spaces.
|
|
9
|
+
*/
|
|
10
|
+
export const isThematicBreak = (line) => {
|
|
11
|
+
return /^ {0,3}([-*_])(?:[ \t]*\1){2,}[ \t]*$/.test(line);
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Matches a valid setext heading underline.
|
|
15
|
+
*/
|
|
16
|
+
export const isSetextUnderline = (line) => {
|
|
17
|
+
return /^ {0,3}(=+|-+)\s*$/.exec(line);
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Removes optional closing hash markers from an ATX heading.
|
|
21
|
+
*/
|
|
22
|
+
export const trimClosingHeadingHashes = (source) => {
|
|
23
|
+
if (/^#+\s*$/.test(source))
|
|
24
|
+
return '';
|
|
25
|
+
return source.replace(/\s+#+\s*$/, '').trim();
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Removes up to three leading spaces from paragraph lines and preserves hard-break markers.
|
|
29
|
+
*/
|
|
30
|
+
export const normalizeParagraphLine = (line) => {
|
|
31
|
+
return line.replace(/^ {0,3}/, '').trimStart();
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Joins paragraph lines and removes spaces that only trail the paragraph.
|
|
35
|
+
*/
|
|
36
|
+
export const normalizeParagraphSource = (lines) => {
|
|
37
|
+
return lines.join('\n').replace(/[ \t]+$/, '');
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=block.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block.js","sourceRoot":"","sources":["../../src/parse/block.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,IAAY,EAAW,EAAE;IAC1D,OAAO,+CAA+C,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;AAC3E,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,IAAY,EAAW,EAAE;IACvD,OAAO,uCAAuC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAA0B,EAAE;IACxE,OAAO,oBAAoB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACzC,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,MAAc,EAAU,EAAE;IACjE,IAAI,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,EAAE,CAAC;IACtC,OAAO,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;AAChD,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,IAAY,EAAU,EAAE;IAC7D,OAAO,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC,SAAS,EAAE,CAAC;AACjD,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,KAAe,EAAU,EAAE;IAClE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;AACjD,CAAC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type BlockquoteContinuationOptions = {
|
|
2
|
+
safe: boolean;
|
|
3
|
+
};
|
|
4
|
+
/**
|
|
5
|
+
* Checks whether an unmarked line lazily continues a blockquote paragraph.
|
|
6
|
+
*/
|
|
7
|
+
export declare const canContinueBlockquoteLazily: (line: string, options: BlockquoteContinuationOptions, lines: string[], index: number) => boolean;
|
|
8
|
+
/**
|
|
9
|
+
* Checks whether the current quoted line can be followed by lazy continuation.
|
|
10
|
+
*/
|
|
11
|
+
export declare const canStartLazyBlockquoteContinuation: <TOptions extends BlockquoteContinuationOptions>(line: string, options: TOptions, lines: string[], index: number, isBlockStart: (line: string, options: TOptions, lines: string[], index: number) => boolean) => boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Finds the deepest paragraph-like content that can receive lazy continuation.
|
|
14
|
+
*/
|
|
15
|
+
export declare const lazyContinuationCandidate: (line: string) => string;
|
|
16
|
+
//# sourceMappingURL=blockquote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockquote.d.ts","sourceRoot":"","sources":["../../src/parse/blockquote.ts"],"names":[],"mappings":"AAKA,MAAM,MAAM,6BAA6B,GAAG;IAC1C,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,2BAA2B,GACtC,MAAM,MAAM,EACZ,SAAS,6BAA6B,EACtC,OAAO,MAAM,EAAE,EACf,OAAO,MAAM,KACZ,OAUF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kCAAkC,GAAI,QAAQ,SAAS,6BAA6B,EAC/F,MAAM,MAAM,EACZ,SAAS,QAAQ,EACjB,OAAO,MAAM,EAAE,EACf,OAAO,MAAM,EACb,cAAc,CACZ,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,QAAQ,EACjB,KAAK,EAAE,MAAM,EAAE,EACf,KAAK,EAAE,MAAM,KACV,OAAO,KACX,OAQF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,yBAAyB,GAAI,MAAM,MAAM,KAAG,MAkBxD,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isThematicBreak } from './block.js';
|
|
2
|
+
import { isInterruptingHtmlBlockStart } from './html.js';
|
|
3
|
+
import { parseListMarker } from './list.js';
|
|
4
|
+
import { isTableStart } from './table.js';
|
|
5
|
+
/**
|
|
6
|
+
* Checks whether an unmarked line lazily continues a blockquote paragraph.
|
|
7
|
+
*/
|
|
8
|
+
export const canContinueBlockquoteLazily = (line, options, lines, index) => {
|
|
9
|
+
return Boolean(line.trim() &&
|
|
10
|
+
!/^ {0,3}> ?/.test(line) &&
|
|
11
|
+
!/^ {0,3}(`{3,}|~{3,})/.test(line) &&
|
|
12
|
+
!isThematicBreak(line) &&
|
|
13
|
+
!parseListMarker(line) &&
|
|
14
|
+
!isTableStart(lines, index) &&
|
|
15
|
+
!(options.safe === false && isInterruptingHtmlBlockStart(line)));
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Checks whether the current quoted line can be followed by lazy continuation.
|
|
19
|
+
*/
|
|
20
|
+
export const canStartLazyBlockquoteContinuation = (line, options, lines, index, isBlockStart) => {
|
|
21
|
+
const candidate = lazyContinuationCandidate(line);
|
|
22
|
+
return Boolean(candidate.trim() &&
|
|
23
|
+
!/^ {0,3}(`{3,}|~{3,})/.test(candidate) &&
|
|
24
|
+
!/^ {4}/.test(candidate) &&
|
|
25
|
+
!isBlockStart(candidate, options, lines, index));
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Finds the deepest paragraph-like content that can receive lazy continuation.
|
|
29
|
+
*/
|
|
30
|
+
export const lazyContinuationCandidate = (line) => {
|
|
31
|
+
let candidate = line;
|
|
32
|
+
while (true) {
|
|
33
|
+
const quoteMarker = /^ {0,3}> ?(.*)$/.exec(candidate);
|
|
34
|
+
if (quoteMarker) {
|
|
35
|
+
candidate = quoteMarker[1];
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const marker = parseListMarker(candidate);
|
|
39
|
+
if (marker && /^ {0,3}> ?/.test(marker.body)) {
|
|
40
|
+
candidate = marker.body;
|
|
41
|
+
continue;
|
|
42
|
+
}
|
|
43
|
+
return candidate;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=blockquote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"blockquote.js","sourceRoot":"","sources":["../../src/parse/blockquote.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAM1C;;GAEG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,CACzC,IAAY,EACZ,OAAsC,EACtC,KAAe,EACf,KAAa,EACJ,EAAE;IACX,OAAO,OAAO,CACV,IAAI,CAAC,IAAI,EAAE;QACX,CAAC,YAAY,CAAC,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xB,SAAS;QACX,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a closing fence pattern for a fenced-code opener.
|
|
3
|
+
*/
|
|
4
|
+
export declare const openingFenceClosePattern: (line: string) => RegExp | null;
|
|
5
|
+
/**
|
|
6
|
+
* Applies CommonMark whitespace normalization for code spans.
|
|
7
|
+
*/
|
|
8
|
+
export declare const normalizeCodeSpan: (code: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Parses and decodes the info string of a fenced code block.
|
|
11
|
+
*/
|
|
12
|
+
export declare const parseFenceInfo: (info: string, marker: string) => {
|
|
13
|
+
lang?: string;
|
|
14
|
+
meta: string;
|
|
15
|
+
valid: boolean;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Removes up to the opening fence indentation from fenced code content.
|
|
19
|
+
*/
|
|
20
|
+
export declare const stripFenceIndent: (line: string, indent: number) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Parses code fence metadata such as filename and highlighted line ranges.
|
|
23
|
+
*/
|
|
24
|
+
export declare const parseCodeMeta: (meta: string) => {
|
|
25
|
+
filename?: string;
|
|
26
|
+
highlightLines?: number[];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Expands a comma-delimited line range expression into sorted line numbers.
|
|
30
|
+
*/
|
|
31
|
+
export declare const expandLineRanges: (source: string) => number[];
|
|
32
|
+
//# sourceMappingURL=code.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../src/parse/code.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,MAAM,MAAM,KAAG,MAAM,GAAG,IAKhE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,iBAAiB,GAAI,MAAM,MAAM,KAAG,MAKhD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAM1G,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,EAAE,QAAQ,MAAM,KAAG,MAO/D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG;IAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAAC,cAAc,CAAC,EAAE,MAAM,EAAE,CAAA;CAO1F,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,KAAG,MAAM,EAYvD,CAAC"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { decodeStringContent } from './common.js';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a closing fence pattern for a fenced-code opener.
|
|
4
|
+
*/
|
|
5
|
+
export const openingFenceClosePattern = (line) => {
|
|
6
|
+
const fence = /^( {0,3})(`{3,}|~{3,})[ \t]*(.*)$/.exec(line);
|
|
7
|
+
if (!fence)
|
|
8
|
+
return null;
|
|
9
|
+
const marker = fence[2][0];
|
|
10
|
+
return new RegExp(`^ {0,3}\\${marker}{${fence[2].length},}\\s*$`);
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Applies CommonMark whitespace normalization for code spans.
|
|
14
|
+
*/
|
|
15
|
+
export const normalizeCodeSpan = (code) => {
|
|
16
|
+
const normalized = code.replace(/\r?\n/g, ' ');
|
|
17
|
+
return normalized.startsWith(' ') && normalized.endsWith(' ') && /[^ ]/.test(normalized)
|
|
18
|
+
? normalized.slice(1, -1)
|
|
19
|
+
: normalized;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Parses and decodes the info string of a fenced code block.
|
|
23
|
+
*/
|
|
24
|
+
export const parseFenceInfo = (info, marker) => {
|
|
25
|
+
const meta = decodeStringContent(info.trim());
|
|
26
|
+
if (marker === '`' && meta.includes('`'))
|
|
27
|
+
return { meta: '', valid: false };
|
|
28
|
+
if (!meta)
|
|
29
|
+
return { meta: '', valid: true };
|
|
30
|
+
const [lang] = meta.split(/\s+/, 1);
|
|
31
|
+
return { lang, meta, valid: true };
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* Removes up to the opening fence indentation from fenced code content.
|
|
35
|
+
*/
|
|
36
|
+
export const stripFenceIndent = (line, indent) => {
|
|
37
|
+
let removed = 0;
|
|
38
|
+
while (removed < indent && line.startsWith(' ')) {
|
|
39
|
+
line = line.slice(1);
|
|
40
|
+
removed += 1;
|
|
41
|
+
}
|
|
42
|
+
return line;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* Parses code fence metadata such as filename and highlighted line ranges.
|
|
46
|
+
*/
|
|
47
|
+
export const parseCodeMeta = (meta) => {
|
|
48
|
+
const filename = /filename=(?:"([^"]+)"|'([^']+)'|(\S+))/.exec(meta);
|
|
49
|
+
const highlight = /\{([^}]+)\}/.exec(meta);
|
|
50
|
+
return {
|
|
51
|
+
filename: filename?.[1] ?? filename?.[2] ?? filename?.[3],
|
|
52
|
+
highlightLines: highlight ? expandLineRanges(highlight[1]) : undefined,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Expands a comma-delimited line range expression into sorted line numbers.
|
|
57
|
+
*/
|
|
58
|
+
export const expandLineRanges = (source) => {
|
|
59
|
+
const lines = new Set();
|
|
60
|
+
for (const part of source.split(',')) {
|
|
61
|
+
const [start, end] = part.trim().split('-').map(Number);
|
|
62
|
+
if (!Number.isFinite(start))
|
|
63
|
+
continue;
|
|
64
|
+
if (Number.isFinite(end)) {
|
|
65
|
+
for (let line = start; line <= end; line += 1)
|
|
66
|
+
lines.add(line);
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
lines.add(start);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return [...lines].sort((a, b) => a - b);
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=code.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../src/parse/code.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAiB,EAAE;IACtE,MAAM,KAAK,GAAG,mCAAmC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7D,IAAI,CAAC,KAAK;QAAE,OAAO,IAAI,CAAC;IACxB,MAAM,MAAM,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3B,OAAO,IAAI,MAAM,CAAC,YAAY,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,SAAS,CAAC,CAAC;AACpE,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAY,EAAU,EAAE;IACxD,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC,CAAC;IAC/C,OAAO,UAAU,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC;QACtF,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;QACzB,CAAC,CAAC,UAAU,CAAC;AACjB,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,MAAc,EAAmD,EAAE;IAC9G,MAAM,IAAI,GAAG,mBAAmB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;IAC9C,IAAI,MAAM,K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AC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,MAAc,EAAY,EAAE;IAC3D,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;QACrC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACxD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,SAAS;QACtC,IAAI,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACzB,KAAK,IAAI,IAAI,GAAG,KAAK,EAAE,IAAI,IAAI,GAAG,EAAE,IAAI,IAAI,CAAC;gBAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACjE,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QACnB,CAAC;IACH,CAAC;IACD,OAAO,CAAC,GAAG,KAAK,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;AAC1C,CAAC,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type ReferenceDefinition = {
|
|
2
|
+
href: string;
|
|
3
|
+
title?: string;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes a reference label for case-insensitive lookup.
|
|
7
|
+
*/
|
|
8
|
+
export declare const normalizeReference: (label: string) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Normalizes an inline reference label for lookup.
|
|
11
|
+
*/
|
|
12
|
+
export declare const normalizeReferenceLabelForLookup: (label: string) => string;
|
|
13
|
+
/**
|
|
14
|
+
* Removes angle brackets from a link reference destination.
|
|
15
|
+
*/
|
|
16
|
+
export declare const stripDestinationBrackets: (destination: string) => string;
|
|
17
|
+
/**
|
|
18
|
+
* Applies URI encoding required for rendered link destinations.
|
|
19
|
+
*/
|
|
20
|
+
export declare const normalizeHref: (destination: string) => string;
|
|
21
|
+
/**
|
|
22
|
+
* Decodes backslash escapes and character references in link-like attributes.
|
|
23
|
+
*/
|
|
24
|
+
export declare const decodeStringContent: (source: string) => string;
|
|
25
|
+
/**
|
|
26
|
+
* Decodes the named and numeric entities Nizel handles directly.
|
|
27
|
+
*/
|
|
28
|
+
export declare const decodeEntity: (entity: string) => string;
|
|
29
|
+
/**
|
|
30
|
+
* Converts a numeric entity code point, preserving invalid entities as text.
|
|
31
|
+
*/
|
|
32
|
+
export declare const decodeCodePoint: (entity: string, codePoint: number) => string;
|
|
33
|
+
//# sourceMappingURL=common.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../../src/parse/common.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,kBAAkB,GAAI,OAAO,MAAM,KAAG,MAElD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gCAAgC,GAAI,OAAO,MAAM,KAAG,MAEhE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,aAAa,MAAM,KAAG,MAE9D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,aAAa,MAAM,KAAG,MAMnD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,QAAQ,MAAM,KAAG,MAMpD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,QAAQ,MAAM,KAAG,MAsB7C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,MAanE,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalizes a reference label for case-insensitive lookup.
|
|
3
|
+
*/
|
|
4
|
+
export const normalizeReference = (label) => {
|
|
5
|
+
return label.trim().replace(/\s+/g, ' ').replace(/[ẞß]/g, 'ss').toLowerCase();
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Normalizes an inline reference label for lookup.
|
|
9
|
+
*/
|
|
10
|
+
export const normalizeReferenceLabelForLookup = (label) => {
|
|
11
|
+
return normalizeReference(label.replace(/\\([\[\]])/g, '$1'));
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Removes angle brackets from a link reference destination.
|
|
15
|
+
*/
|
|
16
|
+
export const stripDestinationBrackets = (destination) => {
|
|
17
|
+
return destination.replace(/^<|>$/g, '');
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Applies URI encoding required for rendered link destinations.
|
|
21
|
+
*/
|
|
22
|
+
export const normalizeHref = (destination) => {
|
|
23
|
+
try {
|
|
24
|
+
return encodeURI(destination).replace(/%25([0-9A-Fa-f]{2})/g, '%$1');
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return destination;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Decodes backslash escapes and character references in link-like attributes.
|
|
32
|
+
*/
|
|
33
|
+
export const decodeStringContent = (source) => {
|
|
34
|
+
return source
|
|
35
|
+
.replace(/\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g, '$1')
|
|
36
|
+
.replace(/&([A-Za-z][A-Za-z0-9]+|#[0-9]+|#[xX][0-9A-Fa-f]+);/g, (_, entity) => decodeEntity(entity));
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Decodes the named and numeric entities Nizel handles directly.
|
|
40
|
+
*/
|
|
41
|
+
export const decodeEntity = (entity) => {
|
|
42
|
+
if (/^#[xX]/.test(entity))
|
|
43
|
+
return decodeCodePoint(entity, Number.parseInt(entity.slice(2), 16));
|
|
44
|
+
if (entity.startsWith('#'))
|
|
45
|
+
return decodeCodePoint(entity, Number.parseInt(entity.slice(1), 10));
|
|
46
|
+
const named = {
|
|
47
|
+
amp: '&',
|
|
48
|
+
lt: '<',
|
|
49
|
+
gt: '>',
|
|
50
|
+
quot: '"',
|
|
51
|
+
apos: "'",
|
|
52
|
+
nbsp: '\u00a0',
|
|
53
|
+
AElig: 'Æ',
|
|
54
|
+
auml: 'ä',
|
|
55
|
+
ClockwiseContourIntegral: '∲',
|
|
56
|
+
copy: '©',
|
|
57
|
+
Dcaron: 'Ď',
|
|
58
|
+
DifferentialD: 'ⅆ',
|
|
59
|
+
frac34: '¾',
|
|
60
|
+
HilbertSpace: 'ℋ',
|
|
61
|
+
ngE: '≧̸',
|
|
62
|
+
ouml: 'ö',
|
|
63
|
+
};
|
|
64
|
+
return named[entity] ?? `&${entity};`;
|
|
65
|
+
};
|
|
66
|
+
/**
|
|
67
|
+
* Converts a numeric entity code point, preserving invalid entities as text.
|
|
68
|
+
*/
|
|
69
|
+
export const decodeCodePoint = (entity, codePoint) => {
|
|
70
|
+
if (!Number.isFinite(codePoint) ||
|
|
71
|
+
codePoint === 0 ||
|
|
72
|
+
(codePoint >= 0xd800 && codePoint <= 0xdfff)) {
|
|
73
|
+
return '\ufffd';
|
|
74
|
+
}
|
|
75
|
+
if (codePoint < 0 || codePoint > 0x10ffff) {
|
|
76
|
+
return `&${entity};`;
|
|
77
|
+
}
|
|
78
|
+
return String.fromCodePoint(codePoint);
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=common.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../../src/parse/common.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,KAAa,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/**
|
|
2
|
+
* Reads a custom block body, optional props section, and closing delimiter.
|
|
3
|
+
*/
|
|
4
|
+
export declare const readCustomBlock: (lines: string[], startIndex: number) => {
|
|
5
|
+
props: Record<string, unknown>;
|
|
6
|
+
content: string;
|
|
7
|
+
endIndex: number;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Finds the next custom block delimiter from a starting line index.
|
|
11
|
+
*/
|
|
12
|
+
export declare const findDelimiter: (lines: string[], startIndex: number) => number;
|
|
13
|
+
/**
|
|
14
|
+
* Checks whether a line can be part of a custom block props section.
|
|
15
|
+
*/
|
|
16
|
+
export declare const isPropOrBlank: (line: string) => boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Parses key-value custom block props.
|
|
19
|
+
*/
|
|
20
|
+
export declare const parseProps: (lines: string[]) => Record<string, unknown>;
|
|
21
|
+
/**
|
|
22
|
+
* Coerces a custom block prop scalar into a JavaScript primitive.
|
|
23
|
+
*/
|
|
24
|
+
export declare const parsePrimitive: (value: string) => unknown;
|
|
25
|
+
/**
|
|
26
|
+
* Splits a custom block argument string into whitespace-separated words.
|
|
27
|
+
*/
|
|
28
|
+
export declare const splitWords: (source: string) => string[];
|
|
29
|
+
//# sourceMappingURL=custom.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"custom.d.ts","sourceRoot":"","sources":["../../src/parse/custom.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,OAAO,MAAM,EAAE,EAAE,YAAY,MAAM,KAAG;IACpE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;CA4BlB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,OAAO,MAAM,EAAE,EAAE,YAAY,MAAM,KAAG,MAKnE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,MAAM,KAAG,OAE5C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,OAAO,MAAM,EAAE,KAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAQlE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,MAAM,KAAG,OAO9C,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,UAAU,GAAI,QAAQ,MAAM,KAAG,MAAM,EAEjD,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Reads a custom block body, optional props section, and closing delimiter.
|
|
3
|
+
*/
|
|
4
|
+
export const readCustomBlock = (lines, startIndex) => {
|
|
5
|
+
const firstDelimiter = findDelimiter(lines, startIndex + 1);
|
|
6
|
+
if (firstDelimiter === -1) {
|
|
7
|
+
return {
|
|
8
|
+
props: {},
|
|
9
|
+
content: lines.slice(startIndex + 1).join('\n'),
|
|
10
|
+
endIndex: lines.length - 1,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const beforeDelimiter = lines.slice(startIndex + 1, firstDelimiter);
|
|
14
|
+
if (beforeDelimiter.length > 0 && beforeDelimiter.every(isPropOrBlank)) {
|
|
15
|
+
const closingDelimiter = findDelimiter(lines, firstDelimiter + 1);
|
|
16
|
+
return {
|
|
17
|
+
props: parseProps(beforeDelimiter),
|
|
18
|
+
content: lines
|
|
19
|
+
.slice(firstDelimiter + 1, closingDelimiter === -1 ? lines.length : closingDelimiter)
|
|
20
|
+
.join('\n'),
|
|
21
|
+
endIndex: closingDelimiter === -1 ? lines.length - 1 : closingDelimiter,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
props: {},
|
|
26
|
+
content: beforeDelimiter.join('\n'),
|
|
27
|
+
endIndex: firstDelimiter,
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Finds the next custom block delimiter from a starting line index.
|
|
32
|
+
*/
|
|
33
|
+
export const findDelimiter = (lines, startIndex) => {
|
|
34
|
+
for (let index = startIndex; index < lines.length; index += 1) {
|
|
35
|
+
if (lines[index].trim() === '::')
|
|
36
|
+
return index;
|
|
37
|
+
}
|
|
38
|
+
return -1;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Checks whether a line can be part of a custom block props section.
|
|
42
|
+
*/
|
|
43
|
+
export const isPropOrBlank = (line) => {
|
|
44
|
+
return !line.trim() || /^[A-Za-z0-9_-]+:\s*.*$/.test(line.trim());
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Parses key-value custom block props.
|
|
48
|
+
*/
|
|
49
|
+
export const parseProps = (lines) => {
|
|
50
|
+
const props = {};
|
|
51
|
+
for (const line of lines) {
|
|
52
|
+
const match = /^([A-Za-z0-9_-]+):\s*(.*)$/.exec(line.trim());
|
|
53
|
+
if (!match)
|
|
54
|
+
continue;
|
|
55
|
+
props[match[1]] = parsePrimitive(match[2]);
|
|
56
|
+
}
|
|
57
|
+
return props;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Coerces a custom block prop scalar into a JavaScript primitive.
|
|
61
|
+
*/
|
|
62
|
+
export const parsePrimitive = (value) => {
|
|
63
|
+
const trimmed = value.trim();
|
|
64
|
+
if (trimmed === 'true')
|
|
65
|
+
return true;
|
|
66
|
+
if (trimmed === 'false')
|
|
67
|
+
return false;
|
|
68
|
+
if (trimmed === 'null')
|
|
69
|
+
return null;
|
|
70
|
+
if (/^-?\d+(\.\d+)?$/.test(trimmed))
|
|
71
|
+
return Number(trimmed);
|
|
72
|
+
return trimmed.replace(/^["']|["']$/g, '');
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* Splits a custom block argument string into whitespace-separated words.
|
|
76
|
+
*/
|
|
77
|
+
export const splitWords = (source) => {
|
|
78
|
+
return source.trim() ? source.trim().split(/\s+/) : [];
|
|
79
|
+
};
|
|
80
|
+
//# sourceMappingURL=custom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;QAAE,OAAO,IAAI,CAAC;IACpC,IAAI,OAAO,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACtC,IAAI,OAAO,KAAK,MAAM;QAAE,OAAO,IAAI,CAAC;IACpC,IAAI,iBAAiB,CAAC,IAAI,CAAC,OAAO,CAAC;QAAE,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;IAC5D,OAAO,OAAO,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;AAC7C,CAAC,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,MAAc,EAAY,EAAE;IACrD,OAAO,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACzD,CAAC,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import type { NizelInlineNode, NizelTextNode } from '../types.js';
|
|
2
|
+
export type EscapedTextNode = NizelTextNode & {
|
|
3
|
+
escaped?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export type InlineToken = {
|
|
6
|
+
type: 'node';
|
|
7
|
+
node: NizelInlineNode;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'delimiter';
|
|
10
|
+
char: '*' | '_';
|
|
11
|
+
close: boolean;
|
|
12
|
+
length: number;
|
|
13
|
+
open: boolean;
|
|
14
|
+
};
|
|
15
|
+
/**
|
|
16
|
+
* Resolves emphasis delimiter runs that remain after non-emphasis inline tokenization.
|
|
17
|
+
*/
|
|
18
|
+
export declare const resolveRemainingEmphasis: (nodes: NizelInlineNode[]) => NizelInlineNode[];
|
|
19
|
+
/**
|
|
20
|
+
* Splits text nodes into text and emphasis delimiter tokens.
|
|
21
|
+
*/
|
|
22
|
+
export declare const tokenizeEmphasisDelimiters: (nodes: NizelInlineNode[]) => InlineToken[];
|
|
23
|
+
/**
|
|
24
|
+
* Gets the next text-like character represented by inline nodes.
|
|
25
|
+
*/
|
|
26
|
+
export declare const nextInlineCharacter: (nodes: NizelInlineNode[], startIndex: number) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Gets the first text-like character represented by an inline node.
|
|
29
|
+
*/
|
|
30
|
+
export declare const firstInlineCharacter: (node: NizelInlineNode) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Applies CommonMark's rule that forbids some mixed-length delimiter matches.
|
|
33
|
+
*/
|
|
34
|
+
export declare const isForbiddenDelimiterMatch: (opener: Extract<InlineToken, {
|
|
35
|
+
type: "delimiter";
|
|
36
|
+
}>, closer: Extract<InlineToken, {
|
|
37
|
+
type: "delimiter";
|
|
38
|
+
}>) => boolean;
|
|
39
|
+
/**
|
|
40
|
+
* Finds the next emphasis delimiter in a text run.
|
|
41
|
+
*/
|
|
42
|
+
export declare const nextEmphasisDelimiter: (source: string, startIndex: number) => number;
|
|
43
|
+
/**
|
|
44
|
+
* Gets the previous visible character from emitted inline tokens.
|
|
45
|
+
*/
|
|
46
|
+
export declare const previousCharacter: (tokens: InlineToken[]) => string;
|
|
47
|
+
/**
|
|
48
|
+
* Gets the last text-like character represented by an inline node.
|
|
49
|
+
*/
|
|
50
|
+
export declare const lastInlineCharacter: (node: NizelInlineNode) => string;
|
|
51
|
+
/**
|
|
52
|
+
* Applies CommonMark left/right-flanking delimiter rules.
|
|
53
|
+
*/
|
|
54
|
+
export declare const classifyDelimiterRun: (char: "*" | "_", before: string, after: string) => {
|
|
55
|
+
open: boolean;
|
|
56
|
+
close: boolean;
|
|
57
|
+
};
|
|
58
|
+
/**
|
|
59
|
+
* Checks whether a character is Unicode punctuation.
|
|
60
|
+
*/
|
|
61
|
+
export declare const isUnicodePunctuation: (character: string) => boolean;
|
|
62
|
+
/**
|
|
63
|
+
* Converts delimiter tokens back to inline nodes.
|
|
64
|
+
*/
|
|
65
|
+
export declare const inlineTokensToNodes: (tokens: InlineToken[]) => NizelInlineNode[];
|
|
66
|
+
/**
|
|
67
|
+
* Appends text while coalescing adjacent text nodes.
|
|
68
|
+
*/
|
|
69
|
+
export declare const appendTextNode: (nodes: NizelInlineNode[], value: string) => void;
|
|
70
|
+
//# sourceMappingURL=emphasis.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"emphasis.d.ts","sourceRoot":"","sources":["../../src/parse/emphasis.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAElE,MAAM,MAAM,eAAe,GAAG,aAAa,GAAG;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,eAAe,CAAA;CAAE,GACvC;IACE,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,GAAG,GAAG,GAAG,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEN;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,OAAO,eAAe,EAAE,KAAG,eAAe,EAgDlF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,0BAA0B,GAAI,OAAO,eAAe,EAAE,KAAG,WAAW,EA6ChF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,OAAO,eAAe,EAAE,EAAE,YAAY,MAAM,KAAG,MAMlF,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,GAAI,MAAM,eAAe,KAAG,MAY5D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,yBAAyB,GACpC,QAAQ,OAAO,CAAC,WAAW,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC,EACnD,QAAQ,OAAO,CAAC,WAAW,EAAE;IAAE,IAAI,EAAE,WAAW,CAAA;CAAE,CAAC,KAClD,OAIF,C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