@readme/markdown 15.5.2 → 15.7.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.
@@ -0,0 +1,10 @@
1
+ import type { Transform } from 'mdast-util-from-markdown';
2
+ /**
3
+ * Serializes the three image shapes a parsed document carries. An image that picked up readme
4
+ * attributes has no markdown spelling left and goes out as `<Image>`, a plain one stays
5
+ * `![alt](src)`.
6
+ *
7
+ * Order matters: `figure` unwraps into the `image` its caption belongs to, so it runs first.
8
+ */
9
+ declare const imagesToJsx: () => Transform;
10
+ export default imagesToJsx;
@@ -0,0 +1,9 @@
1
+ import type { Transform } from 'mdast-util-from-markdown';
2
+ /**
3
+ * A `sidebar: true` magic block (e.g. `[block:code]`) parses into an `rdme-pin` wrapper via
4
+ * `wrapPinnedBlocks`, and remark-stringify throws on any node type without a handler. The mdxish
5
+ * dialect has no spelling for a pin, so the wrapper serializes as its content instead — the same
6
+ * (lossy) unwrap `readmeToMdx` has always done, trading the `sidebar` flag for not crashing.
7
+ */
8
+ declare const unwrapPins: () => Transform;
9
+ export default unwrapPins;
@@ -19045,7 +19045,7 @@ module.exports = function () {
19045
19045
 
19046
19046
  /***/ },
19047
19047
 
19048
- /***/ 9743
19048
+ /***/ 5072
19049
19049
  (module, __webpack_exports__, __webpack_require__) {
19050
19050
 
19051
19051
  "use strict";
@@ -101217,6 +101217,8 @@ const processTableNode = (node, index, parent, documentPosition) => {
101217
101217
  type: 'table',
101218
101218
  position,
101219
101219
  children,
101220
+ // Remember the author's spelling so the serializer can write `<table>` back instead of `<Table>`
101221
+ ...(node.name === 'table' && { data: { lowercaseTable: true } }),
101220
101222
  };
101221
101223
  parent.children[index] = mdNode;
101222
101224
  };
@@ -116819,7 +116821,7 @@ const rehypeToc = ({ components = {} }) => {
116819
116821
  });
116820
116822
  };
116821
116823
  };
116822
- const MAX_DEPTH = 2;
116824
+ const MAX_DEPTH = 3;
116823
116825
  /**
116824
116826
  * Get the depth of a heading element based on its tag name.
116825
116827
  *
@@ -124215,6 +124217,111 @@ const generateSlugForHeadings = () => (tree) => {
124215
124217
  };
124216
124218
  /* harmony default export */ const heading_slugs = (generateSlugForHeadings);
124217
124219
 
