@readme/markdown 7.2.0 → 7.2.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.
package/dist/enums.d.ts CHANGED
@@ -3,6 +3,8 @@ export declare enum NodeTypes {
3
3
  codeTabs = "code-tabs",
4
4
  embedBlock = "embed-block",
5
5
  emoji = "gemoji",
6
+ figcaption = "figcaption",
7
+ figure = "figure",
6
8
  glossary = "readme-glossary-item",
7
9
  htmlBlock = "html-block",
8
10
  i = "i",
package/dist/main.js CHANGED
@@ -47737,6 +47737,8 @@ var NodeTypes;
47737
47737
  NodeTypes["codeTabs"] = "code-tabs";
47738
47738
  NodeTypes["embedBlock"] = "embed-block";
47739
47739
  NodeTypes["emoji"] = "gemoji";
47740
+ NodeTypes["figcaption"] = "figcaption";
47741
+ NodeTypes["figure"] = "figure";
47740
47742
  NodeTypes["glossary"] = "readme-glossary-item";
47741
47743
  NodeTypes["htmlBlock"] = "html-block";
47742
47744
  NodeTypes["i"] = "i";
@@ -47983,6 +47985,19 @@ const reformatHTML = (html, indent = 2) => {
47983
47985
  // const indented = cleaned.split('\n').map((line: string) => `${tab}${line}`).join('\n');
47984
47986
  return cleaned;
47985
47987
  };
47988
+ const toAttributes = (object, keys = []) => {
47989
+ let attributes = [];
47990
+ Object.entries(object).forEach(([name, value]) => {
47991
+ if (keys.length > 0 && !keys.includes(name))
47992
+ return;
47993
+ attributes.push({
47994
+ type: 'mdxJsxAttribute',
47995
+ name,
47996
+ value: value,
47997
+ });
47998
+ });
47999
+ return attributes;
48000
+ };
47986
48001
 
47987
48002
  ;// CONCATENATED MODULE: ./processor/transform/images.ts
47988
48003
 
@@ -47992,10 +48007,8 @@ const reformatHTML = (html, indent = 2) => {
47992
48007
  const imageTransformer = () => (tree) => {
47993
48008
  visit(tree, 'paragraph', (node, i, parent) => {
47994
48009
  var _a;
47995
- // check if inline
47996
- if (parent.type !== 'root' ||
47997
- ((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 1 ||
47998
- node.children[0].type !== 'image')
48010
+ // check if inline
48011
+ if (parent.type !== 'root' || ((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 1 || node.children[0].type !== 'image')
47999
48012
  return;
48000
48013
  const [{ alt, url, title }] = node.children;
48001
48014
  const newNode = {
@@ -65219,6 +65232,8 @@ const readmeComponents = (opts) => () => tree => {
65219
65232
  ;// CONCATENATED MODULE: ./processor/transform/readme-to-mdx.ts
65220
65233
 
65221
65234
 
65235
+
65236
+ const imageAttrs = ['align', 'alt', 'caption', 'border', 'src', 'title', 'width', 'lazy', 'className'];
65222
65237
  const readmeToMdx = () => tree => {
65223
65238
  // Unwrap pinned nodes, replace rdme-pin with its child node
65224
65239
  visit(tree, 'rdme-pin', (node, i, parent) => {
@@ -65226,22 +65241,56 @@ const readmeToMdx = () => tree => {
65226
65241
  parent.children.splice(i, 1, newNode);
65227
65242
  });
65228
65243
  visit(tree, NodeTypes.tutorialTile, (tile, index, parent) => {
65229
- const attributes = ['backgroundColor', 'emoji', 'id', 'link', 'slug', 'title'].map(name => {
65230
- const value = tile[name];
65231
- delete tile[name];
65232
- return {
65233
- type: 'mdxJsxAttribute',
65234
- name,
65235
- value,
65236
- };
65237
- });
65238
65244
  parent.children.splice(index, 1, {
65239
65245
  type: 'mdxJsxFlowElement',
65240
65246
  name: 'TutorialTile',
65241
- attributes,
65247
+ attributes: toAttributes(tile, ['backgroundColor', 'emoji', 'id', 'link', 'slug', 'title']),
65242
65248
  children: [],
65243
65249
  });
65244
65250
  });
65251
+ visit(tree, 'figure', (figure, index, parent) => {
65252
+ const [image, caption] = figure.children;
65253
+ parent.children.splice(index, 1, {
65254
+ type: 'mdxJsxFlowElement',
65255
+ name: 'Image',
65256
+ attributes: toAttributes(image, imageAttrs),
65257
+ children: caption.children,
65258
+ });
65259
+ });
65260
+ const hasExtra = (attributes) => !!attributes.find(attr => !['alt', 'src', 'title'].includes(attr.name));
65261
+ visit(tree, 'image', (image, index, parent) => {
65262
+ if (!('data' in image))
65263
+ return;
65264
+ const attributes = toAttributes(image.data.hProperties, imageAttrs);
65265
+ if (hasExtra(attributes)) {
65266
+ parent.children.splice(index, 1, {
65267
+ type: 'mdxJsxFlowElement',
65268
+ name: 'Image',
65269
+ attributes,
65270
+ children: [],
65271
+ });
65272
+ }
65273
+ });
65274
+ visit(tree, NodeTypes.imageBlock, (image, index, parent) => {
65275
+ const attributes = toAttributes(image.data.hProperties, imageAttrs);
65276
+ if (hasExtra(attributes)) {
65277
+ parent.children.splice(index, 1, {
65278
+ type: 'mdxJsxFlowElement',
65279
+ name: 'Image',
65280
+ attributes,
65281
+ children: [],
65282
+ });
65283
+ }
65284
+ else {
65285
+ parent.children.splice(index, 1, {
65286
+ type: 'image',
65287
+ children: [],
65288
+ url: image.url,
65289
+ title: image.title,
65290
+ alt: image.alt,
65291
+ });
65292
+ }
65293
+ });
65245
65294
  return tree;
65246
65295
  };
65247
65296
  /* harmony default export */ const readme_to_mdx = (readmeToMdx);
@@ -82657,24 +82706,6 @@ ${reformatHTML(html)}
82657
82706
  };
82658
82707
  /* harmony default export */ const html_block = (htmlBlock);
82659
82708
 
82660
- ;// CONCATENATED MODULE: ./processor/compile/image.ts
82661
-
82662
- const compile_image_image = (node) => {
82663
- var _a;
82664
- const attributes = formatHProps(node);
82665
- const hProps = getHProps(node);
82666
- const hPropKeys = getHPropKeys(node);
82667
- const ImageBlock = `<Image ${attributes} />`;
82668
- const MDImage = `![${(_a = node.alt) !== null && _a !== void 0 ? _a : ''}](${hProps.src ? hProps.src : node.url}${node.title ? ` "${node.title}")` : ')'}`;
82669
- if (Boolean(attributes)) {
82670
- if (hPropKeys.includes('src') && (hPropKeys.includes('width') || hPropKeys.includes('border') || hPropKeys.includes('align'))) {
82671
- return ImageBlock;
82672
- }
82673
- }
82674
- return MDImage;
82675
- };
82676
- /* harmony default export */ const compile_image = (compile_image_image);
82677
-
82678
82709
  ;// CONCATENATED MODULE: ./node_modules/hast-util-from-parse5/node_modules/hastscript/lib/create-h.js
82679
82710
  /**
82680
82711
  * @typedef {import('hast').Element} Element
@@ -93871,7 +93902,12 @@ const compatibility = (node) => {
93871
93902
  /* harmony default export */ const compile_compatibility = (compatibility);
93872
93903
 
93873
93904
  ;// CONCATENATED MODULE: ./processor/compile/variable.ts
93874
- const variable = (node) => `{user.${node.data.hProperties.name}}`;
93905
+ const variable = (node) => {
93906
+ // @note: coming from RDMD, it's set as `variable`. But when mdx is parsed,
93907
+ // it's set as `name`
93908
+ const name = node.data.hProperties.variable || node.data.hProperties.name;
93909
+ return `{user.${name}}`;
93910
+ };
93875
93911
  /* harmony default export */ const compile_variable = (variable);
93876
93912
 
93877
93913
  ;// CONCATENATED MODULE: ./processor/compile/index.ts
@@ -93883,7 +93919,6 @@ const variable = (node) => `{user.${node.data.hProperties.name}}`;
93883
93919
 
93884
93920
 
93885
93921
 
93886
-
93887
93922
  function compilers() {
93888
93923
  const data = this.data();
93889
93924
  const toMarkdownExtensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
@@ -93894,7 +93929,6 @@ function compilers() {
93894
93929
  [NodeTypes.emoji]: compile_gemoji,
93895
93930
  [NodeTypes.glossary]: compile_compatibility,
93896
93931
  [NodeTypes.htmlBlock]: html_block,
93897
- [NodeTypes.imageBlock]: compile_image,
93898
93932
  [NodeTypes.reusableContent]: compile_compatibility,
93899
93933
  [NodeTypes.variable]: compile_variable,
93900
93934
  embed: compile_compatibility,
@@ -93924,8 +93958,8 @@ const mdx_mdx = (tree, { hast = false } = {}) => {
93924
93958
  .use(div)
93925
93959
  .use(readme_to_mdx)
93926
93960
  .use(tables_to_jsx)
93927
- .use(remarkStringify)
93928
- .use(processor_compile);
93961
+ .use(processor_compile)
93962
+ .use(remarkStringify);
93929
93963
  return processor.stringify(processor.runSync(tree));
93930
93964
  };
93931
93965
  /* harmony default export */ const lib_mdx = (mdx_mdx);
package/dist/main.node.js CHANGED
@@ -48724,6 +48724,8 @@ var NodeTypes;
48724
48724
  NodeTypes["codeTabs"] = "code-tabs";
48725
48725
  NodeTypes["embedBlock"] = "embed-block";
48726
48726
  NodeTypes["emoji"] = "gemoji";
48727
+ NodeTypes["figcaption"] = "figcaption";
48728
+ NodeTypes["figure"] = "figure";
48727
48729
  NodeTypes["glossary"] = "readme-glossary-item";
48728
48730
  NodeTypes["htmlBlock"] = "html-block";
48729
48731
  NodeTypes["i"] = "i";
@@ -48970,6 +48972,19 @@ const reformatHTML = (html, indent = 2) => {
48970
48972
  // const indented = cleaned.split('\n').map((line: string) => `${tab}${line}`).join('\n');
48971
48973
  return cleaned;
48972
48974
  };
48975
+ const toAttributes = (object, keys = []) => {
48976
+ let attributes = [];
48977
+ Object.entries(object).forEach(([name, value]) => {
48978
+ if (keys.length > 0 && !keys.includes(name))
48979
+ return;
48980
+ attributes.push({
48981
+ type: 'mdxJsxAttribute',
48982
+ name,
48983
+ value: value,
48984
+ });
48985
+ });
48986
+ return attributes;
48987
+ };
48973
48988
 
48974
48989
  ;// CONCATENATED MODULE: ./processor/transform/images.ts
48975
48990
 
@@ -48979,10 +48994,8 @@ const reformatHTML = (html, indent = 2) => {
48979
48994
  const imageTransformer = () => (tree) => {
48980
48995
  visit(tree, 'paragraph', (node, i, parent) => {
48981
48996
  var _a;
48982
- // check if inline
48983
- if (parent.type !== 'root' ||
48984
- ((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 1 ||
48985
- node.children[0].type !== 'image')
48997
+ // check if inline
48998
+ if (parent.type !== 'root' || ((_a = node.children) === null || _a === void 0 ? void 0 : _a.length) > 1 || node.children[0].type !== 'image')
48986
48999
  return;
48987
49000
  const [{ alt, url, title }] = node.children;
48988
49001
  const newNode = {
@@ -66206,6 +66219,8 @@ const readmeComponents = (opts) => () => tree => {
66206
66219
  ;// CONCATENATED MODULE: ./processor/transform/readme-to-mdx.ts
66207
66220
 
66208
66221
 
66222
+
66223
+ const imageAttrs = ['align', 'alt', 'caption', 'border', 'src', 'title', 'width', 'lazy', 'className'];
66209
66224
  const readmeToMdx = () => tree => {
66210
66225
  // Unwrap pinned nodes, replace rdme-pin with its child node
66211
66226
  visit(tree, 'rdme-pin', (node, i, parent) => {
@@ -66213,22 +66228,56 @@ const readmeToMdx = () => tree => {
66213
66228
  parent.children.splice(i, 1, newNode);
66214
66229
  });
66215
66230
  visit(tree, NodeTypes.tutorialTile, (tile, index, parent) => {
66216
- const attributes = ['backgroundColor', 'emoji', 'id', 'link', 'slug', 'title'].map(name => {
66217
- const value = tile[name];
66218
- delete tile[name];
66219
- return {
66220
- type: 'mdxJsxAttribute',
66221
- name,
66222
- value,
66223
- };
66224
- });
66225
66231
  parent.children.splice(index, 1, {
66226
66232
  type: 'mdxJsxFlowElement',
66227
66233
  name: 'TutorialTile',
66228
- attributes,
66234
+ attributes: toAttributes(tile, ['backgroundColor', 'emoji', 'id', 'link', 'slug', 'title']),
66229
66235
  children: [],
66230
66236
  });
66231
66237
  });
66238
+ visit(tree, 'figure', (figure, index, parent) => {
66239
+ const [image, caption] = figure.children;
66240
+ parent.children.splice(index, 1, {
66241
+ type: 'mdxJsxFlowElement',
66242
+ name: 'Image',
66243
+ attributes: toAttributes(image, imageAttrs),
66244
+ children: caption.children,
66245
+ });
66246
+ });
66247
+ const hasExtra = (attributes) => !!attributes.find(attr => !['alt', 'src', 'title'].includes(attr.name));
66248
+ visit(tree, 'image', (image, index, parent) => {
66249
+ if (!('data' in image))
66250
+ return;
66251
+ const attributes = toAttributes(image.data.hProperties, imageAttrs);
66252
+ if (hasExtra(attributes)) {
66253
+ parent.children.splice(index, 1, {
66254
+ type: 'mdxJsxFlowElement',
66255
+ name: 'Image',
66256
+ attributes,
66257
+ children: [],
66258
+ });
66259
+ }
66260
+ });
66261
+ visit(tree, NodeTypes.imageBlock, (image, index, parent) => {
66262
+ const attributes = toAttributes(image.data.hProperties, imageAttrs);
66263
+ if (hasExtra(attributes)) {
66264
+ parent.children.splice(index, 1, {
66265
+ type: 'mdxJsxFlowElement',
66266
+ name: 'Image',
66267
+ attributes,
66268
+ children: [],
66269
+ });
66270
+ }
66271
+ else {
66272
+ parent.children.splice(index, 1, {
66273
+ type: 'image',
66274
+ children: [],
66275
+ url: image.url,
66276
+ title: image.title,
66277
+ alt: image.alt,
66278
+ });
66279
+ }
66280
+ });
66232
66281
  return tree;
66233
66282
  };
66234
66283
  /* harmony default export */ const readme_to_mdx = (readmeToMdx);
@@ -83644,24 +83693,6 @@ ${reformatHTML(html)}
83644
83693
  };
83645
83694
  /* harmony default export */ const html_block = (htmlBlock);
83646
83695
 
83647
- ;// CONCATENATED MODULE: ./processor/compile/image.ts
83648
-
83649
- const compile_image_image = (node) => {
83650
- var _a;
83651
- const attributes = formatHProps(node);
83652
- const hProps = getHProps(node);
83653
- const hPropKeys = getHPropKeys(node);
83654
- const ImageBlock = `<Image ${attributes} />`;
83655
- const MDImage = `![${(_a = node.alt) !== null && _a !== void 0 ? _a : ''}](${hProps.src ? hProps.src : node.url}${node.title ? ` "${node.title}")` : ')'}`;
83656
- if (Boolean(attributes)) {
83657
- if (hPropKeys.includes('src') && (hPropKeys.includes('width') || hPropKeys.includes('border') || hPropKeys.includes('align'))) {
83658
- return ImageBlock;
83659
- }
83660
- }
83661
- return MDImage;
83662
- };
83663
- /* harmony default export */ const compile_image = (compile_image_image);
83664
-
83665
83696
  ;// CONCATENATED MODULE: ./node_modules/hast-util-from-parse5/node_modules/hastscript/lib/create-h.js
83666
83697
  /**
83667
83698
  * @typedef {import('hast').Element} Element
@@ -94858,7 +94889,12 @@ const compatibility = (node) => {
94858
94889
  /* harmony default export */ const compile_compatibility = (compatibility);
94859
94890
 
94860
94891
  ;// CONCATENATED MODULE: ./processor/compile/variable.ts
94861
- const variable = (node) => `{user.${node.data.hProperties.name}}`;
94892
+ const variable = (node) => {
94893
+ // @note: coming from RDMD, it's set as `variable`. But when mdx is parsed,
94894
+ // it's set as `name`
94895
+ const name = node.data.hProperties.variable || node.data.hProperties.name;
94896
+ return `{user.${name}}`;
94897
+ };
94862
94898
  /* harmony default export */ const compile_variable = (variable);
94863
94899
 
94864
94900
  ;// CONCATENATED MODULE: ./processor/compile/index.ts
@@ -94870,7 +94906,6 @@ const variable = (node) => `{user.${node.data.hProperties.name}}`;
94870
94906
 
94871
94907
 
94872
94908
 
94873
-
94874
94909
  function compilers() {
94875
94910
  const data = this.data();
94876
94911
  const toMarkdownExtensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
@@ -94881,7 +94916,6 @@ function compilers() {
94881
94916
  [NodeTypes.emoji]: compile_gemoji,
94882
94917
  [NodeTypes.glossary]: compile_compatibility,
94883
94918
  [NodeTypes.htmlBlock]: html_block,
94884
- [NodeTypes.imageBlock]: compile_image,
94885
94919
  [NodeTypes.reusableContent]: compile_compatibility,
94886
94920
  [NodeTypes.variable]: compile_variable,
94887
94921
  embed: compile_compatibility,
@@ -94911,8 +94945,8 @@ const mdx_mdx = (tree, { hast = false } = {}) => {
94911
94945
  .use(transform_div)
94912
94946
  .use(readme_to_mdx)
94913
94947
  .use(tables_to_jsx)
94914
- .use(remarkStringify)
94915
- .use(processor_compile);
94948
+ .use(processor_compile)
94949
+ .use(remarkStringify);
94916
94950
  return processor.stringify(processor.runSync(tree));
94917
94951
  };
94918
94952
  /* harmony default export */ const lib_mdx = (mdx_mdx);
@@ -1,5 +1,6 @@
1
1
  import { Node } from 'mdast';
2
2
  import { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx';
3
+ import { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
3
4
  /**
4
5
  * Formats the hProperties of a node as a string, so they can be compiled back into JSX/MDX.
5
6
  * This currently sets all the values to a string since we process/compile the MDX on the fly
@@ -75,3 +76,4 @@ export declare const formatHTML: (html: string) => string;
75
76
  * @returns {string} re-formatted HTML
76
77
  */
77
78
  export declare const reformatHTML: (html: string, indent?: number) => string;
79
+ export declare const toAttributes: (object: Record<string, any>, keys?: string[]) => MdxJsxAttribute[];
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@readme/markdown",
3
3
  "description": "ReadMe's React-based Markdown parser",
4
4
  "author": "Rafe Goldberg <rafe@readme.io>",
5
- "version": "7.2.0",
5
+ "version": "7.2.1",
6
6
  "main": "dist/main.node.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "browser": "dist/main.js",
@@ -1,3 +0,0 @@
1
- import type { ImageBlock } from 'types';
2
- declare const image: (node: ImageBlock) => string;
3
- export default image;