@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/text.mjs
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { DEFAULT_BLOCK_SPACING, LIST_ITEM_SPACING, NO_SPACING, TABLE_ROW_SPACING } from "./const.mjs";
|
|
2
|
-
import { figcaptionOwnsBlockSpacing, isDataUrl, isInsideHeading, isInsideTableCell, lastOutputChar, markRenderedChildContent, trimOutputStart, trimTextAtLineStart } from "./
|
|
3
|
-
import { resolveUrl } from "./url.mjs";
|
|
2
|
+
import { figcaptionOwnsBlockSpacing, isDataUrl, isInsideHeading, isInsideTableCell, lastOutputChar, markRenderedChildContent, needsSpacing, resolveUrl, trimOutputStart, trimTextAtLineStart } 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";
|
|
@@ -30,7 +29,7 @@ function currentColumn(buffer, base, scan) {
|
|
|
30
29
|
scan[1] = columnAt(value, value.length, scan[1]);
|
|
31
30
|
}
|
|
32
31
|
const tail = buffer.at(-1);
|
|
33
|
-
return tail ? columnAt(tail, tail.length, scan[1]) :
|
|
32
|
+
return tail ? columnAt(tail, tail.length, scan[1]) : scan[1];
|
|
34
33
|
}
|
|
35
34
|
function columnAt(value, end, column) {
|
|
36
35
|
const newline = end > 0 ? value.lastIndexOf("\n", end - 1) : -1;
|
|
@@ -152,11 +151,11 @@ function elementOutput(node, eventType, state) {
|
|
|
152
151
|
const output = alt !== void 0 ? alt || void 0 : node.attributes.title || resolveUrl(isDataUrl(src) ? "" : src, state.options.origin, state.options.clean) || void 0;
|
|
153
152
|
if (output && hasVisibleContent(output)) {
|
|
154
153
|
markRenderedChildContent(node);
|
|
155
|
-
if (lastOutputChar(state.buffer)
|
|
154
|
+
if (needsSpacing(charOf(lastOutputChar(state.buffer)), output[0])) return ` ${output}`;
|
|
156
155
|
}
|
|
157
156
|
return output;
|
|
158
157
|
}
|
|
159
|
-
if (node.tagId === 81) return lastOutputChar(state.buffer)
|
|
158
|
+
if (node.tagId === 81) return needsSpacing(charOf(lastOutputChar(state.buffer)), "\"") ? " \"" : "\"";
|
|
160
159
|
} else if (node.tagId === 81) return "\"";
|
|
161
160
|
}
|
|
162
161
|
function trailingNewlines(buffer) {
|
|
@@ -197,19 +196,20 @@ function appendOutput(state, element, eventType, output) {
|
|
|
197
196
|
}
|
|
198
197
|
const closesPre = element.tagId === 34;
|
|
199
198
|
const inPre = state.depthMap[34] > 0 && !closesPre;
|
|
199
|
+
const keepsOwnSpaces = closesPre && missingNewlines === 0 && state.lastTextNode?.parent === element && state.lastTextNode.index === element.currentWalkIndex - 1;
|
|
200
200
|
if (buffer.length && state.lastTextNode?.containsWhitespace && !inPre) {
|
|
201
201
|
const isBlock = !isInline && missingNewlines > 0;
|
|
202
202
|
const collapses = element.tagHandler?.collapsesInnerWhiteSpace;
|
|
203
203
|
const hasSpacing = Array.isArray(element.tagHandler?.spacing);
|
|
204
|
-
if (element.tagId === 6 && output?.endsWith("\n") || isBlock || (!isInline || eventType === 1) && !(collapses && eventType === 0) && !(hasSpacing && eventType === 0)) {
|
|
204
|
+
if ((element.tagId === 6 && output?.endsWith("\n") || isBlock || (!isInline || eventType === 1) && !(collapses && eventType === 0) && !(hasSpacing && eventType === 0)) && !keepsOwnSpaces) {
|
|
205
205
|
const last = buffer.at(-1);
|
|
206
|
-
const trimmed = closesPre ? trimSpacesEnd(last) : trimAsciiWhitespaceEnd(last);
|
|
206
|
+
const trimmed = element.tagId === 6 && state.depthMap[28] > 0 ? trimSpacesEnd(last, true) : closesPre || state.lastTextNode.parent?.tagId === 34 ? trimSpacesEnd(last) : trimAsciiWhitespaceEnd(last);
|
|
207
207
|
if (trimmed.length !== last.length) {
|
|
208
208
|
buffer[buffer.length - 1] = trimmed;
|
|
209
209
|
if (eventType === 1 && isInline) state.pendingInlineWhitespace = true;
|
|
210
210
|
}
|
|
211
211
|
}
|
|
212
|
-
state.lastTextNode = void 0;
|
|
212
|
+
if (!keepsOwnSpaces) state.lastTextNode = void 0;
|
|
213
213
|
}
|
|
214
214
|
const newline = missingNewlines ? "\n".repeat(missingNewlines) : "";
|
|
215
215
|
if (eventType === 0 && newline) buffer.push(newline);
|
|
@@ -342,7 +342,7 @@ function createTextOutputProcessor(options, hasPlugins = false) {
|
|
|
342
342
|
state.pendingInlineWhitespace = false;
|
|
343
343
|
if (output && !state.depthMap[34] && state.buffer.length > 0) {
|
|
344
344
|
const tail = state.buffer[state.buffer.length - 1];
|
|
345
|
-
const trimmed = trimSpacesEnd(tail);
|
|
345
|
+
const trimmed = trimSpacesEnd(tail, state.depthMap[28] > 0);
|
|
346
346
|
if (trimmed.length !== tail.length) state.buffer[state.buffer.length - 1] = trimmed;
|
|
347
347
|
}
|
|
348
348
|
if (output && captionOpen > 0 && !captionContent) captionBreakRun++;
|
|
@@ -524,6 +524,7 @@ assign([6, 54], {
|
|
|
524
524
|
collapsesInnerWhiteSpace: true,
|
|
525
525
|
isInline: true
|
|
526
526
|
});
|
|
527
|
+
assign([52, 53], { spacing: NO_SPACING });
|
|
527
528
|
assign([
|
|
528
529
|
88,
|
|
529
530
|
70,
|
package/dist/_chunks/types.d.mts
CHANGED
|
@@ -314,12 +314,44 @@ interface MdreamRuntimeState extends Partial<MdreamProcessingState>, PluginState
|
|
|
314
314
|
preFencePendingDepth?: number;
|
|
315
315
|
preFenceLang?: string;
|
|
316
316
|
preFenceOwnerDepth?: number;
|
|
317
|
+
/** A fence may be misread by a parser; see MarkdownState. */
|
|
318
|
+
fencesUnreliable?: boolean;
|
|
319
|
+
preFenceInline?: boolean;
|
|
320
|
+
/** Element whose enter opened the deferred <pre> fence. */
|
|
321
|
+
preFenceOpener?: ElementNode;
|
|
322
|
+
/** Open fenced block, whose opener is the fragment at this index. */
|
|
323
|
+
codeFence?: {
|
|
324
|
+
fragment: number;
|
|
325
|
+
};
|
|
317
326
|
/** Number of default blockquotes currently buffered for line prefixing. */
|
|
318
327
|
bufferedBlockquoteDepth?: number;
|
|
328
|
+
/** Fragments the buffered blockquotes' content starts at, innermost last. */
|
|
329
|
+
blockquotes?: ReadonlyArray<{
|
|
330
|
+
readonly fragment: number;
|
|
331
|
+
}>;
|
|
319
332
|
/** Content-column prefix deferred after a list item rule. */
|
|
320
333
|
listRulePending?: string;
|
|
321
334
|
/** Whether output should omit Markdown/HTML markup */
|
|
322
335
|
plainText?: boolean;
|
|
336
|
+
/**
|
|
337
|
+
* A `<div>`'s heading-marker check, kept with the entries the walk ends and
|
|
338
|
+
* stops in so divs that leave the line unchanged don't redo it.
|
|
339
|
+
* @internal
|
|
340
|
+
*/
|
|
341
|
+
markerLine?: MarkerLineMemo;
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* A `<div>`'s heading-marker answer with the entries the check ended and
|
|
345
|
+
* stopped in. `noteBufferRewrite` drops it whenever output at or before
|
|
346
|
+
* `index` is rewritten.
|
|
347
|
+
* @internal
|
|
348
|
+
*/
|
|
349
|
+
interface MarkerLineMemo {
|
|
350
|
+
index: number;
|
|
351
|
+
entry: string;
|
|
352
|
+
stop: number;
|
|
353
|
+
stopEntry: string;
|
|
354
|
+
opens: boolean;
|
|
323
355
|
}
|
|
324
356
|
type NodeEventEnter = 0;
|
|
325
357
|
type NodeEventExit = 1;
|
|
@@ -386,6 +418,8 @@ export interface TagHandler {
|
|
|
386
418
|
* strings so markers like `^`/`~` attach to adjacent content (issue #93).
|
|
387
419
|
*/
|
|
388
420
|
literalEnter?: boolean;
|
|
421
|
+
/** Whether a declarative literal enter starts with an ATX heading prefix. */
|
|
422
|
+
literalEnterHeading?: boolean;
|
|
389
423
|
/** When true, the `exit` string is a user-supplied tagOverride, exempt from empty-pair cleanup. */
|
|
390
424
|
literalExit?: boolean;
|
|
391
425
|
/** Whether a declarative literal exit string writes output. */
|