@readme/markdown 15.2.0 → 15.3.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/README.md CHANGED
@@ -99,6 +99,7 @@ Extends [`CompileOptions`](https://mdxjs.com/packages/mdx/#compileoptions)
99
99
  - **`safeMode`** (`boolean`, optional)—extract script tags from `HTMLBlock`s
100
100
  - **`components`** (`Record<string, string>`, optional)—an object of tag names to mdx.
101
101
  - **`copyButtons`** (`Boolean`, optional) — add a copy button to code blocks
102
+ - **`hardBreaks`** (`boolean`, optional)—render every newline as a `<br>`. `mdxish` defaults to `true`
102
103
 
103
104
  ### `RunOpts`
104
105
 
@@ -3,6 +3,15 @@ import type { Root } from 'hast';
3
3
  import type { Root as MdastRoot } from 'mdast';
4
4
  export interface MdxishOpts {
5
5
  components?: CustomComponents;
6
+ /**
7
+ * Whether a single newline (\n) renders as a `<br>`. Defaults to `true`, matching legacy rdmd.
8
+ * Turn it off for CommonMark semantics, where only a blank line breaks — what content
9
+ * soft-wrapped to a line-length limit (OpenAPI descriptions, linted markdown) expects.
10
+ *
11
+ * Only applies to `mdxish()`; `mdxishAstProcessor` never hard-breaks its MDAST.
12
+ * There's no use for it right now but it can be revisited if needed.
13
+ */
14
+ hardBreaks?: boolean;
6
15
  newEditorTypes?: boolean;
7
16
  /**
8
17
  * When enabled, the pipeline ignores all expression syntax `{...}`.
package/dist/main.js CHANGED
@@ -11423,7 +11423,7 @@ module.exports = function () {
11423
11423
 
11424
11424
  /***/ },
11425
11425
 
11426
- /***/ 8071
11426
+ /***/ 5168
11427
11427
  (module, __webpack_exports__, __webpack_require__) {
11428
11428
 
11429
11429
  "use strict";
@@ -75799,6 +75799,7 @@ var allCSS2RNProps = __webpack_unused_export__ = flatten([allProps, CSS2RNProps]
75799
75799
 
75800
75800
 
75801
75801
 
75802
+
75802
75803
  /**
75803
75804
  * Extract word boundaries from camelCase strings (e.g., "borderWidth" -> ["border", "width"])
75804
75805
  */
@@ -75878,10 +75879,43 @@ const CUSTOM_PROP_BOUNDARIES = [
75878
75879
  */
75879
75880
  const RUNTIME_COMPONENT_TAGS = new Set(['Variable', 'variable', 'html-block', 'rdme-pin']);
75880
75881
  /**
75881
- * Standard HTML tags that should never be treated as custom components.
75882
- * Uses the html-tags package, converted to a Set<string> for efficient lookups.
75882
+ * Elements that are not actually standard HTML tags, or those that we intentionally
75883
+ * don't want to treat as one & is mute to check with. These include:
75884
+ * - SVG/MathML descendants
75885
+ * - Namespaced foreign content
75886
+ * - `image`, which the HTML tree builder rewrites to `img`
75887
+ * Most of these are bundled in parse5's `TAG_NAMES` set, but we can also add a few more.
75888
+ */
75889
+ const NON_STANDARD_TAGS = new Set([
75890
+ 'annotation-xml',
75891
+ 'desc',
75892
+ 'foreignObject',
75893
+ 'image',
75894
+ 'malignmark',
75895
+ 'mglyph',
75896
+ 'mi',
75897
+ 'mn',
75898
+ 'mo',
75899
+ 'ms',
75900
+ 'mtext',
75901
+ ]);
75902
+ /**
75903
+ * Standard HTML tags list.
75904
+ * A use case of this is to differentiate custom components tag vs standard HTML tags.
75905
+ *
75906
+ * Unioned from:
75907
+ * - `html-tags`: All modern spec HTML elements
75908
+ * - parse5's `TAG_NAMES`: Elements the HTML tree-construction algorithm has to special-case
75909
+ * This includes obsolete tags that are still rendered by browsers.
75910
+ * - NON_STANDARD_TAGS: We've had to filter because currently parse5's `TAG_NAMES` set over-enumerates
75911
+ * tags that are not actually standard HTML tags. It also allows custom tags to be filtered out.
75883
75912
  */
75884
- const STANDARD_HTML_TAGS = new Set(html_tags_namespaceObject);
75913
+ const STANDARD_HTML_TAGS = new Set([
75914
+ ...html_tags_namespaceObject,
75915
+ ...Object.values(TAG_NAMES),
75916
+ 'acronym', // Obselete tag not included either of the above sources. Add here if we have missed any.
75917
+ 'blink',
75918
+ ].filter(tag => !NON_STANDARD_TAGS.has(tag)));
75885
75919
  /**
75886
75920
  * Table structural tags. Blank lines inside these carry deliberate meaning for
75887
75921
  * `mdxishTables` (e.g. splitting cell content into paragraphs, or deciding
@@ -101458,27 +101492,6 @@ const mdastV6 = (doc, { rdmd }) => {
101458
101492
  };
101459
101493
  /* harmony default export */ const lib_mdastV6 = (mdastV6);
101460
101494
 
101461
- ;// ./processor/compile/anchor.ts
101462
-
101463
-
101464
- const anchor_anchor = (node) => {
101465
- const { href, label, target, title } = getHProps(node);
101466
- const attrs = {
101467
- ...(label && { label }),
101468
- ...(target && { target }),
101469
- href: href ?? '',
101470
- ...(title && { title }),
101471
- };
101472
- // Serialize children (phrasing content) back to markdown
101473
- // Wrap in paragraph to satisfy RootContent type requirement
101474
- const children = toMarkdown({
101475
- type: 'paragraph',
101476
- children: node.children,
101477
- }).trim();
101478
- return `<Anchor ${formatProps(attrs)}>${children}</Anchor>`;
101479
- };
101480
- /* harmony default export */ const compile_anchor = (anchor_anchor);
101481
-
101482
101495
  ;// ./processor/compile/callout.ts
101483
101496
 
101484
101497
  const callout = (node, _, state, info) => {
@@ -101636,7 +101649,6 @@ const compile_text_text = (node, parent, state, info) => {
101636
101649
 
101637
101650
 
101638
101651
 
101639
-
101640
101652
  function compilers(mdxish = false) {
101641
101653
  const data = this.data();
101642
101654
  const toMarkdownExtensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
@@ -101656,7 +101668,6 @@ function compilers(mdxish = false) {
101656
101668
  plain: compile_plain,
101657
101669
  yaml: compile_compatibility,
101658
101670
  // needed only for mdxish
101659
- ...(mdxish && { [NodeTypes.anchor]: compile_anchor }),
101660
101671
  ...(mdxish && { list: compile_list }),
101661
101672
  ...(mdxish && { listItem: list_item }),
101662
101673
  ...(mdxish && { text: compile_text }),
@@ -103541,6 +103552,39 @@ const mdxComponentHandlers = {
103541
103552
  [NodeTypes.htmlBlock]: htmlBlockHandler,
103542
103553
  };
103543
103554
 
103555
+ ;// ./processor/transform/mdxish/anchor-to-jsx.ts
103556
+
103557
+
103558
+
103559
+ /**
103560
+ * Serializes mdxish anchors to JSX `<Anchor>` syntax. Handing the node to
103561
+ * `mdast-util-mdx-jsx` runs the label through the document's own serializer
103562
+ * state, so readme nodes (variables, emoji, glossary) reach their handlers.
103563
+ */
103564
+ const mdxishAnchorToJsx = () => tree => {
103565
+ visit(tree, NodeTypes.anchor, (node, index, parent) => {
103566
+ if (!parent || index === undefined)
103567
+ return;
103568
+ const { href, label, target, title } = getHProps(node);
103569
+ const jsx = {
103570
+ type: 'mdxJsxTextElement',
103571
+ name: 'Anchor',
103572
+ // An anchor always renders an `href`, even an empty one, so it's built
103573
+ // directly rather than through `toAttributes`, which drops empty values.
103574
+ attributes: [
103575
+ ...toAttributes({ label, target }),
103576
+ { type: 'mdxJsxAttribute', name: 'href', value: href ?? '' },
103577
+ ...toAttributes({ title }),
103578
+ ],
103579
+ children: node.children,
103580
+ position: node.position,
103581
+ };
103582
+ parent.children[index] = jsx;
103583
+ });
103584
+ return tree;
103585
+ };
103586
+ /* harmony default export */ const anchor_to_jsx = (mdxishAnchorToJsx);
103587
+
103544
103588
  ;// ./processor/transform/mdxish/callout-to-jsx.ts
103545
103589
 
103546
103590
 
@@ -105341,8 +105385,11 @@ var variable_default = /*#__PURE__*/__webpack_require__.n(variable_);
105341
105385
  const HTML_TAG_RE = /<\/?([a-zA-Z][a-zA-Z0-9-]*)((?:[^>"']*(?:"[^"]*"|'[^']*'))*[^>"']*)>/g;
105342
105386
  /** Matches an HTML element from its opening tag to the matching closing tag. */
105343
105387
  const HTML_ELEMENT_BLOCK_RE = /<([a-zA-Z][a-zA-Z0-9-]*)[\s>][\s\S]*?<\/\1>/g;
105388
+ const NEWLINE_RE = /\n/g;
105344
105389
  /** Matches a newline with surrounding horizontal whitespace. */
105345
105390
  const NEWLINE_WITH_WHITESPACE_RE = /[^\S\n]*\n[^\S\n]*/g;
105391
+ /** Matches a run of two or more newlines (a blank line) with surrounding horizontal whitespace. */
105392
+ const BLANK_LINE_RE = /[^\S\n]*\n(?:[^\S\n]*\n)+[^\S\n]*/g;
105346
105393
  /** Matches a closing block-level tag followed by non-tag text or by a newline then non-blank content. */
105347
105394
  const CLOSE_BLOCK_TAG_BOUNDARY_RE = /<\/([a-zA-Z][a-zA-Z0-9-]*)>\s*(?:(?!<)(\S)|\n([^\n]))/g;
105348
105395
  /** Strips HTML open/close tags. Used to detect non-tag inner text content. */
@@ -105412,7 +105459,6 @@ const EMPTY_CODE_PLACEHOLDER = {
105412
105459
 
105413
105460
 
105414
105461
 
105415
-
105416
105462
  /**
105417
105463
  * Wraps a node in a "pinned" container if sidebar: true is set.
105418
105464
  */
@@ -105447,16 +105493,13 @@ const textToBlock = (text) => [{ children: textToInline(text), type: 'paragraph'
105447
105493
  */
105448
105494
  const ensureLeadingBreaks = (text) => text.replace(/^\n+/, match => '<br>'.repeat(match.length));
105449
105495
  /** Preprocesses magic block body content before parsing. */
105450
- const preprocessBody = (text) => {
105451
- return ensureLeadingBreaks(text);
105452
- };
105496
+ const preprocessBody = (text, hardBreaks) => (hardBreaks ? ensureLeadingBreaks(text) : text);
105453
105497
  const bodyExtensions = mdxishExtensions(FEATURES.magicBlockBody);
105454
105498
  /** Markdown parser */
105455
105499
  const contentParser = unified()
105456
105500
  .data('micromarkExtensions', bodyExtensions.micromarkExtensions)
105457
105501
  .data('fromMarkdownExtensions', bodyExtensions.fromMarkdownExtensions)
105458
105502
  .use(remarkParse)
105459
- .use(hard_breaks)
105460
105503
  .use(remarkGfm)
105461
105504
  .use(normalize_malformed_md_syntax);
105462
105505
  /**
@@ -105553,17 +105596,21 @@ const processMarkdownInHtmlString = (html) => {
105553
105596
  /**
105554
105597
  * Separate a closing block-level tag from the content that follows it.
105555
105598
  *
105556
- * Each \n in the original text becomes a <br> tag to preserve spacing, then a
105557
- * blank line (\n\n) is appended so CommonMark ends the HTML block and parses
105558
- * the following content as markdown.
105599
+ * A blank line (\n\n) is appended so CommonMark ends the HTML block and parses the
105600
+ * following content as markdown; with hard breaks each \n also becomes a <br> to keep its spacing.
105559
105601
  */
105560
- const separateBlockTagFromContent = (match, tag, inlineChar, nextLineChar) => {
105602
+ const separateBlockTagFromContent = (hardBreaks, match, tag, inlineChar, nextLineChar) => {
105561
105603
  if (!BLOCK_LEVEL_TAGS.has(tag.toLowerCase()))
105562
105604
  return match;
105563
- const newlineCount = (match.match(/\n/g) ?? []).length;
105605
+ const newlineCount = hardBreaks ? (match.match(NEWLINE_RE) ?? []).length : 0;
105564
105606
  const breaks = '<br>'.repeat(newlineCount);
105565
105607
  return `</${tag}>${breaks}\n\n${inlineChar || nextLineChar}`;
105566
105608
  };
105609
+ /**
105610
+ * Newlines inside an HTML block become <br> so CommonMark doesn't end the block on a blank
105611
+ * line. Without hard breaks only blank lines break, but they still have to be replaced.
105612
+ */
105613
+ const collapseHtmlBlockNewlines = (html, hardBreaks) => html.replace(hardBreaks ? NEWLINE_WITH_WHITESPACE_RE : BLANK_LINE_RE, '<br>');
105567
105614
  /** Escape a leading (possibly indented) `-`/`*`/`+` so cells don't become bullet lists. */
105568
105615
  const escapeLeadingListMarkers = (text) => text.replace(/^([ \t]*)([-*+])(?=[ \t]|$)/gm, '$1\\$2');
105569
105616
  /**
@@ -105571,15 +105618,13 @@ const escapeLeadingListMarkers = (text) => text.replace(/^([ \t]*)([-*+])(?=[ \t
105571
105618
  * so `<ul><li>_text_</li></ul>` won't convert underscores to emphasis.
105572
105619
  * We parse first, then visit html nodes and process their text content.
105573
105620
  */
105574
- const parseTableCell = (text) => {
105621
+ const parseTableCell = (text, hardBreaks) => {
105575
105622
  if (!text.trim())
105576
105623
  return [{ type: 'text', value: '' }];
105577
- // Convert \n (and surrounding whitespace) to <br> inside HTML blocks so
105578
- // CommonMark doesn't split them on blank lines.
105579
105624
  const escaped = processBackslashEscapes(text);
105580
105625
  const normalized = escaped
105581
- .replace(HTML_ELEMENT_BLOCK_RE, match => match.replace(NEWLINE_WITH_WHITESPACE_RE, '<br>'))
105582
- .replace(CLOSE_BLOCK_TAG_BOUNDARY_RE, separateBlockTagFromContent);
105626
+ .replace(HTML_ELEMENT_BLOCK_RE, match => collapseHtmlBlockNewlines(match, hardBreaks))
105627
+ .replace(CLOSE_BLOCK_TAG_BOUNDARY_RE, (match, tag, inlineChar, nextLineChar) => separateBlockTagFromContent(hardBreaks, match, tag, inlineChar, nextLineChar));
105583
105628
  const processed = escapeLeadingListMarkers(normalized);
105584
105629
  const tree = contentParser.runSync(contentParser.parse(processed));
105585
105630
  // Process markdown inside HTML blocks that have non-tag inner text (e.g. `<div>**x**`
@@ -105628,7 +105673,7 @@ const parseApiHeaderTitle = (text) => {
105628
105673
  * Transform a magicBlock node into final MDAST nodes.
105629
105674
  */
105630
105675
  function transformMagicBlock(blockType, data, rawValue, options = {}) {
105631
- const { compatibilityMode = false, safeMode = false } = options;
105676
+ const { compatibilityMode = false, hardBreaks = true, safeMode = false } = options;
105632
105677
  // Handle empty data by returning placeholder nodes for known block types
105633
105678
  // This allows the editor to show appropriate placeholder UI instead of nothing
105634
105679
  if (Object.keys(data).length < 1) {
@@ -105767,7 +105812,7 @@ function transformMagicBlock(blockType, data, rawValue, options = {}) {
105767
105812
  });
105768
105813
  }
105769
105814
  if (hasBody) {
105770
- const bodyBlocks = parseBlock(preprocessBody(calloutJson.body || ''));
105815
+ const bodyBlocks = parseBlock(preprocessBody(calloutJson.body || '', hardBreaks));
105771
105816
  children.push(...bodyBlocks);
105772
105817
  }
105773
105818
  const calloutElement = {
@@ -105799,12 +105844,12 @@ function transformMagicBlock(blockType, data, rawValue, options = {}) {
105799
105844
  mapped[rowIndex][colIndex] = v;
105800
105845
  return mapped;
105801
105846
  }, []);
105802
- const tokenizeCell = compatibilityMode
105803
- ? textToBlock
105804
- : parseTableCell;
105847
+ const tokenizeCell = compatibilityMode ? textToBlock : (text) => parseTableCell(text, hardBreaks);
105805
105848
  const tableChildren = Array.from({ length: rows + 1 }, (_, y) => ({
105806
105849
  children: Array.from({ length: cols }, (__, x) => ({
105807
- children: sparseData[y]?.[x] ? tokenizeCell(preprocessBody(sparseData[y][x])) : [{ type: 'text', value: '' }],
105850
+ children: sparseData[y]?.[x]
105851
+ ? tokenizeCell(preprocessBody(sparseData[y][x], hardBreaks))
105852
+ : [{ type: 'text', value: '' }],
105808
105853
  type: y === 0 ? 'tableHead' : 'tableCell',
105809
105854
  })),
105810
105855
  type: 'tableRow',
@@ -107641,6 +107686,7 @@ function loadComponents() {
107641
107686
 
107642
107687
 
107643
107688
 
107689
+
107644
107690
 
107645
107691
 
107646
107692
  const defaultTransformers = [
@@ -107679,7 +107725,7 @@ function preprocessContent(content, opts) {
107679
107725
  return processSnakeCaseComponent(result, { knownComponents });
107680
107726
  }
107681
107727
  function mdxishAstProcessor(mdContent, opts = {}) {
107682
- const { components: userComponents = {}, newEditorTypes = false, safeMode = false, useTailwind } = opts;
107728
+ const { components: userComponents = {}, hardBreaks: enableHardBreaks = true, newEditorTypes = false, safeMode = false, useTailwind, } = opts;
107683
107729
  const components = {
107684
107730
  ...loadComponents(),
107685
107731
  ...userComponents,
@@ -107708,7 +107754,7 @@ function mdxishAstProcessor(mdContent, opts = {}) {
107708
107754
  // The next few transformers must appear after mdxishMdxComponentBlocks
107709
107755
  // so nodes produced by the inline re-parse of component bodies
107710
107756
  // (e.g. code/image/embed inside <Tabs>) get visited too
107711
- .use(magic_block_transformer)
107757
+ .use(magic_block_transformer, { hardBreaks: enableHardBreaks })
107712
107758
  .use(transform_images, { isMdxish: true })
107713
107759
  .use(defaultTransformers)
107714
107760
  .use(newEditorTypes ? inline_mdx_blocks : undefined) // Merge inline html components (e.g. <Anchor>) into MDAST nodes
@@ -107743,6 +107789,7 @@ function mdxishMdastToMd(mdast) {
107743
107789
  .use(remarkGfm)
107744
107790
  .use(callout_to_jsx)
107745
107791
  .use(mdxish_tables_to_jsx)
107792
+ .use(anchor_to_jsx)
107746
107793
  .use(mdxishCompilers)
107747
107794
  .use(mdxJsxStringify)
107748
107795
  .use(remarkStringify, {
@@ -107764,7 +107811,7 @@ function mdxishMdastToMd(mdast) {
107764
107811
  * @see .claude/context/MDXish/Processor Overview.md
107765
107812
  */
107766
107813
  function mdxish(mdContent, opts = {}) {
107767
- const { components: userComponents = {}, safeMode = false, variables } = opts;
107814
+ const { components: userComponents = {}, hardBreaks: enableHardBreaks = true, safeMode = false, variables } = opts;
107768
107815
  const components = {
107769
107816
  ...loadComponents(),
107770
107817
  ...userComponents,
@@ -107776,7 +107823,7 @@ function mdxish(mdContent, opts = {}) {
107776
107823
  const { processor, parserReadyContent } = mdxishAstProcessor(contentWithoutComments, opts);
107777
107824
  processor
107778
107825
  .use(safeMode ? undefined : evaluate_exports) // Evaluate `export const/function` and stash scope on file.data.mdxishScope
107779
- .use(hard_breaks) // Must precede evaluateExpressions to avoid splitting the \n in an evaluated template literal into a <br> node
107826
+ .use(enableHardBreaks ? hard_breaks : undefined) // Must precede evaluateExpressions to avoid splitting the \n in an evaluated template literal into a <br> node
107780
107827
  .use(safeMode ? undefined : evaluate_expressions) // Evaluate self-contained MDX expressions (e.g. `{1+1}`)
107781
107828
  .use(safeMode ? undefined : evaluate_style_block_expressions) // Evaluate `<style>{`...`}</style>` template literals into plain CSS
107782
107829
  .use(variables_code, { variables }) // Resolve <<...>> and {user.*} inside code and inline code nodes
@@ -108764,7 +108811,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"*":["about","acceptCharset","accessK
108764
108811
  /******/ // startup
108765
108812
  /******/ // Load entry module and return exports
108766
108813
  /******/ // This entry module used 'module' so it can't be inlined
108767
- /******/ let __webpack_exports__ = __webpack_require__(8071);
108814
+ /******/ let __webpack_exports__ = __webpack_require__(5168);
108768
108815
  /******/
108769
108816
  /******/ return __webpack_exports__;
108770
108817
  /******/ })()