@readme/markdown 15.5.2 → 15.6.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";
@@ -124215,6 +124215,111 @@ const generateSlugForHeadings = () => (tree) => {
124215
124215
  };
124216
124216
  /* harmony default export */ const heading_slugs = (generateSlugForHeadings);
124217
124217
 
124218
+ ;// ./processor/transform/mdxish/images-to-jsx.ts
124219
+ /* unused harmony import specifier */ var images_to_jsx_toMarkdown;
124220
+ /* unused harmony import specifier */ var images_to_jsx_visit;
124221
+ /* unused harmony import specifier */ var images_to_jsx_NodeTypes;
124222
+ /* unused harmony import specifier */ var images_to_jsx_INLINE_ONLY_PARENT_TYPES;
124223
+ /* unused harmony import specifier */ var images_to_jsx_toAttributes;
124224
+
124225
+
124226
+
124227
+
124228
+
124229
+ const IMAGE_ATTRS = (/* unused pure expression or super */ null && (['align', 'alt', 'border', 'caption', 'className', 'height', 'lazy', 'src', 'title', 'width']));
124230
+ /** The three attributes markdown's `![alt](src "title")` can carry. Anything else forces JSX. */
124231
+ const PLAIN_IMAGE_ATTRS = (/* unused pure expression or super */ null && (['alt', 'src', 'title']));
124232
+ const EMOJI_COLONS = /^:(.*):$/;
124233
+ const hasExtra = (attributes) => attributes.some(attr => !PLAIN_IMAGE_ATTRS.includes(attr.name));
124234
+ const toImageJsx = (attributes, children = []) => ({
124235
+ type: 'mdxJsxFlowElement',
124236
+ name: 'Image',
124237
+ attributes,
124238
+ children,
124239
+ });
124240
+ /**
124241
+ * An `image` is phrasing content, but the nodes it replaces here (`image-block`, and a plain
124242
+ * `[block:image]`) sit where flow content belongs. `mdast-util-to-markdown` picks a block separator
124243
+ * from the two node types around it and has no rule for phrasing-next-to-flow, so it emits none and
124244
+ * glues the image to whatever follows (`![a](src)# Heading`), which then cascades through the rest
124245
+ * of the document. Wrapping restores a block for it to join against.
124246
+ */
124247
+ const placeImage = (parent, index, image) => {
124248
+ const wrapped = { type: 'paragraph', children: [image] };
124249
+ parent.children[index] = images_to_jsx_INLINE_ONLY_PARENT_TYPES.has(parent.type) ? image : wrapped;
124250
+ };
124251
+ /**
124252
+ * Serializes the three image shapes a parsed document carries. An image that picked up readme
124253
+ * attributes has no markdown spelling left and goes out as `<Image>`, a plain one stays
124254
+ * `![alt](src)`.
124255
+ *
124256
+ * Order matters: `figure` unwraps into the `image` its caption belongs to, so it runs first.
124257
+ */
124258
+ const imagesToJsx = () => tree => {
124259
+ images_to_jsx_visit(tree, images_to_jsx_NodeTypes.figure, (node, index, parent) => {
124260
+ if (!parent || index === undefined)
124261
+ return;
124262
+ const [image, caption] = node.children;
124263
+ const { align, className, width } = image.data.hProperties;
124264
+ parent.children[index] = toImageJsx(images_to_jsx_toAttributes({ ...image, align, width, ...(className === 'border' && { border: true }), src: image.src || image.url }, IMAGE_ATTRS),
124265
+ // The caption stays a child rather than a pre-serialized `caption` attribute, so readme nodes
124266
+ // inside it (emoji, variables, glossary) reach their own handlers instead of the bare
124267
+ // `toMarkdown` in `compatibility.figureToImageBlock`, which throws on them.
124268
+ caption.children);
124269
+ });
124270
+ images_to_jsx_visit(tree, 'image', (n, index, parent) => {
124271
+ const node = n;
124272
+ if (!parent || index === undefined)
124273
+ return undefined;
124274
+ const hProperties = node.data?.hProperties;
124275
+ // A `:joy:`-style shortcode round-trips as a gemoji rather than the image it parsed into.
124276
+ if (hProperties?.className === 'emoji' && node.title) {
124277
+ const emoji = {
124278
+ type: images_to_jsx_NodeTypes.emoji,
124279
+ name: node.title.replace(EMOJI_COLONS, '$1'),
124280
+ value: node.title,
124281
+ };
124282
+ parent.children[index] = emoji;
124283
+ return undefined;
124284
+ }
124285
+ if (hProperties) {
124286
+ const attributes = images_to_jsx_toAttributes({ ...node, ...hProperties, src: node.url }, IMAGE_ATTRS);
124287
+ if (hasExtra(attributes)) {
124288
+ parent.children[index] = toImageJsx(attributes);
124289
+ return undefined;
124290
+ }
124291
+ }
124292
+ // An attribute-less `[block:image]` parses straight to an `image` in a flow slot, so it needs
124293
+ // the same wrap. Editor images always arrive inside a paragraph and are left alone.
124294
+ if (images_to_jsx_INLINE_ONLY_PARENT_TYPES.has(parent.type))
124295
+ return undefined;
124296
+ placeImage(parent, index, node);
124297
+ // Step over the paragraph just created, or the visitor walks back into the same image.
124298
+ return [(/* inlined export .SKIP */"skip"), index + 1];
124299
+ });
124300
+ images_to_jsx_visit(tree, images_to_jsx_NodeTypes.imageBlock, (node, index, parent) => {
124301
+ if (!parent || index === undefined)
124302
+ return;
124303
+ // An image-block keeps its caption as children, so it has to be re-serialized back into the
124304
+ // `caption` attribute before the node is replaced.
124305
+ const captionChildren = node.children ?? [];
124306
+ const caption = captionChildren.length ? images_to_jsx_toMarkdown({ type: 'root', children: captionChildren }).trim() : '';
124307
+ const attributes = images_to_jsx_toAttributes({ ...node, ...node.data.hProperties, ...(caption && { caption }) }, IMAGE_ATTRS);
124308
+ if (hasExtra(attributes)) {
124309
+ parent.children[index] = toImageJsx(attributes);
124310
+ return;
124311
+ }
124312
+ placeImage(parent, index, {
124313
+ type: 'image',
124314
+ url: node.src,
124315
+ ...(node.title && { title: node.title }),
124316
+ ...(node.alt && { alt: node.alt }),
124317
+ });
124318
+ });
124319
+ return tree;
124320
+ };
124321
+ /* harmony default export */ const images_to_jsx = ((/* unused pure expression or super */ null && (imagesToJsx)));
124322
+
124218
124323
  // EXTERNAL MODULE: ./node_modules/@readme/variable/dist/index.js
