@readme/markdown 14.12.0 → 14.12.1

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.
@@ -0,0 +1,13 @@
1
+ import type { Root } from 'mdast';
2
+ import type { Plugin } from 'unified';
3
+ /**
4
+ * Converts LF and CRLF line endings into hard breaks while leaving standalone
5
+ * carriage returns as soft whitespace.
6
+ *
7
+ * Unlike `remark-breaks`, this does not promote a lone `\r` into a `<br>`.
8
+ * Standalone carriage returns can be left behind by generators that replace
9
+ * the LF in Windows line endings with an explicit `<br>`, producing input such
10
+ * as `\r<br>`. Treating both characters as hard breaks doubles the spacing.
11
+ */
12
+ declare const hardBreaks: Plugin<[], Root>;
13
+ export default hardBreaks;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * CommonMark indentation helpers, shared by the mdxish preprocessors so tab- and
3
+ * space-indented content is measured (and sliced) on one scale.
4
+ *
5
+ * CommonMark's indented-code threshold is 4 *columns*, and a tab is a 4-column tab
6
+ * stop — not a fixed 4 characters. Counting characters (tab = 1) under-measures
7
+ * tab-indented lines, letting them slip past the 4-column gate so their content
8
+ * fragments into code blocks. Keeping one implementation here stops the two callers
9
+ * from drifting on what "4 columns" means.
10
+ */
11
+ /** The run of leading spaces/tabs on a line. */
12
+ export declare const leadingIndent: (line: string) => string;
13
+ /**
14
+ * Expand a leading-whitespace run to spaces using CommonMark's 4-column tab stops,
15
+ * so a run of mixed tabs/spaces can be measured by length and sliced by column.
16
+ */
17
+ export declare function expandIndentToColumns(indent: string): string;
18
+ /** Indentation width of a line in CommonMark columns (a tab advances to the next 4-column stop). */
19
+ export declare const indentWidth: (line: string) => number;
@@ -109833,63 +109833,6 @@ function rehypeSanitize(options) {
109833
109833
  }
109834
109834
  }
109835
109835
 
109836
- ;// ./node_modules/mdast-util-newline-to-break/lib/index.js
109837
- /**
109838
- * @typedef {import('mdast').Nodes} Nodes
109839
- * @typedef {import('mdast-util-find-and-replace').ReplaceFunction} ReplaceFunction
109840
- */
109841
-
109842
-
109843
-
109844
- /**
109845
- * Turn normal line endings into hard breaks.
109846
- *
109847
- * @param {Nodes} tree
109848
- * Tree to change.
109849
- * @returns {undefined}
109850
- * Nothing.
109851
- */
109852
- function newlineToBreak(tree) {
109853
- findAndReplace(tree, [/\r?\n|\r/g, lib_replace])
109854
- }
109855
-
109856
- /**
109857
- * Replace line endings.
109858
- *
109859
- * @type {ReplaceFunction}
109860
- */
109861
- function lib_replace() {
109862
- return {type: 'break'}
109863
- }
109864
-
109865
- ;// ./node_modules/remark-breaks/lib/index.js
109866
- /**
109867
- * @typedef {import('mdast').Root} Root
109868
- */
109869
-
109870
-
109871
-
109872
- /**
109873
- * Support hard breaks without needing spaces or escapes (turns enters into
109874
- * `<br>`s).
109875
- *
109876
- * @returns
109877
- * Transform.
109878
- */
109879
- function remarkBreaks() {
109880
- /**
109881
- * Transform.
109882
- *
109883
- * @param {Root} tree
109884
- * Tree.
109885
- * @returns {undefined}
109886
- * Nothing.
109887
- */
109888
- return function (tree) {
109889
- newlineToBreak(tree)
109890
- }
109891
- }
109892
-
109893
109836
  ;// ./errors/mdx-syntax-error.ts
109894
109837
  class MdxSyntaxError extends SyntaxError {
109895
109838
  original = null;
@@ -109911,6 +109854,22 @@ class MdxSyntaxError extends SyntaxError {
109911
109854
  }
109912
109855
  }
109913
109856
 
109857
+ ;// ./processor/plugin/hard-breaks.ts
109858
+
109859
+ /**
109860
+ * Converts LF and CRLF line endings into hard breaks while leaving standalone
109861
+ * carriage returns as soft whitespace.
109862
+ *
109863
+ * Unlike `remark-breaks`, this does not promote a lone `\r` into a `<br>`.
109864
+ * Standalone carriage returns can be left behind by generators that replace
109865
+ * the LF in Windows line endings with an explicit `<br>`, producing input such
109866
+ * as `\r<br>`. Treating both characters as hard breaks doubles the spacing.
109867
+ */
109868
+ const hardBreaks = () => tree => {
109869
+ findAndReplace(tree, [/\r?\n/g, () => ({ type: 'break' })]);
109870
+ };
109871
+ /* harmony default export */ const hard_breaks = (hardBreaks);
109872
+
109914
109873
  ;// ./node_modules/estree-util-value-to-estree/dist/estree-util-value-to-estree.js
