@readme/markdown 13.6.1 → 13.6.2

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.
@@ -9,6 +9,13 @@ interface Options {
9
9
  * their respective regexes.
10
10
  */
11
11
  preserveVariableSyntax?: boolean;
12
+ /**
13
+ * Separator to use when joining sibling nodes.
14
+ * Defaults to a space for document-level plain text extraction.
15
+ * Use an empty string for inline-only contexts like TOC labels, where
16
+ * adjacent inline siblings should preserve authored adjacency.
17
+ */
18
+ separator?: string;
12
19
  variables?: Record<string, string>;
13
20
  }
14
21
  declare const plain: (node: Nodes, opts?: Options) => string | number | true | (string | number)[];
package/dist/main.js CHANGED
@@ -53015,11 +53015,12 @@ function plain_one(node, opts) {
53015
53015
  function plain_all(node, opts) {
53016
53016
  let index = -1;
53017
53017
  const result = [];
53018
+ const separator = opts.separator ?? ' ';
53018
53019
  // eslint-disable-next-line no-plusplus
53019
53020
  while (++index < node?.children.length) {
53020
53021
  result[index] = plain_one(node.children[index], opts);
53021
53022
  }
53022
- return result.join(' ').replaceAll(/\s+/g, ' ').trim();
53023
+ return result.join(separator).replaceAll(/\s+/g, ' ').trim();
53023
53024
  }
53024
53025
  const plain = (node, opts = {}) => {
53025
53026
  return 'children' in node ? plain_all(node, opts) || plain_one(node, opts) : plain_one(node, opts);
@@ -71261,6 +71262,7 @@ const normalizeEmphasisAST = () => (tree) => {
71261
71262
 
71262
71263
 
71263
71264
 
71265
+
71264
71266
  const isTableCell = (node) => isMDXElement(node) && ['th', 'td'].includes(node.name);
71265
71267
  const tableTypes = {
71266
71268
  tr: 'tableRow',
@@ -71271,7 +71273,7 @@ const tableNodeProcessor = unified()
71271
71273
  .use(remarkParse)
71272
71274
  .use(remarkMdx)
71273
71275
  .use(normalize_malformed_md_syntax)
71274
- .use([callouts, gemoji_])
71276
+ .use([callouts, gemoji_, code_tabs])
71275
71277
  .use(remarkGfm);
71276
71278
  /**
71277
71279
  * Check if children are only text nodes that might contain markdown
@@ -86943,7 +86945,7 @@ const tocToHast = (headings = [], variables) => {
86943
86945
  stack.pop();
86944
86946
  }
86945
86947
  if (heading.properties) {
86946
- const content = lib_plain({ type: 'root', children: heading.children }, { variables: flatVars });
86948
+ const content = lib_plain({ type: 'root', children: heading.children }, { separator: '', variables: flatVars });
86947
86949
  stack[stack.length - 1].children.push(hastscript_lib_h('li', null, hastscript_lib_h('a', { href: `#${heading.properties.id}` }, content)));
86948
86950
  }
86949
86951
  });
@@ -93754,6 +93756,14 @@ const rehypeMdxishComponents = ({ components, processMarkdown }) => {
93754
93756
  visit(tree, 'element', (node, index, parent) => {
93755
93757
  if (index === undefined || !parent)
93756
93758
  return;
93759
+ // Parse Image caption as markdown so it renders formatted (bold, code,
93760
+ // decoded entities) in the figcaption instead of as a raw string.
93761
+ // rehypeRaw strips children from <img> (void element), so we must
93762
+ // re-process the caption here, after rehypeRaw.
93763
+ if (node.tagName === 'img' && typeof node.properties?.caption === 'string' && !node.children?.length) {
93764
+ const captionHast = processMarkdown(node.properties.caption);
93765
+ node.children = (captionHast.children ?? []).filter(isElementContentNode);
93766
+ }
93757
93767
  // Skip runtime components and standard HTML tags
93758
93768
  if (RUNTIME_COMPONENT_TAGS.has(node.tagName))
93759
93769
  return;
@@ -95816,6 +95826,21 @@ const stripClosingTagFromParagraph = (node, tag) => {
95816
95826
  if (closingIndex === -1)
95817
95827
  return { paragraph: node, found: false };
95818
95828
  children.splice(closingIndex, 1);
95829
+ // After removing the closing tag, trim trailing whitespace/newlines from the
95830
+ // preceding text node. Remark parses "Hello\n</Callout>" as text("Hello\n") +
95831
+ // html("</Callout>"), and the leftover \n would be converted to <br> in HAST.
95832
+ if (closingIndex > 0) {
95833
+ const prev = children[closingIndex - 1];
95834
+ if (prev.type === 'text') {
95835
+ const trimmed = prev.value.trimEnd();
95836
+ if (trimmed) {
95837
+ prev.value = trimmed;
95838
+ }
95839
+ else {
95840
+ children.splice(closingIndex - 1, 1);
95841
+ }
95842
+ }
95843
+ }
95819
95844
  return { paragraph: { ...node, children }, found: true };
95820
95845
  };
95821
95846
  /**
@@ -96428,6 +96453,7 @@ const mdxishInlineComponents = () => tree => {
96428
96453
 
96429
96454
 
96430
96455
 
96456
+
96431
96457
  const transformAnchor = (jsx) => {
96432
96458
  const attrs = getAttrs(jsx);
96433
96459
  const { href = '', label, target, title } = attrs;
@@ -96467,6 +96493,7 @@ const transformImage = (jsx) => {
96467
96493
  alt,
96468
96494
  border: border !== undefined ? String(border) : undefined,
96469
96495
  caption,
96496
+ children: caption ? lib_mdast(caption).children : [],
96470
96497
  className,
96471
96498
  height: height !== undefined ? String(height) : undefined,
96472
96499
  lazy,
package/dist/main.node.js CHANGED
@@ -73219,11 +73219,12 @@ function plain_one(node, opts) {
73219
73219
  function plain_all(node, opts) {
73220
73220
  let index = -1;
73221
73221
  const result = [];
73222
+ const separator = opts.separator ?? ' ';
73222
73223
  // eslint-disable-next-line no-plusplus
73223
73224
  while (++index < node?.children.length) {
73224
73225
  result[index] = plain_one(node.children[index], opts);
73225
73226
  }
73226
- return result.join(' ').replaceAll(/\s+/g, ' ').trim();
73227
+ return result.join(separator).replaceAll(/\s+/g, ' ').trim();
73227
73228
  }
73228
73229
  const plain = (node, opts = {}) => {
73229
73230
  return 'children' in node ? plain_all(node, opts) || plain_one(node, opts) : plain_one(node, opts);
@@ -91465,6 +91466,7 @@ const normalizeEmphasisAST = () => (tree) => {
91465
91466
 
91466
91467
 
91467
91468
 
91469
+
91468
91470
  const isTableCell = (node) => isMDXElement(node) && ['th', 'td'].includes(node.name);
91469
91471
  const tableTypes = {
91470
91472
  tr: 'tableRow',
@@ -91475,7 +91477,7 @@ const tableNodeProcessor = unified()
91475
91477
  .use(remarkParse)
91476
91478
  .use(remarkMdx)
91477
91479
  .use(normalize_malformed_md_syntax)
91478
- .use([callouts, gemoji_])
91480
+ .use([callouts, gemoji_, code_tabs])
91479
91481
  .use(remarkGfm);
91480
91482
  /**
91481
91483
  * Check if children are only text nodes that might contain markdown
@@ -107147,7 +107149,7 @@ const tocToHast = (headings = [], variables) => {
107147
107149
  stack.pop();
107148
107150
  }
107149
107151
  if (heading.properties) {
107150
- const content = lib_plain({ type: 'root', children: heading.children }, { variables: flatVars });
107152
+ const content = lib_plain({ type: 'root', children: heading.children }, { separator: '', variables: flatVars });
107151
107153
  stack[stack.length - 1].children.push(hastscript_lib_h('li', null, hastscript_lib_h('a', { href: `#${heading.properties.id}` }, content)));
107152
107154
  }
107153
107155
  });
@@ -113958,6 +113960,14 @@ const rehypeMdxishComponents = ({ components, processMarkdown }) => {
113958
113960
  visit(tree, 'element', (node, index, parent) => {
113959
113961
  if (index === undefined || !parent)
113960
113962
  return;
113963
+ // Parse Image caption as markdown so it renders formatted (bold, code,
113964
+ // decoded entities) in the figcaption instead of as a raw string.
113965
+ // rehypeRaw strips children from <img> (void element), so we must
113966
+ // re-process the caption here, after rehypeRaw.
113967
+ if (node.tagName === 'img' && typeof node.properties?.caption === 'string' && !node.children?.length) {
113968
+ const captionHast = processMarkdown(node.properties.caption);
113969
+ node.children = (captionHast.children ?? []).filter(isElementContentNode);
113970
+ }
113961
113971
  // Skip runtime components and standard HTML tags
113962
113972
  if (RUNTIME_COMPONENT_TAGS.has(node.tagName))
113963
113973
  return;
@@ -116020,6 +116030,21 @@ const stripClosingTagFromParagraph = (node, tag) => {
116020
116030
  if (closingIndex === -1)
116021
116031
  return { paragraph: node, found: false };
116022
116032
  children.splice(closingIndex, 1);
116033
+ // After removing the closing tag, trim trailing whitespace/newlines from the
116034
+ // preceding text node. Remark parses "Hello\n</Callout>" as text("Hello\n") +
116035
+ // html("</Callout>"), and the leftover \n would be converted to <br> in HAST.
116036
+ if (closingIndex > 0) {
116037
+ const prev = children[closingIndex - 1];
116038
+ if (prev.type === 'text') {
116039
+ const trimmed = prev.value.trimEnd();
116040
+ if (trimmed) {
116041
+ prev.value = trimmed;
116042
+ }
116043
+ else {
116044
+ children.splice(closingIndex - 1, 1);
116045
+ }
116046
+ }
116047
+ }
116023
116048
  return { paragraph: { ...node, children }, found: true };
116024
116049
  };
116025
116050
  /**
@@ -116632,6 +116657,7 @@ const mdxishInlineComponents = () => tree => {
116632
116657
 
116633
116658
 
116634
116659
 
116660
+
116635
116661
  const transformAnchor = (jsx) => {
116636
116662
  const attrs = getAttrs(jsx);
116637
116663
  const { href = '', label, target, title } = attrs;
@@ -116671,6 +116697,7 @@ const transformImage = (jsx) => {
116671
116697
  alt,
116672
116698
  border: border !== undefined ? String(border) : undefined,
116673
116699
  caption,
116700
+ children: caption ? lib_mdast(caption).children : [],
116674
116701
  className,
116675
116702
  height: height !== undefined ? String(height) : undefined,
116676
116703
  lazy,