124220
+ ;// ./processor/transform/mdxish/images-to-jsx.ts
124221
+ /* unused harmony import specifier */ var images_to_jsx_toMarkdown;
124222
+ /* unused harmony import specifier */ var images_to_jsx_visit;
124223
+ /* unused harmony import specifier */ var images_to_jsx_NodeTypes;
124224
+ /* unused harmony import specifier */ var images_to_jsx_INLINE_ONLY_PARENT_TYPES;
124225
+ /* unused harmony import specifier */ var images_to_jsx_toAttributes;
124226
+
124227
+
124228
+
124229
+
124230
+
124231
+ const IMAGE_ATTRS = (/* unused pure expression or super */ null && (['align', 'alt', 'border', 'caption', 'className', 'height', 'lazy', 'src', 'title', 'width']));
124232
+ /** The three attributes markdown's `![alt](src "title")` can carry. Anything else forces JSX. */
124233
+ const PLAIN_IMAGE_ATTRS = (/* unused pure expression or super */ null && (['alt', 'src', 'title']));
124234
+ const EMOJI_COLONS = /^:(.*):$/;
124235
+ const hasExtra = (attributes) => attributes.some(attr => !PLAIN_IMAGE_ATTRS.includes(attr.name));
124236
+ const toImageJsx = (attributes, children = []) => ({
124237
+ type: 'mdxJsxFlowElement',
124238
+ name: 'Image',
124239
+ attributes,
124240
+ children,
124241
+ });
124242
+ /**
124243
+ * An `image` is phrasing content, but the nodes it replaces here (`image-block`, and a plain
124244
+ * `[block:image]`) sit where flow content belongs. `mdast-util-to-markdown` picks a block separator
124245
+ * from the two node types around it and has no rule for phrasing-next-to-flow, so it emits none and
124246
+ * glues the image to whatever follows (`![a](src)# Heading`), which then cascades through the rest
124247
+ * of the document. Wrapping restores a block for it to join against.
124248
+ */
124249
+ const placeImage = (parent, index, image) => {
124250
+ const wrapped = { type: 'paragraph', children: [image] };
124251
+ parent.children[index] = images_to_jsx_INLINE_ONLY_PARENT_TYPES.has(parent.type) ? image : wrapped;
124252
+ };
124253
+ /**
124254
+ * Serializes the three image shapes a parsed document carries. An image that picked up readme
124255
+ * attributes has no markdown spelling left and goes out as `<Image>`, a plain one stays
124256
+ * `![alt](src)`.
124257
+ *
124258
+ * Order matters: `figure` unwraps into the `image` its caption belongs to, so it runs first.
124259
+ */
124260
+ const imagesToJsx = () => tree => {
124261
+ images_to_jsx_visit(tree, images_to_jsx_NodeTypes.figure, (node, index, parent) => {
124262
+ if (!parent || index === undefined)
124263
+ return;
124264
+ const [image, caption] = node.children;
124265
+ const { align, className, width } = image.data.hProperties;
124266
+ parent.children[index] = toImageJsx(images_to_jsx_toAttributes({ ...image, align, width, ...(className === 'border' && { border: true }), src: image.src || image.url }, IMAGE_ATTRS),
124267
+ // The caption stays a child rather than a pre-serialized `caption` attribute, so readme nodes
124268
+ // inside it (emoji, variables, glossary) reach their own handlers instead of the bare
124269
+ // `toMarkdown` in `compatibility.figureToImageBlock`, which throws on them.
124270
+ caption.children);
124271
+ });
124272
+ images_to_jsx_visit(tree, 'image', (n, index, parent) => {
124273
+ const node = n;
124274
+ if (!parent || index === undefined)
124275
+ return undefined;
124276
+ const hProperties = node.data?.hProperties;
124277
+ // A `:joy:`-style shortcode round-trips as a gemoji rather than the image it parsed into.
124278
+ if (hProperties?.className === 'emoji' && node.title) {
124279
+ const emoji = {
124280
+ type: images_to_jsx_NodeTypes.emoji,
124281
+ name: node.title.replace(EMOJI_COLONS, '$1'),
124282
+ value: node.title,
124283
+ };
124284
+ parent.children[index] = emoji;
124285
+ return undefined;
124286
+ }
124287
+ if (hProperties) {
124288
+ const attributes = images_to_jsx_toAttributes({ ...node, ...hProperties, src: node.url }, IMAGE_ATTRS);
124289
+ if (hasExtra(attributes)) {
124290
+ parent.children[index] = toImageJsx(attributes);
124291
+ return undefined;
124292
+ }
124293
+ }
124294
+ // An attribute-less `[block:image]` parses straight to an `image` in a flow slot, so it needs
124295
+ // the same wrap. Editor images always arrive inside a paragraph and are left alone.
124296
+ if (images_to_jsx_INLINE_ONLY_PARENT_TYPES.has(parent.type))
124297
+ return undefined;
124298
+ placeImage(parent, index, node);
124299
+ // Step over the paragraph just created, or the visitor walks back into the same image.
124300
+ return [(/* inlined export .SKIP */"skip"), index + 1];
124301
+ });
124302
+ images_to_jsx_visit(tree, images_to_jsx_NodeTypes.imageBlock, (node, index, parent) => {
124303
+ if (!parent || index === undefined)
124304
+ return;
124305
+ // An image-block keeps its caption as children, so it has to be re-serialized back into the
124306
+ // `caption` attribute before the node is replaced.
124307
+ const captionChildren = node.children ?? [];
124308
+ const caption = captionChildren.length ? images_to_jsx_toMarkdown({ type: 'root', children: captionChildren }).trim() : '';
124309
+ const attributes = images_to_jsx_toAttributes({ ...node, ...node.data.hProperties, ...(caption && { caption }) }, IMAGE_ATTRS);
124310
+ if (hasExtra(attributes)) {
124311
+ parent.children[index] = toImageJsx(attributes);
124312
+ return;
124313
+ }
124314
+ placeImage(parent, index, {
124315
+ type: 'image',
124316
+ url: node.src,
124317
+ ...(node.title && { title: node.title }),
124318
+ ...(node.alt && { alt: node.alt }),
124319
+ });
124320
+ });
124321
+ return tree;
124322
+ };
124323
+ /* harmony default export */ const images_to_jsx = ((/* unused pure expression or super */ null && (imagesToJsx)));
124324
+
124218
124325
  // EXTERNAL MODULE: ./node_modules/@readme/variable/dist/index.js