124219
124324
  var variable_dist = __webpack_require__(4355);
124220
124325
  var variable_dist_default = /*#__PURE__*/__webpack_require__.n(variable_dist);
@@ -127742,7 +127847,9 @@ function loadComponents() {
127742
127847
  }
127743
127848
 
127744
127849
  ;// ./lib/mdxish.ts
127850
+ /* unused harmony import specifier */ var mdxish_mdxExpressionToMarkdown;
127745
127851
  /* unused harmony import specifier */ var mdxish_mdxJsxToMarkdown;
127852
+ /* unused harmony import specifier */ var mdxish_mdxjsEsmToMarkdown;
127746
127853
  /* unused harmony import specifier */ var mdxish_remarkGfm;
127747
127854
  /* unused harmony import specifier */ var mdxish_remarkStringify;
127748
127855
  /* unused harmony import specifier */ var mdxish_unified;
@@ -127750,7 +127857,13 @@ function loadComponents() {
127750
127857
  /* unused harmony import specifier */ var mdxish_DEFAULT_BULLET;
127751
127858
  /* unused harmony import specifier */ var mdxish_mdxishAnchorToJsx;
127752
127859
  /* unused harmony import specifier */ var mdxish_mdxishCalloutToJsx;
127860
+ /* unused harmony import specifier */ var mdxishImagesToJsx;
127753
127861
  /* unused harmony import specifier */ var mdxish_mdxishTablesToJsx;
127862
+ /* unused harmony import specifier */ var unwrapPins;
127863
+
127864
+
127865
+
127866
+
127754
127867
 
127755
127868
 
127756
127869
 
@@ -127881,35 +127994,43 @@ function mdxishAstProcessor(mdContent, opts = {}) {
127881
127994
  };
127882
127995
  }
