@mdream/js 2.0.3 → 2.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/_chunks/clean.mjs +1 -2
- package/dist/_chunks/extraction.d.mts +2 -1
- package/dist/_chunks/html.mjs +18 -8
- package/dist/_chunks/markdown-processor.mjs +746 -144
- package/dist/_chunks/output-runner.mjs +2 -1
- package/dist/_chunks/parse.mjs +148 -27
- package/dist/_chunks/src.mjs +25 -6
- package/dist/_chunks/tag-overrides.mjs +12 -2
- package/dist/_chunks/tailwind.mjs +66 -32
- package/dist/_chunks/text.mjs +10 -9
- package/dist/_chunks/types.d.mts +34 -0
- package/dist/_chunks/url.mjs +670 -2
- package/dist/clean.mjs +1 -2
- package/dist/html.mjs +1 -2
- package/dist/negotiate.d.mts +2 -1
- package/dist/negotiate.mjs +43 -29
- package/dist/parse.d.mts +16 -1
- package/dist/parse.mjs +1 -2
- package/dist/preset/minimal.d.mts +2 -1
- package/dist/preset/minimal.mjs +1 -2
- package/dist/splitter.mjs +3 -2
- package/dist/text.mjs +1 -2
- package/package.json +2 -2
- package/dist/_chunks/utils.mjs +0 -659
package/dist/negotiate.mjs
CHANGED
|
@@ -1,9 +1,43 @@
|
|
|
1
|
+
function findDelimiter(value, start, delimiter) {
|
|
2
|
+
let isQuoted = false;
|
|
3
|
+
for (let i = start; i < value.length; i++) {
|
|
4
|
+
const char = value.charCodeAt(i);
|
|
5
|
+
if (isQuoted && char === 92) {
|
|
6
|
+
i++;
|
|
7
|
+
continue;
|
|
8
|
+
}
|
|
9
|
+
if (char === 34) {
|
|
10
|
+
isQuoted = !isQuoted;
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
if (!isQuoted && char === delimiter) return i;
|
|
14
|
+
}
|
|
15
|
+
return value.length;
|
|
16
|
+
}
|
|
17
|
+
function parseQuality(part, start) {
|
|
18
|
+
while (start < part.length) {
|
|
19
|
+
let char = part.charCodeAt(start);
|
|
20
|
+
while (char === 32 || char === 9) {
|
|
21
|
+
start++;
|
|
22
|
+
char = part.charCodeAt(start);
|
|
23
|
+
}
|
|
24
|
+
if ((char === 113 || char === 81) && part.charCodeAt(start + 1) === 61) {
|
|
25
|
+
const qStart = start + 2;
|
|
26
|
+
let qEnd = qStart;
|
|
27
|
+
while (qEnd < part.length && part.charCodeAt(qEnd) !== 59 && part.charCodeAt(qEnd) !== 32 && part.charCodeAt(qEnd) !== 9) qEnd++;
|
|
28
|
+
return +part.slice(qStart, qEnd) || 0;
|
|
29
|
+
}
|
|
30
|
+
start = findDelimiter(part, start, 59) + 1;
|
|
31
|
+
}
|
|
32
|
+
return 1;
|
|
33
|
+
}
|
|
1
34
|
function parseAcceptHeader(accept) {
|
|
2
35
|
if (!accept) return [];
|
|
3
36
|
const entries = [];
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const part =
|
|
37
|
+
for (let start = 0, i = 0; start < accept.length; i++) {
|
|
38
|
+
const end = findDelimiter(accept, start, 44);
|
|
39
|
+
const part = accept.slice(start, end).trim();
|
|
40
|
+
start = end + 1;
|
|
7
41
|
if (!part) continue;
|
|
8
42
|
const semicolonIdx = part.indexOf(";");
|
|
9
43
|
let type;
|
|
@@ -11,14 +45,7 @@ function parseAcceptHeader(accept) {
|
|
|
11
45
|
if (semicolonIdx === -1) type = part;
|
|
12
46
|
else {
|
|
13
47
|
type = part.slice(0, semicolonIdx).trim();
|
|
14
|
-
|
|
15
|
-
const qIdx = paramStr.indexOf("q=");
|
|
16
|
-
if (qIdx !== -1) {
|
|
17
|
-
const qStart = qIdx + 2;
|
|
18
|
-
let qEnd = qStart;
|
|
19
|
-
while (qEnd < paramStr.length && paramStr.charCodeAt(qEnd) !== 59 && paramStr.charCodeAt(qEnd) !== 32) qEnd++;
|
|
20
|
-
q = +paramStr.slice(qStart, qEnd) || 0;
|
|
21
|
-
}
|
|
48
|
+
q = parseQuality(part, semicolonIdx + 1);
|
|
22
49
|
}
|
|
23
50
|
entries.push({
|
|
24
51
|
type,
|
|
@@ -42,9 +69,10 @@ function negotiateContent(acceptHeader, secFetchDest) {
|
|
|
42
69
|
let sawAcceptable = false;
|
|
43
70
|
let rejectedMd = false;
|
|
44
71
|
let rejectedHtml = false;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const part =
|
|
72
|
+
for (let start = 0, i = 0; start < accept.length; i++) {
|
|
73
|
+
const end = findDelimiter(accept, start, 44);
|
|
74
|
+
const part = accept.slice(start, end).trim();
|
|
75
|
+
start = end + 1;
|
|
48
76
|
if (!part) continue;
|
|
49
77
|
sawAnyEntry = true;
|
|
50
78
|
const semicolonIdx = part.indexOf(";");
|
|
@@ -53,21 +81,7 @@ function negotiateContent(acceptHeader, secFetchDest) {
|
|
|
53
81
|
if (semicolonIdx === -1) type = part;
|
|
54
82
|
else {
|
|
55
83
|
type = part.slice(0, semicolonIdx).trim();
|
|
56
|
-
|
|
57
|
-
let qIdx = -1;
|
|
58
|
-
for (let j = 0; j < paramStr.length - 1; j++) {
|
|
59
|
-
const c = paramStr.charCodeAt(j);
|
|
60
|
-
if ((c === 113 || c === 81) && paramStr.charCodeAt(j + 1) === 61) {
|
|
61
|
-
qIdx = j;
|
|
62
|
-
break;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (qIdx !== -1) {
|
|
66
|
-
const qStart = qIdx + 2;
|
|
67
|
-
let qEnd = qStart;
|
|
68
|
-
while (qEnd < paramStr.length && paramStr.charCodeAt(qEnd) !== 59 && paramStr.charCodeAt(qEnd) !== 32) qEnd++;
|
|
69
|
-
q = +paramStr.slice(qStart, qEnd) || 0;
|
|
70
|
-
}
|
|
84
|
+
q = parseQuality(part, semicolonIdx + 1);
|
|
71
85
|
}
|
|
72
86
|
const normalized = type.toLowerCase();
|
|
73
87
|
if (normalized === "text/markdown" || normalized === "text/plain") {
|
package/dist/parse.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ElementNode, Node, NodeEvent, TagHandler, TransformPlugin } from "./_chunks/types.mjs";
|
|
1
|
+
import { ElementNode, EngineOptions, Node, NodeEvent, TagHandler, TransformPlugin } from "./_chunks/types.mjs";
|
|
2
2
|
/**
|
|
3
3
|
* Commit end-of-input state: flush trailing buffered text and close any open
|
|
4
4
|
* elements. The streaming parser keeps trailing text and unclosed elements
|
|
@@ -37,8 +37,12 @@ export interface ParseState {
|
|
|
37
37
|
flattenedRawExcludesText?: boolean;
|
|
38
38
|
/** Currently processing element node */
|
|
39
39
|
currentNode?: ElementNode | null;
|
|
40
|
+
/** `<li>` children opened so far in each open `<ol>` or `<ul>`, innermost last */
|
|
41
|
+
listItemCounts?: number[];
|
|
40
42
|
/** Whether current content contains HTML entities that need decoding */
|
|
41
43
|
hasEncodedHtmlEntity?: boolean;
|
|
44
|
+
/** Text buffer offsets where a discarded token ended the DOM text node */
|
|
45
|
+
entitySeals?: number[];
|
|
42
46
|
/** Whether the last processed character was whitespace - for collapsing whitespace */
|
|
43
47
|
lastCharWasWhitespace?: boolean;
|
|
44
48
|
/** Whether the last processed buffer has whitespace - optimization flag */
|
|
@@ -65,6 +69,12 @@ export interface ParseState {
|
|
|
65
69
|
tagOverrideHandlers?: Map<string, TagHandler>;
|
|
66
70
|
/** Whether emitted text should skip Markdown-only escaping */
|
|
67
71
|
plainText?: boolean;
|
|
72
|
+
/** Output state whose `options.origin` the first usable `<base href>` replaces. */
|
|
73
|
+
urlBaseTarget?: {
|
|
74
|
+
options: EngineOptions;
|
|
75
|
+
};
|
|
76
|
+
/** Only the first `<base href>` counts, even when it is not usable. */
|
|
77
|
+
baseHrefSeen?: boolean;
|
|
68
78
|
/**
|
|
69
79
|
* Parsed (whitespace-collapsed) form of the raw run the last parse returned.
|
|
70
80
|
* At end of input it is committed instead of the raw run, so trailing text
|
|
@@ -85,6 +95,11 @@ export interface ParseResult {
|
|
|
85
95
|
* Completely decoupled from markdown generation
|
|
86
96
|
*/
|
|
87
97
|
export declare function parseHtml(html: string, options?: ParseOptions): ParseResult;
|
|
98
|
+
/**
|
|
99
|
+
* Stream-owned opt-in: commit only an ordinary ASCII prose prefix. Public
|
|
100
|
+
* parser calls keep the complete text-node event contract by never calling it.
|
|
101
|
+
*/
|
|
102
|
+
export declare function commitPlainTextPrefix(remainingHtml: string, state: ParseState, onEvent: (event: NodeEvent) => void): string;
|
|
88
103
|
/**
|
|
89
104
|
* Streaming HTML parser - calls onEvent for each DOM event
|
|
90
105
|
*/
|
package/dist/parse.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { finalizeParse, parseAttributes, parseHtml, parseHtmlStream };
|
|
1
|
+
export { commitPlainTextPrefix, finalizeParse, parseAttributes, parseHtml, parseHtmlStream } from "./_chunks/parse.mjs";
|
|
@@ -11,4 +11,5 @@ type PresetInput<T extends MdreamOptions> = Omit<T, 'clean'> & {
|
|
|
11
11
|
* `htmlToMarkdownSplitChunks()`.
|
|
12
12
|
*/
|
|
13
13
|
export declare function withMinimalPreset(options?: PresetInput<MdreamOptions>): MdreamOptions;
|
|
14
|
-
export declare function withMinimalPreset(options: PresetInput<SplitterOptions>): SplitterOptions;
|
|
14
|
+
export declare function withMinimalPreset(options: PresetInput<SplitterOptions>): SplitterOptions;
|
|
15
|
+
export {};
|
package/dist/preset/minimal.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { withMinimalPreset };
|
|
1
|
+
export { withMinimalPreset } from "../_chunks/minimal.mjs";
|
package/dist/splitter.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "./_chunks/const.mjs";
|
|
2
|
-
import { trimOutputStart } from "./_chunks/
|
|
2
|
+
import { trimOutputStart } from "./_chunks/url.mjs";
|
|
3
3
|
import { createMarkdownProcessor, tagHandlers, trimAsciiWhitespaceEnd } from "./_chunks/markdown-processor.mjs";
|
|
4
4
|
import { assertEngineOptions, buildTagOverrideHandlers, checkClean, endPlugins, processPluginsForEvent } from "./_chunks/tag-overrides.mjs";
|
|
5
5
|
import { finalizeParse, parseHtmlStream } from "./_chunks/parse.mjs";
|
|
@@ -264,7 +264,8 @@ function* htmlToMarkdownSplitChunksStream(html, options = {}) {
|
|
|
264
264
|
depth: 0,
|
|
265
265
|
resolvedPlugins: opts.resolvedPlugins,
|
|
266
266
|
tagHandlers,
|
|
267
|
-
tagOverrideHandlers: opts.tagOverrideHandlers
|
|
267
|
+
tagOverrideHandlers: opts.tagOverrideHandlers,
|
|
268
|
+
urlBaseTarget: processor.state
|
|
268
269
|
};
|
|
269
270
|
const leftover = parseHtmlStream(html, parseState, handleEvent);
|
|
270
271
|
finalizeParse(leftover, parseState, handleEvent);
|
package/dist/text.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { htmlToText, streamHtmlToText };
|
|
1
|
+
export { htmlToText, streamHtmlToText } from "./_chunks/text.mjs";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mdream/js",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.0
|
|
4
|
+
"version": "2.1.0",
|
|
5
5
|
"description": "Tree-shakable JavaScript converters and plugins for mdream.",
|
|
6
6
|
"author": {
|
|
7
7
|
"name": "Harlan Wilton",
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
"dist"
|
|
118
118
|
],
|
|
119
119
|
"dependencies": {
|
|
120
|
-
"cac": "^7.0
|
|
120
|
+
"cac": "^7.1.0",
|
|
121
121
|
"pathe": "^2.0.3"
|
|
122
122
|
},
|
|
123
123
|
"scripts": {
|