@readme/markdown 6.75.0-beta.34 → 6.75.0-beta.35

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.
@@ -23,20 +23,20 @@ const themes: Record<string, string> = {
23
23
  };
24
24
 
25
25
  const Callout = (props: Props) => {
26
- const { attributes, children, icon, heading } = props;
26
+ const { attributes, children, icon } = props;
27
27
 
28
28
  let theme = props.theme || themes[icon] || 'default';
29
+ const [heading, ...body] = Array.isArray(children) ? children : [children];
30
+ const empty = !heading.props.children;
29
31
 
30
32
  return (
31
33
  // @ts-ignore
32
34
  <blockquote {...attributes} className={`callout callout_${theme}`} theme={icon}>
33
- {heading && (
34
- <h3 className={`callout-heading${heading ? '' : ' empty'}`}>
35
- <span className="callout-icon">{icon}</span>
36
- {heading}
37
- </h3>
38
- )}
39
- {children}
35
+ <h3 className={`callout-heading${empty ? ' empty' : ''}`}>
36
+ <span className="callout-icon">{icon}</span>
37
+ {!empty && heading}
38
+ </h3>
39
+ {body}
40
40
  </blockquote>
41
41
  );
42
42
  };
package/dist/main.js CHANGED
@@ -60974,15 +60974,17 @@ const themes = {
60974
60974
  '\u26A0': 'warn',
60975
60975
  };
60976
60976
  const Callout = (props) => {
60977
- const { attributes, children, icon, heading } = props;
60977
+ const { attributes, children, icon } = props;
60978
60978
  let theme = props.theme || themes[icon] || 'default';
60979
+ const [heading, ...body] = Array.isArray(children) ? children : [children];
60980
+ const empty = !heading.props.children;
60979
60981
  return (
60980
60982
  // @ts-ignore
60981
60983
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("blockquote", Object.assign({}, attributes, { className: `callout callout_${theme}`, theme: icon }),
60982
- heading && (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("h3", { className: `callout-heading${heading ? '' : ' empty'}` },
60984
+ external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("h3", { className: `callout-heading${empty ? ' empty' : ''}` },
60983
60985
  external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_.createElement("span", { className: "callout-icon" }, icon),
60984
- heading)),
60985
- children));
60986
+ !empty && heading),
60987
+ body));
60986
60988
  };
60987
60989
  /* harmony default export */ const components_Callout = (Callout);
60988
60990
 