127883
127996
  /**
127884
- * Registers the mdx-jsx serialization extension so remark-stringify
127885
- * can convert JSX nodes (e.g. `<Table>`) to markdown.
127997
+ * Registers serialization for the node types remark-stringify can't write on its own:
127998
+ * JSX elements (e.g. `<Table>`), MDX expressions, and ESM exports.
127886
127999
  */
127887
- function mdxJsxStringify() {
128000
+ function mdxStringifyExtensions() {
127888
128001
  const data = this.data();
127889
128002
  const extensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
127890
- extensions.push({ extensions: [mdxish_mdxJsxToMarkdown()] });
128003
+ extensions.push({ extensions: [mdxish_mdxJsxToMarkdown(), mdxish_mdxExpressionToMarkdown(), mdxish_mdxjsEsmToMarkdown()] });
127891
128004
  }
128005
+ const stringifyOptions = (/* unused pure expression or super */ null && ({
128006
+ bullet: mdxish_DEFAULT_BULLET,
128007
+ emphasis: '_',
128008
+ // Escape literal braces in text so they don't parse as (often
128009
+ // unterminated) MDX expressions on the next round trip.
128010
+ unsafe: [
128011
+ { character: '{', inConstruct: 'phrasing' },
128012
+ { character: '}', inConstruct: 'phrasing' },
128013
+ ],
128014
+ }));
127892
128015
  /**
127893
128016
  * Serializes an Mdast back into a markdown string.
127894
128017
  */
127895
128018
  function mdxishMdastToMd(mdast) {
127896
128019
  const processor = mdxish_unified()
127897
128020
  .use(mdxish_remarkGfm)
128021
+ // Readme nodes with no markdown spelling go out as JSX, the same tags mdxish re-parses.
127898
128022
  .use(mdxish_mdxishCalloutToJsx)
127899
128023
  .use(mdxish_mdxishTablesToJsx)
127900
128024
  .use(mdxish_mdxishAnchorToJsx)
128025
+ // The rest only a PARSER tree carries.
128026
+ // A `sidebar: true` block parses into an `rdme-pin` wrapper the dialect can't spell.
128027
+ .use(unwrapPins)
128028
+ // Figures, image blocks, and images that picked up readme attributes while parsing.
128029
+ .use(mdxishImagesToJsx)
128030
+ // Handlers for the readme nodes that stay themselves (variables, emoji, html-blocks, lists).
127901
128031
  .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
- });
128032
+ .use(mdxStringifyExtensions)
128033
+ .use(mdxish_remarkStringify, stringifyOptions);
127913
128034
  return processor.stringify(processor.runSync(mdast));
127914
128035
  }
127915
128036
  /**
@@ -129023,7 +129144,7 @@ module.exports = /*#__PURE__*/JSON.parse('{"*":["about","acceptCharset","accessK
129023
129144
  /******/ // startup
129024
129145
  /******/ // Load entry module and return exports
129025
129146
  /******/ // This entry module used 'module' so it can't be inlined
129026
- /******/ let __webpack_exports__ = __webpack_require__(9743);
129147
+ /******/ let __webpack_exports__ = __webpack_require__(5072);
129027
129148
  /******/ module.exports = __webpack_exports__;
129028
129149
  /******/
129029
129150
  /******/ })()