109915
109874
  /**
109916
109875
  * Create an ESTree identifier node for a given name.
@@ -112615,7 +112574,7 @@ const compile_compile = (text, { components = {}, missingComponents, copyButtons
112615
112574
  const remarkPlugins = [
112616
112575
  remarkFrontmatter,
112617
112576
  lib_remarkGfm,
112618
- ...(hardBreaks ? [remarkBreaks] : []),
112577
+ ...(hardBreaks ? [hard_breaks] : []),
112619
112578
  ...Object.values(transforms),
112620
112579
  [codeTabsTransformer, { copyButtons }],
112621
112580
  [
@@ -121379,10 +121338,36 @@ const mdxishInlineMdxComponents = () => tree => {
121379
121338
  };
121380
121339
  /* harmony default export */ const inline_mdx_blocks = (mdxishInlineMdxComponents);
121381
121340
 
121341
+ ;// ./processor/transform/mdxish/indentation.ts
121342
+ /**
121343
+ * CommonMark indentation helpers, shared by the mdxish preprocessors so tab- and
121344
+ * space-indented content is measured (and sliced) on one scale.
121345
+ *
121346
+ * CommonMark's indented-code threshold is 4 *columns*, and a tab is a 4-column tab
121347
+ * stop — not a fixed 4 characters. Counting characters (tab = 1) under-measures
121348
+ * tab-indented lines, letting them slip past the 4-column gate so their content
121349
+ * fragments into code blocks. Keeping one implementation here stops the two callers
121350
+ * from drifting on what "4 columns" means.
121351
+ */
121352
+ /** The run of leading spaces/tabs on a line. */
121353
+ const leadingIndent = (line) => line.match(/^[ \t]*/)?.[0] ?? '';
121354
+ /**
121355
+ * Expand a leading-whitespace run to spaces using CommonMark's 4-column tab stops,
121356
+ * so a run of mixed tabs/spaces can be measured by length and sliced by column.
121357
+ */
121358
+ function expandIndentToColumns(indent) {
121359
+ return indent
121360
+ .split('')
121361
+ .reduce((columns, char) => columns + (char === '\t' ? ' '.repeat(4 - (columns.length % 4)) : ' '), '');
121362
+ }
121363
+ /** Indentation width of a line in CommonMark columns (a tab advances to the next 4-column stop). */
121364
+ const indentWidth = (line) => expandIndentToColumns(leadingIndent(line)).length;
121365
+
121382
121366
  ;// ./processor/transform/mdxish/terminate-html-flow-blocks.ts
121383
121367
 
121384
121368
 
121385
121369
 
121370
+
121386
121371
  const STANDALONE_HTML_LINE_REGEX = /^(<[a-z][^<>]*>|<\/[a-z][^<>]*>)+\s*$/;
121387
121372
  const HTML_LINE_WITH_CONTENT_REGEX = /^<[a-z][^<>]*>.*<\/[a-z][^<>]*>(?:[^<]*)$/;
121388
121373
  // A line that is exactly one lowercase opening (or self-closing) tag — the shape
@@ -121408,11 +121393,6 @@ function countRawContentTags(line) {
121408
121393
  closes: (line.match(close) ?? []).length,
121409
121394
  }));
121410
121395
  }
121411
- // Indentation width in columns, counting a tab as 4 per CommonMark.
121412
- function indentWidth(line) {
121413
- const leading = line.match(/^[ \t]*/)?.[0] ?? '';
121414
- return leading.replace(/\t/g, ' ').length;
121415
- }
121416
121396
  /**
121417
121397
  * Decides whether a blank line belongs between `line` and `next` so the HTML
121418
121398
  * flow block opened on `line` terminates and `next` parses as markdown.
@@ -121484,6 +121464,7 @@ function terminateHtmlFlowBlocks(content) {
121484
121464
 
121485
121465
 
121486
121466
 
121467
+
121487
121468
  // Matches a JSX attribute expression (e.g. `key={i}`) anywhere in a string. */
