@mdream/js 2.0.2 → 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 +67 -33
- 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/_chunks/clean.mjs
CHANGED
|
@@ -11,4 +11,5 @@ export interface ExtractedElement extends ElementNode {
|
|
|
11
11
|
}
|
|
12
12
|
type ExtractionCallback = (element: ExtractedElement, state: PluginState) => void;
|
|
13
13
|
/** Extract matching elements through the composable JavaScript plugin interface. */
|
|
14
|
-
export declare function extractionPlugin(selectors: Record<string, ExtractionCallback>): PluginSetup;
|
|
14
|
+
export declare function extractionPlugin(selectors: Record<string, ExtractionCallback>): PluginSetup;
|
|
15
|
+
export {};
|
package/dist/_chunks/html.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { TagIdMap } from "./const.mjs";
|
|
2
|
-
import { escapeHtml,
|
|
3
|
-
import { resolveUrl, safeAnchorOutput } from "./url.mjs";
|
|
2
|
+
import { escapeHtml, getLanguageFromAttributes, hasNonWhitespace, isSafeHtmlUrl, markRenderedChildContent, parseUnsignedInteger, resolveUrl, safeAnchorOutput, suppressesFormattingInPre } from "./url.mjs";
|
|
4
3
|
import { assertEngineOptions, buildTagOverrideHandlers, checkClean } from "./tag-overrides.mjs";
|
|
5
4
|
import { parserTagHandlers } from "./parse.mjs";
|
|
6
5
|
import { resolvePlugins } from "./plugin.mjs";
|
|
@@ -44,7 +43,7 @@ function safeAttributes(node, tagId) {
|
|
|
44
43
|
return start === void 0 ? "" : ` start="${start}"`;
|
|
45
44
|
}
|
|
46
45
|
if (tagId === 23) {
|
|
47
|
-
const language =
|
|
46
|
+
const language = getLanguageFromAttributes(attributes);
|
|
48
47
|
return language ? ` class="language-${escapeHtml(language, true)}"` : "";
|
|
49
48
|
}
|
|
50
49
|
if (tagId === 31 || tagId === 32) {
|
|
@@ -83,6 +82,8 @@ function processText(node, state, output) {
|
|
|
83
82
|
if (!value) return;
|
|
84
83
|
}
|
|
85
84
|
}
|
|
85
|
+
const top = state.frames.at(-1);
|
|
86
|
+
if (top?._tag === 1 && top.languagePending && hasNonWhitespace(value)) top.languagePending = false;
|
|
86
87
|
for (let index = state.frames.length - 1; index >= 0; index--) {
|
|
87
88
|
const frame = state.frames[index];
|
|
88
89
|
if (frame._tag === 0) {
|
|
@@ -113,9 +114,17 @@ function processHtmlOutputEvent(event, state, output, options) {
|
|
|
113
114
|
const tagId = resolveTagId(element);
|
|
114
115
|
const frame = state.frames.at(-1);
|
|
115
116
|
if (frame?._tag === 1) {
|
|
116
|
-
if (type === 0
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
if (type === 0) {
|
|
118
|
+
if (frame.languagePending && tagId !== 34 && !suppressesFormattingInPre(tagId)) {
|
|
119
|
+
frame.languagePending = false;
|
|
120
|
+
const parent = element.parent;
|
|
121
|
+
if (tagId === 23 && parent?.tagId === 34 && parent.depth === frame.depth) {
|
|
122
|
+
const codeLanguage = getLanguageFromAttributes(element.attributes);
|
|
123
|
+
if (codeLanguage) frame.language = codeLanguage;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (tagId === 6) frame.output += "\n";
|
|
127
|
+
} else if (tagId === 34 && element.depth === frame.depth) closeFrame(state, output, frame);
|
|
119
128
|
return;
|
|
120
129
|
}
|
|
121
130
|
if (type === 0 && tagId !== void 0 && tagId >= 7 && tagId <= 12) {
|
|
@@ -135,7 +144,8 @@ function processHtmlOutputEvent(event, state, output, options) {
|
|
|
135
144
|
state.frames.push({
|
|
136
145
|
_tag: 1,
|
|
137
146
|
depth: element.depth,
|
|
138
|
-
language:
|
|
147
|
+
language: getLanguageFromAttributes(element.attributes),
|
|
148
|
+
languagePending: true,
|
|
139
149
|
output: ""
|
|
140
150
|
});
|
|
141
151
|
return;
|
|
@@ -231,7 +241,7 @@ function createProcessor(options) {
|
|
|
231
241
|
processEvent(event) {
|
|
232
242
|
state.depth = event.node.depth;
|
|
233
243
|
if (event.node.type === 1 ? event.node.excludedFromMarkdown : event.node.parent?.excludedFromMarkdown) return;
|
|
234
|
-
processHtmlOutputEvent(event, outputState, state.buffer, options);
|
|
244
|
+
processHtmlOutputEvent(event, outputState, state.buffer, state.options);
|
|
235
245
|
},
|
|
236
246
|
takeOutput() {
|
|
237
247
|
const output = state.buffer.join("");
|