124219
124326
  var variable_dist = __webpack_require__(4355);
124220
124327
  var variable_dist_default = /*#__PURE__*/__webpack_require__.n(variable_dist);
@@ -127485,13 +127592,22 @@ const mdxishTablesToJsx = () => tree => {
127485
127592
  gfmCells.push([cell, normalized]);
127486
127593
  return undefined;
127487
127594
  });
127488
- if (!requiresJsxTable) {
127595
+ const stayLowercase = table.data?.lowercaseTable === true;
127596
+ // We transform to GFM tables if:
127597
+ // 1. If it doesn't contain complex elements that the syntax can't represent
127598
+ // 2. The original table is not lowercase HTML <table>, because we want to
127599
+ // preserve original tables as much as possible
127600
+ if (!requiresJsxTable && !stayLowercase) {
127489
127601
  gfmCells.forEach(([cell, children]) => {
127490
127602
  cell.children = children;
127491
127603
  });
127492
127604
  table.type = 'table';
127493
127605
  return;
127494
127606
  }
127607
+ // Nothing to build a JSX table from; leave the empty node to the GFM stringifier.
127608
+ const [headerRow, ...bodyRows] = table.children;
127609
+ if (!headerRow)
127610
+ return;
127495
127611
  mdxish_tables_to_jsx_visit(table, mdxish_tables_to_jsx_isTableCell, flattenBreaksToNewlines);
127496
127612
  const styles = table.align.map(mdxish_tables_to_jsx_alignToStyle);
127497
127613
  const head = {
@@ -127503,7 +127619,7 @@ const mdxishTablesToJsx = () => tree => {
127503
127619
  attributes: [],
127504
127620
  type: 'mdxJsxFlowElement',
127505
127621
  name: 'tr',
127506
- children: table.children[0].children.map((cell, cellIndex) => {
127622
+ children: headerRow.children.map((cell, cellIndex) => {
127507
127623
  return {
127508
127624
  attributes: [],
127509
127625
  type: 'mdxJsxFlowElement',
@@ -127519,7 +127635,7 @@ const mdxishTablesToJsx = () => tree => {
127519
127635
  attributes: [],
127520
127636
  type: 'mdxJsxFlowElement',
127521
127637
  name: 'tbody',
127522
- children: table.children.splice(1).map(row => {
127638
+ children: bodyRows.map(row => {
127523
127639
  return {
127524
127640
  attributes: [],
127525
127641
  type: 'mdxJsxFlowElement',
@@ -127547,8 +127663,8 @@ const mdxishTablesToJsx = () => tree => {
127547
127663
  ];
127548
127664
  const jsx = {
127549
127665
  type: 'mdxJsxFlowElement',
127550
- name: 'Table',
127551
- attributes: table.align.find(a => a) ? attributes : [],
127666
+ name: stayLowercase ? 'table' : 'Table',
127667
+ attributes: !stayLowercase && table.align.find(a => a) ? attributes : [],
127552
127668
  children: [head, body],
127553
127669
  };
127554
127670
  parent.children[index] = jsx;
@@ -127742,7 +127858,9 @@ function loadComponents() {
127742
127858
  }
127743
127859
 
127744
127860
  ;// ./lib/mdxish.ts
127861
+ /* unused harmony import specifier */ var mdxish_mdxExpressionToMarkdown;
127745
127862
  /* unused harmony import specifier */ var mdxish_mdxJsxToMarkdown;
127863
+ /* unused harmony import specifier */ var mdxish_mdxjsEsmToMarkdown;
127746
127864
  /* unused harmony import specifier */ var mdxish_remarkGfm;
127747
127865
  /* unused harmony import specifier */ var mdxish_remarkStringify;
127748
127866
  /* unused harmony import specifier */ var mdxish_unified;
@@ -127750,7 +127868,13 @@ function loadComponents() {
127750
127868
  /* unused harmony import specifier */ var mdxish_DEFAULT_BULLET;
127751
127869
  /* unused harmony import specifier */ var mdxish_mdxishAnchorToJsx;
127752
127870
  /* unused harmony import specifier */ var mdxish_mdxishCalloutToJsx;
127871
+ /* unused harmony import specifier */ var mdxishImagesToJsx;
127753
127872
  /* unused harmony import specifier */ var mdxish_mdxishTablesToJsx;
127873
+ /* unused harmony import specifier */ var unwrapPins;
127874
+
127875
+
127876
+
127877
+
127754
127878
 
127755
127879
 
127756
127880
 
@@ -127881,35 +128005,43 @@ function mdxishAstProcessor(mdContent, opts = {}) {
127881
128005
  };
127882
128006
  }
127883
128007
  /**
127884
- * Registers the mdx-jsx serialization extension so remark-stringify
127885
- * can convert JSX nodes (e.g. `<Table>`) to markdown.
128008
+ * Registers serialization for the node types remark-stringify can't write on its own:
128009
+ * JSX elements (e.g. `<Table>`), MDX expressions, and ESM exports.
127886
128010
  */
127887
- function mdxJsxStringify() {
128011
+ function mdxStringifyExtensions() {
127888
128012
  const data = this.data();
127889
128013
  const extensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
127890
- extensions.push({ extensions: [mdxish_mdxJsxToMarkdown()] });
128014
+ extensions.push({ extensions: [mdxish_mdxJsxToMarkdown(), mdxish_mdxExpressionToMarkdown(), mdxish_mdxjsEsmToMarkdown()] });
127891
128015
  }
128016
+ const stringifyOptions = (/* unused pure expression or super */ null && ({
128017
+ bullet: mdxish_DEFAULT_BULLET,
128018
+ emphasis: '_',
128019
+ // Escape literal braces in text so they don't parse as (often
128020
+ // unterminated) MDX expressions on the next round trip.
128021
+ unsafe: [
128022
+ { character: '{', inConstruct: 'phrasing' },
128023
+ { character: '}', inConstruct: 'phrasing' },
128024
+ ],
128025
+ }));
127892
128026
  /**
127893
128027
  * Serializes an Mdast back into a markdown string.
127894
128028
  */
127895
128029
  function mdxishMdastToMd(mdast) {
127896
128030
  const processor = mdxish_unified()
127897
128031
  .use(mdxish_remarkGfm)
128032
+ // Readme nodes with no markdown spelling go out as JSX, the same tags mdxish re-parses.
127898
128033
  .use(mdxish_mdxishCalloutToJsx)
127899
128034
  .use(mdxish_mdxishTablesToJsx)
127900
128035
  .use(mdxish_mdxishAnchorToJsx)
128036
+ // The rest only a PARSER tree carries.
128037
+ // A `sidebar: true` block parses into an `rdme-pin` wrapper the dialect can't spell.
128038
+ .use(unwrapPins)
128039
+ // Figures, image blocks, and images that picked up readme attributes while parsing.
128040
+ .use(mdxishImagesToJsx)
128041
+ // Handlers for the readme nodes that stay themselves (variables, emoji, html-blocks, lists).
127901
128042
  .use(mdxish_mdxishCompilers)
127902
- .use(mdxJsxStringify)
127903
- .use(mdxish_remarkStringify, {
127904
- bullet: mdxish_DEFAULT_BULLET,
127905
- emphasis: '_',
127906
- // Escape literal braces in text so they don't parse as (often
127907
- // unterminated) MDX expressions on the next round trip.
127908
- unsafe: [
127909
- { character: '{', inConstruct: 'phrasing' },
127910
- { character: '}', inConstruct: 'phrasing' },
127911
- ],
127912
- });
128043
+ .use(mdxStringifyExtensions)
128044
+ .use(mdxish_remarkStringify, stringifyOptions);
127913
128045
  return processor.stringify(processor.runSync(mdast));
127914
128046
  }
127915
128047
  /**
@@ -129023,7 +129155,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"*":["about","acceptCharset","accessK
129023
129155
  /******/ // startup
129024
129156
  /******/ // Load entry module and return exports
129025
129157
  /******/ // This entry module used 'module' so it can't be inlined
129026
- /******/ let __webpack_exports__ = __webpack_require__(9743);
129158
+ /******/ let __webpack_exports__ = __webpack_require__(5072);
129027
129159
  /******/ module.exports = __webpack_exports__;
129028
129160
  /******/
129029
129161
  /******/ })()