@@ -61431,26 +61433,20 @@ const callouts_regex = `^(${emoji_regex().source}|⚠)(\\s+|$)`;
61431
61433
  const calloutTransformer = () => {
61432
61434
  return (tree) => {
61433
61435
  visit(tree, 'blockquote', (node) => {
61434
- try {
61435
- if (!(node.children[0].type === 'paragraph' && node.children[0].children[0].type === 'text'))
61436
- return;
61437
- const startText = node.children[0].children[0].value;
61438
- const [match, icon] = startText.match(callouts_regex) || [];
61439
- if (icon && match) {
61440
- const heading = startText.slice(match.length);
61441
- node.children.shift();
61442
- node.type = NodeTypes.callout;
61443
- node.data = {
61444
- hName: 'Callout',
61445
- hProperties: {
61446
- heading,
61447
- icon,
61448
- },
61449
- };
61450
- }
61451
- }
61452
- catch (e) {
61453
- console.log(e);
61436
+ if (!(node.children[0].type === 'paragraph' && node.children[0].children[0].type === 'text'))
61437
+ return;
61438
+ const startText = node.children[0].children[0].value;
61439
+ const [match, icon] = startText.match(callouts_regex) || [];
61440
+ if (icon && match) {
61441
+ const heading = startText.slice(match.length);
61442
+ node.children[0].children[0].value = heading;
61443
+ node.type = NodeTypes.callout;
61444
+ node.data = {
61445
+ hName: 'Callout',
61446
+ hProperties: {
61447
+ icon,
61448
+ },
61449
+ };
61454
61450
  }
61455
61451
  });
61456
61452
  };
@@ -78515,10 +78511,12 @@ const gemojiTransformer = () => (tree) => {
78515
78511
 
78516
78512
  ;// CONCATENATED MODULE: ./processor/transform/readme-components.ts
78517
78513
 
78514
+
78515
+
78518
78516
  const readme_components_types = {
78519
- Callout: 'rdme-callout',
78517
+ Callout: NodeTypes['callout'],
78520
78518
  Code: 'code',
78521
- CodeTabs: 'code-tabs',
78519
+ CodeTabs: NodeTypes['codeTabs'],
78522
78520
  Image: 'image',
78523
78521
  Table: 'table',
78524
78522
  tr: 'tableRow',
@@ -78531,6 +78529,7 @@ const attributes = (jsx) => jsx.attributes.reduce((memo, attr) => {
78531
78529
  return memo;
78532
78530
  }, {});
78533
78531
  const coerceJsxToMd = ({ components = {} } = {}) => (node, index, parent) => {
78532
+ var _a;
78534
78533
  if (node.name in components)
78535
78534
  return;
78536
78535
  if (node.name === 'Code') {
@@ -78572,6 +78571,21 @@ const coerceJsxToMd = ({ components = {} } = {}) => (node, index, parent) => {
78572
78571
  };
78573
78572
  parent.children[index] = mdNode;
78574
78573
  }
78574
+ else if (node.name === 'Callout') {
78575
+ const { heading, icon } = attributes(node);
78576
+ const child = mdast(heading);
78577
+ // @ts-ignore
78578
+ const mdNode = {
78579
+ children: [(_a = child === null || child === void 0 ? void 0 : child.children) === null || _a === void 0 ? void 0 : _a[0], ...node.children].filter(Boolean),
78580
+ type: NodeTypes.callout,
78581
+ data: {
78582
+ hName: node.name,
78583
+ hProperties: { icon },
78584
+ },
78585
+ position: node.position,
78586
+ };
78587
+ parent.children[index] = mdNode;
78588
+ }
78575
78589
  else if (node.name in readme_components_types) {
78576
78590
  const hProperties = attributes(node);
78577
78591
  // @ts-ignore
@@ -78609,9 +78623,29 @@ const readmeComponents = (opts) => () => tree => {
78609
78623
 
78610
78624
  /* harmony default export */ const transform = ([callouts, code_tabs, transform_embeds, gemoji_]);
78611
78625
 
78612
- ;// CONCATENATED MODULE: ./processor/compile/gemoji.ts
78613
- const gemoji_gemoji = (node) => `:${node.name}:`;
78614
- /* harmony default export */ const compile_gemoji = (gemoji_gemoji);
78626
+ ;// CONCATENATED MODULE: ./processor/compile/callout.ts
78627
+
78628
+ const callout = (node, _, state, info) => {
78629
+ const tracker = state.createTracker(info);
78630
+ const exit = state.enter(NodeTypes.callout);
78631
+ state.join.push(() => 0);
78632
+ const value = state.containerFlow(node, tracker.current());
78633
+ state.join.pop();
78634
+ exit();
78635
+ let lines = value.split('\n');
78636
+ if (lines.length > 1) {
78637
+ const [first, ...rest] = lines;
78638
+ lines = [first, '', ...rest];
78639
+ }
78640
+ let content = lines
78641
+ .map((line, index) => (index > 0 ? `>${line.length > 0 ? ' ' : ''}${line}` : line))
78642
+ .join('\n');
78643
+ if (content.match(/^[^\n]/))
78644
+ content = ' ' + content;
78645
+ const block = `> ${node.data.hProperties.icon}${content}`;
78646
+ return block;
78647
+ };
78648
+ /* harmony default export */ const compile_callout = (callout);
78615
78649
 
78616
78650
  ;// CONCATENATED MODULE: ./processor/compile/code-tabs.ts
78617
78651
 
@@ -78637,6 +78671,10 @@ const embed_embed = (node) => {
78637
78671
  };
78638
78672
  /* harmony default export */ const compile_embed = (embed_embed);
78639
78673
 
78674
+ ;// CONCATENATED MODULE: ./processor/compile/gemoji.ts
78675
+ const gemoji_gemoji = (node) => `:${node.name}:`;
78676
+ /* harmony default export */ const compile_gemoji = (gemoji_gemoji);
78677
+
78640
78678
  ;// CONCATENATED MODULE: ./processor/compile/html-block.ts
78641
78679
  const htmlBlock = (node) => {
78642
78680
  const html = node.data.hProperties.html;
@@ -78662,10 +78700,12 @@ const compile_image_image = (node) => {
78662
78700
 
78663
78701
 
78664
78702
 
78703
+
78665
78704
  function compilers() {
78666
78705
  const data = this.data();
78667
78706
  const toMarkdownExtensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
78668
78707
  const handlers = {
78708
+ [NodeTypes.callout]: compile_callout,
78669
78709
  [NodeTypes.emoji]: compile_gemoji,
78670
78710
  [NodeTypes.codeTabs]: compile_code_tabs,
78671
78711
  [NodeTypes.embed]: compile_embed,
@@ -78674,7 +78714,6 @@ function compilers() {
78674
78714
  };
78675
78715
  toMarkdownExtensions.push({ extensions: [{ handlers }] });
78676
78716
  }
78677
- ;
78678
78717
  /* harmony default export */ const processor_compile = (compilers);
78679
78718
 
78680
78719
  ;// CONCATENATED MODULE: ./errors/mdx-syntax-error.ts
@@ -78749,7 +78788,7 @@ const reactProcessor = (opts = {}) => {
78749
78788
  };
78750
78789
  const index_compile = (text, opts = {}) => {
78751
78790
  try {
78752
- return String(compileSync(text, Object.assign({ outputFormat: 'function-body', providerImportSource: '#', remarkPlugins }, opts))).replace(/await import\(_resolveDynamicMdxSpecifier\('react'\)\)/, 'arguments[0].imports.React');
78791
+ return String(compileSync(text, Object.assign({ outputFormat: 'function-body', providerImportSource: '#', remarkPlugins }, opts))).replace(/await import\(_resolveDynamicMdxSpecifier\(('react'|"react")\)\)/, 'arguments[0].imports.React');
78753
78792
  }
78754
78793
  catch (error) {
78755
78794
  console.error(error);
package/dist/main.node.js CHANGED
@@ -58257,15 +58257,17 @@ const themes = {
58257
58257
  '\u26A0': 'warn',
58258
58258
  };
58259
58259
  const Callout = (props) => {
58260
- const { attributes, children, icon, heading } = props;
58260
+ const { attributes, children, icon } = props;
58261
58261
  let theme = props.theme || themes[icon] || 'default';
58262
+ const [heading, ...body] = Array.isArray(children) ? children : [children];
58263
+ const empty = !heading.props.children;
58262
58264
  return (
58263
58265
  // @ts-ignore
58264
58266
  react.createElement("blockquote", Object.assign({}, attributes, { className: `callout callout_${theme}`, theme: icon }),
58265
- heading && (react.createElement("h3", { className: `callout-heading${heading ? '' : ' empty'}` },
58267
+ react.createElement("h3", { className: `callout-heading${empty ? ' empty' : ''}` },
58266
58268
  react.createElement("span", { className: "callout-icon" }, icon),
58267
- heading)),
58268
- children));
58269
+ !empty && heading),
58270
+ body));
58269
58271
  };
58270
58272
  /* harmony default export */ const components_Callout = (Callout);
58271
58273
 
@@ -63591,26 +63593,20 @@ const callouts_regex = `^(${emoji_regex().source}|⚠)(\\s+|$)`;
63591
63593
  const calloutTransformer = () => {
63592
63594
  return (tree) => {
63593
63595
  visit(tree, 'blockquote', (node) => {
63594
- try {
63595
- if (!(node.children[0].type === 'paragraph' && node.children[0].children[0].type === 'text'))
63596
- return;
63597
- const startText = node.children[0].children[0].value;
63598
- const [match, icon] = startText.match(callouts_regex) || [];
63599
- if (icon && match) {
63600
- const heading = startText.slice(match.length);
63601
- node.children.shift();
63602
- node.type = NodeTypes.callout;
63603
- node.data = {
63604
- hName: 'Callout',
63605
- hProperties: {
63606
- heading,
63607
- icon,
63608
- },
63609
- };
63610
- }
63611
- }
63612
- catch (e) {
63613
- console.log(e);
63596
+ if (!(node.children[0].type === 'paragraph' && node.children[0].children[0].type === 'text'))
63597
+ return;
63598
+ const startText = node.children[0].children[0].value;
63599
+ const [match, icon] = startText.match(callouts_regex) || [];
63600
+ if (icon && match) {
63601
+ const heading = startText.slice(match.length);
63602
+ node.children[0].children[0].value = heading;
63603
+ node.type = NodeTypes.callout;
63604
+ node.data = {
63605
+ hName: 'Callout',
63606
+ hProperties: {
63607
+ icon,
63608
+ },
63609
+ };
63614
63610
  }
63615
63611
  });
63616
63612
  };
@@ -80675,10 +80671,12 @@ const gemojiTransformer = () => (tree) => {
80675
80671
 
80676
80672
  ;// CONCATENATED MODULE: ./processor/transform/readme-components.ts
80677
80673
 
80674
+
80675
+
80678
80676
  const readme_components_types = {
80679
- Callout: 'rdme-callout',
80677
+ Callout: NodeTypes['callout'],
80680
80678
  Code: 'code',
80681
- CodeTabs: 'code-tabs',
80679
+ CodeTabs: NodeTypes['codeTabs'],
80682
80680
  Image: 'image',
80683
80681
  Table: 'table',
80684
80682
  tr: 'tableRow',
@@ -80691,6 +80689,7 @@ const attributes = (jsx) => jsx.attributes.reduce((memo, attr) => {
80691
80689
  return memo;
80692
80690
  }, {});
80693
80691
  const coerceJsxToMd = ({ components = {} } = {}) => (node, index, parent) => {
80692
+ var _a;
80694
80693
  if (node.name in components)
80695
80694
  return;
80696
80695
  if (node.name === 'Code') {
@@ -80732,6 +80731,21 @@ const coerceJsxToMd = ({ components = {} } = {}) => (node, index, parent) => {
80732
80731
  };
80733
80732
  parent.children[index] = mdNode;
80734
80733
  }
80734
+ else if (node.name === 'Callout') {
80735
+ const { heading, icon } = attributes(node);
80736
+ const child = mdast(heading);
80737
+ // @ts-ignore
80738
+ const mdNode = {
80739
+ children: [(_a = child === null || child === void 0 ? void 0 : child.children) === null || _a === void 0 ? void 0 : _a[0], ...node.children].filter(Boolean),
80740
+ type: NodeTypes.callout,
80741
+ data: {
80742
+ hName: node.name,
80743
+ hProperties: { icon },
80744
+ },
80745
+ position: node.position,
80746
+ };
80747
+ parent.children[index] = mdNode;
80748
+ }
80735
80749
  else if (node.name in readme_components_types) {
80736
80750
  const hProperties = attributes(node);
80737
80751
  // @ts-ignore
@@ -80769,9 +80783,29 @@ const readmeComponents = (opts) => () => tree => {
80769
80783
 
80770
80784
  /* harmony default export */ const transform = ([callouts, code_tabs, transform_embeds, gemoji_]);
80771
80785
 
80772
- ;// CONCATENATED MODULE: ./processor/compile/gemoji.ts
80773
- const gemoji_gemoji = (node) => `:${node.name}:`;
80774
- /* harmony default export */ const compile_gemoji = (gemoji_gemoji);
80786
+ ;// CONCATENATED MODULE: ./processor/compile/callout.ts
80787
+
80788
+ const callout = (node, _, state, info) => {
80789
+ const tracker = state.createTracker(info);
80790
+ const exit = state.enter(NodeTypes.callout);
80791
+ state.join.push(() => 0);
80792
+ const value = state.containerFlow(node, tracker.current());
80793
+ state.join.pop();
80794
+ exit();
80795
+ let lines = value.split('\n');
80796
+ if (lines.length > 1) {
80797
+ const [first, ...rest] = lines;
80798
+ lines = [first, '', ...rest];
80799
+ }
80800
+ let content = lines
80801
+ .map((line, index) => (index > 0 ? `>${line.length > 0 ? ' ' : ''}${line}` : line))
80802
+ .join('\n');
80803
+ if (content.match(/^[^\n]/))
80804
+ content = ' ' + content;
80805
+ const block = `> ${node.data.hProperties.icon}${content}`;
80806
+ return block;
80807
+ };
80808
+ /* harmony default export */ const compile_callout = (callout);
80775
80809
 
80776
80810
  ;// CONCATENATED MODULE: ./processor/compile/code-tabs.ts
80777
80811
 
@@ -80797,6 +80831,10 @@ const embed_embed = (node) => {
80797
80831
  };
80798
80832
  /* harmony default export */ const compile_embed = (embed_embed);
80799
80833
 
80834
+ ;// CONCATENATED MODULE: ./processor/compile/gemoji.ts
80835
+ const gemoji_gemoji = (node) => `:${node.name}:`;
80836
+ /* harmony default export */ const compile_gemoji = (gemoji_gemoji);
80837
+
80800
80838
  ;// CONCATENATED MODULE: ./processor/compile/html-block.ts
80801
80839
  const htmlBlock = (node) => {
80802
80840
  const html = node.data.hProperties.html;
@@ -80822,10 +80860,12 @@ const compile_image_image = (node) => {
80822
80860
 
80823
80861
 
80824
80862
 
80863
+
80825
80864
  function compilers() {
80826
80865
  const data = this.data();
80827
80866
  const toMarkdownExtensions = data.toMarkdownExtensions || (data.toMarkdownExtensions = []);
80828
80867
  const handlers = {
80868
+ [NodeTypes.callout]: compile_callout,
80829
80869
  [NodeTypes.emoji]: compile_gemoji,
80830
80870
  [NodeTypes.codeTabs]: compile_code_tabs,
80831
80871
  [NodeTypes.embed]: compile_embed,
@@ -80834,7 +80874,6 @@ function compilers() {
80834
80874
  };
80835
80875
  toMarkdownExtensions.push({ extensions: [{ handlers }] });
80836
80876
  }
80837
- ;
80838
80877
  /* harmony default export */ const processor_compile = (compilers);
80839
80878
 
80840
80879
  ;// CONCATENATED MODULE: ./errors/mdx-syntax-error.ts
@@ -80909,7 +80948,7 @@ const reactProcessor = (opts = {}) => {
80909
80948
  };
80910
80949
  const index_compile = (text, opts = {}) => {
80911
80950
  try {
80912
- return String(compileSync(text, Object.assign({ outputFormat: 'function-body', providerImportSource: '#', remarkPlugins }, opts))).replace(/await import\(_resolveDynamicMdxSpecifier\('react'\)\)/, 'arguments[0].imports.React');
80951
+ return String(compileSync(text, Object.assign({ outputFormat: 'function-body', providerImportSource: '#', remarkPlugins }, opts))).replace(/await import\(_resolveDynamicMdxSpecifier\(('react'|"react")\)\)/, 'arguments[0].imports.React');
80913
80952
  }
80914
80953
  catch (error) {
80915
80954
  console.error(error);
@@ -0,0 +1,3 @@
1
+ import { Callout } from '../../types';
2
+ declare const callout: (node: Callout, _: any, state: any, info: any) => string;
3
+ export default callout;
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": "6.75.0-beta.34",
5
+ "version": "6.75.0-beta.35",
6
6
  "main": "dist/main.node.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "browser": "dist/main.js",