121488
121469
  const NESTED_ATTR_EXPRESSION_RE = /[\w-]+\s*=\s*\{/;
121489
121470
  // Name shape mirrors `componentTagPattern`; the lookbehind skips the inner tag
@@ -121494,25 +121475,33 @@ const NESTED_COMPONENT_TAG_RE = /(?<!<)<([A-Z][A-Za-z0-9_]*)[\s/>]/g;
121494
121475
  const hasNestedGenericComponentTag = (content) => [...content.matchAll(NESTED_COMPONENT_TAG_RE)].some(match => !GENERIC_MDX_COMPONENT_EXCLUDED_TAGS.has(match[1]));
121495
121476
  /**
121496
121477
  * Strip the shared leading indentation from a component body so readability indentation
121497
- * isn't parsed as indented code (4+ spaces), e.g. ` <p>` / ` text` -> `<p>` / ` text`.
121478
+ * isn't parsed as indented code (4+ columns), e.g. ` <p>` / ` text` -> `<p>` / ` text`.
121498
121479
  * Relative indentation is kept, so content genuinely 4+ columns deeper stays code. We
121499
121480
  * only strip when a line actually reaches 4 columns; otherwise the body is left as-is so
121500
121481
  * its leading whitespace survives as text nodes (mixed component + HTML content needs it).
121482
+ *
121483
+ * Indentation is measured in CommonMark columns (tab = up to 4), matching how the parser
121484
+ * decides indented code. A char count (tab = 1) under-measures tab-indented bodies, so
121485
+ * they slip past the 4-column gate and their nested content fragments into code blocks.
121501
121486
  */
121502
121487
  function safeDeindent(text) {
121503
121488
  const lines = text.split('\n');
121504
121489
  const nonEmptyLines = lines.filter(line => line.trim().length > 0);
121505
121490
  if (nonEmptyLines.length === 0)
121506
121491
  return text;
121507
- // Indent counts characters (tab = 1), unlike indentWidth's CommonMark columns
121508
- // (tab = 4) in terminate-html-flow-blocks.
121509
- const indents = nonEmptyLines.map(line => line.match(/^(\s*)/)?.[1].length ?? 0);
121492
+ const indents = nonEmptyLines.map(line => expandIndentToColumns(leadingIndent(line)).length);
121510
121493
  const minIndent = Math.min(...indents);
121511
121494
  const maxIndent = Math.max(...indents);
121512
- const stripAmount = maxIndent > 3 ? minIndent : 0;
121513
- if (stripAmount === 0)
121495
+ if (maxIndent < 4 || minIndent === 0)
121514
121496
  return text;
121515
- return lines.map(line => line.slice(stripAmount)).join('\n');
121497
+ // Expand each line's leading run to spaces before slicing so a shared indent of mixed
121498
+ // tabs/spaces (and partial-tab remainders) strips cleanly while relative depth survives.
121499
+ return lines
121500
+ .map(line => {
121501
+ const indent = leadingIndent(line);
121502
+ return expandIndentToColumns(indent).slice(minIndent) + line.slice(indent.length);
121503
+ })
121504
+ .join('\n');
121516
121505
  }
121517
121506
  /**
121518
121507
  * Parse component-body markdown into mdast children. Dedenting shifts columns and
@@ -124107,7 +124096,7 @@ const textToBlock = (text) => [{ children: textToInline(text), type: 'paragraph'
124107
124096
  /**
124108
124097
  * Converts leading newlines in magic block content to `<br>` tags.
124109
124098
  * Leading newlines are stripped by remark-parse before they become soft break nodes,
124110
- * so remark-breaks cannot handle them. We convert them to HTML `<br>` tags instead.
124099
+ * so the hard-breaks plugin cannot handle them. We convert them to HTML `<br>` tags instead.
124111
124100
  */
124112
124101
  const ensureLeadingBreaks = (text) => text.replace(/^\n+/, match => '<br>'.repeat(match.length));
124113
124102
  /** Preprocesses magic block body content before parsing. */
@@ -124119,7 +124108,7 @@ const contentParser = lib_unified()
124119
124108
  .data('micromarkExtensions', [syntax_gemoji(), legacyVariable(), looseHtmlEntity()])
124120
124109
  .data('fromMarkdownExtensions', [gemojiFromMarkdown(), legacyVariableFromMarkdown(), emptyTaskListItemFromMarkdown(), looseHtmlEntityFromMarkdown()])
124121
124110
  .use(lib_remarkParse)
124122
- .use(remarkBreaks)
124111
+ .use(hard_breaks)
124123
124112
  .use(lib_remarkGfm)
124124
124113
  .use(normalize_malformed_md_syntax);
124125
124114
  /**
@@ -126903,7 +126892,7 @@ function mdxish_mdxish(mdContent, opts = {}) {
126903
126892
  const { processor, parserReadyContent } = mdxishAstProcessor(contentWithoutComments, opts);
126904
126893
  processor
126905
126894
  .use(safeMode ? undefined : evaluate_exports) // Evaluate `export const/function` and stash scope on file.data.mdxishScope
126906
- .use(remarkBreaks) // Must precede evaluateExpressions to avoid splitting the \n in an evaluated template literal into a <br> node
126895
+ .use(hard_breaks) // Must precede evaluateExpressions to avoid splitting the \n in an evaluated template literal into a <br> node
126907
126896
  .use(safeMode ? undefined : evaluate_expressions) // Evaluate self-contained MDX expressions (e.g. `{1+1}`)
126908
126897
  .use(safeMode ? undefined : evaluate_style_block_expressions) // Evaluate `<style>{`...`}</style>` template literals into plain CSS
126909
126898
  .use(variables_code, { variables }) // Resolve <<...>> and {user.*} inside code and inline code nodes