@readme/markdown 6.75.0-beta.58 → 6.75.0-beta.60

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,18 @@
1
+ import React from 'react';
2
+
3
+ import './style.scss';
4
+
5
+ const Card = ({ children }) => <div className="Card">{children}</div>;
6
+
7
+ const CardsGrid = ({ columns = 2, children }) => {
8
+ columns = columns >= 2 ? columns : 2;
9
+ return (
10
+ <div className="CardsGrid" style={{ gridTemplateColumns: `repeat(${columns}, 1fr)` }}>
11
+ {React.Children.map(children, e => (
12
+ <Card>{e}</Card>
13
+ ))}
14
+ </div>
15
+ );
16
+ };
17
+
18
+ export default CardsGrid;
@@ -0,0 +1,12 @@
1
+ .CardsGrid {
2
+ display: grid;
3
+ gap: 20px;
4
+
5
+ .Card {
6
+ padding: 10px;
7
+ backdrop-filter: blur(20px);
8
+ border: 1px solid rgba(black, 0.1);
9
+ border-radius: 5px;
10
+ box-shadow: 0 1px 2px #{rgba(black, 0.05)}, 0 2px 5px #{rgba(black, 0.02)};
11
+ }
12
+ }
@@ -13,8 +13,10 @@ const extractScripts = (html: string = ''): [string, () => void] => {
13
13
  return [cleaned, () => scripts.map(js => window.eval(js))];
14
14
  };
15
15
 
16
- const HTMLBlock = ({ children = '', runScripts = false, safeMode = false }) => {
16
+ const HTMLBlock = ({ children = '', runScripts, safeMode = false }) => {
17
17
  let html = children;
18
+ runScripts = typeof runScripts !== 'boolean' ? (runScripts === 'true' ? true : false) : runScripts;
19
+
18
20
  if (typeof html !== 'string') html = renderToStaticMarkup(html);
19
21
  const [cleanedHtml, exec] = extractScripts(html);
20
22
 
@@ -1,5 +1,6 @@
1
1
  export { default as Anchor } from './Anchor';
2
2
  export { default as Callout } from './Callout';
3
+ export { default as Cards } from './CardsGrid';
3
4
  export { default as Code } from './Code';
4
5
  export { default as CodeTabs } from './CodeTabs';
5
6
  export { default as Embed } from './Embed';
@@ -0,0 +1,7 @@
1
+ import React from 'react';
2
+ import './style.scss';
3
+ declare const CardsGrid: ({ columns, children }: {
4
+ columns?: number;
5
+ children: any;
6
+ }) => React.JSX.Element;
7
+ export default CardsGrid;
@@ -1,7 +1,7 @@
1
1
  import React from 'react';
2
2
  declare const HTMLBlock: ({ children, runScripts, safeMode }: {
3
3
  children?: string;
4
- runScripts?: boolean;
4
+ runScripts: any;
5
5
  safeMode?: boolean;
6
6
  }) => React.JSX.Element;
7
7
  export default HTMLBlock;
@@ -1,5 +1,6 @@
1
1
  export { default as Anchor } from './Anchor';
2
2
  export { default as Callout } from './Callout';
3
+ export { default as Cards } from './CardsGrid';
3
4
  export { default as Code } from './Code';
4
5
  export { default as CodeTabs } from './CodeTabs';
5
6
  export { default as Embed } from './Embed';
package/dist/main.css CHANGED
@@ -1,3 +1,4 @@
1
+ .CardsGrid{display:grid;gap:20px}.CardsGrid .Card{padding:10px;backdrop-filter:blur(20px);border:1px solid rgba(0,0,0,.1);border-radius:5px;box-shadow:0 1px 2px rgba(0, 0, 0, 0.05),0 2px 5px rgba(0, 0, 0, 0.02)}
1
2
  /* BASICS */
2
3
 
3
4
  .CodeMirror {
package/dist/main.js CHANGED
@@ -13984,6 +13984,7 @@ __webpack_require__.r(components_namespaceObject);
13984
13984
  __webpack_require__.d(components_namespaceObject, {
13985
13985
  Anchor: () => (components_Anchor),
13986
13986
  Callout: () => (components_Callout),
13987
+ Cards: () => (components_CardsGrid),
13987
13988
  Code: () => (components_Code),
13988
13989
  CodeTabs: () => (components_CodeTabs),
13989
13990
  Embed: () => (components_Embed),
@@ -14211,6 +14212,16 @@ const Callout = (props) => {
14211
14212
  };
14212
14213
  /* harmony default export */ const components_Callout = (Callout);
14213
14214
 
14215
+ ;// CONCATENATED MODULE: ./components/CardsGrid/index.tsx
14216
+
14217
+
14218
+ const Card = ({ children }) => external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("div", { className: "Card" }, children);
14219
+ const CardsGrid = ({ columns = 2, children }) => {
14220
+ columns = columns >= 2 ? columns : 2;
14221
+ return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("div", { className: "CardsGrid", style: { gridTemplateColumns: `repeat(${columns}, 1fr)` } }, external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().Children.map(children, e => (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(Card, null, e)))));
14222
+ };
14223
+ /* harmony default export */ const components_CardsGrid = (CardsGrid);
14224
+
14214
14225
  // EXTERNAL MODULE: ./node_modules/copy-to-clipboard/index.js
14215
14226
  var copy_to_clipboard = __webpack_require__(7965);
14216
14227
  var copy_to_clipboard_default = /*#__PURE__*/__webpack_require__.n(copy_to_clipboard);
@@ -14387,8 +14398,9 @@ const extractScripts = (html = '') => {
14387
14398
  const cleaned = html.replace(MATCH_SCRIPT_TAGS, '');
14388
14399
  return [cleaned, () => scripts.map(js => window.eval(js))];
14389
14400
  };
14390
- const HTMLBlock = ({ children = '', runScripts = false, safeMode = false }) => {
14401
+ const HTMLBlock = ({ children = '', runScripts, safeMode = false }) => {
14391
14402
  let html = children;
14403
+ runScripts = typeof runScripts !== 'boolean' ? (runScripts === 'true' ? true : false) : runScripts;
14392
14404
  if (typeof html !== 'string')
14393
14405
  html = (0,server_browser/* renderToStaticMarkup */.qV)(html);
14394
14406
  const [cleanedHtml, exec] = extractScripts(html);
@@ -14509,6 +14521,7 @@ function TableOfContents({ children }) {
14509
14521
 
14510
14522
 
14511
14523
 
14524
+
14512
14525
  // EXTERNAL MODULE: ./node_modules/core-js/modules/es.symbol.to-primitive.js
14513
14526
  var es_symbol_to_primitive = __webpack_require__(6611);
14514
14527
  // EXTERNAL MODULE: ./node_modules/core-js/modules/es.array.filter.js
@@ -65564,29 +65577,121 @@ const injectComponents = (opts) => () => tree => {
65564
65577
  /* harmony default export */ const inject_components = (injectComponents);
65565
65578
 
65566
65579
  ;// CONCATENATED MODULE: ./processor/utils.ts
65580
+ /**
65581
+ * Formats the hProperties of a node as a string, so they can be compiled back into JSX/MDX.
65582
+ * This currently sets all the values to a string since we process/compile the MDX on the fly
65583
+ * through the editor, and it'll throw errors over malformed JSX. TODO: fix this.
65584
+ *
65585
+ * @template T
65586
+ * @param {Node} node
65587
+ * @returns {string} formatted hProperties as JSX attributes
65588
+ */
65567
65589
  const formatHProps = (node) => {
65568
65590
  const hProps = getHProps(node);
65569
65591
  const hPropKeys = getHPropKeys(node);
65570
65592
  return hPropKeys.map(key => `${key}="${hProps[key]}"`).join(' ');
65571
65593
  };
65594
+ /**
65595
+ * Returns the hProperties of a node.
65596
+ *
65597
+ * @template T
65598
+ * @param {Node} node
65599
+ * @returns {T} hProperties
65600
+ */
65572
65601
  const getHProps = (node) => {
65573
65602
  var _a;
65574
65603
  const hProps = ((_a = node.data) === null || _a === void 0 ? void 0 : _a.hProperties) || {};
65575
65604
  return hProps;
65576
65605
  };
65606
+ /**
65607
+ * Returns array of hProperty keys.
65608
+ *
65609
+ * @template T
65610
+ * @param {Node} node
65611
+ * @returns {Array} array of hProperty keys
65612
+ */
65577
65613
  const getHPropKeys = (node) => {
65578
65614
  const hProps = getHProps(node);
65579
65615
  return Object.keys(hProps) || [];
65580
65616
  };
65617
+ /**
65618
+ * Gets the attributes of an MDX element and returns them as an object of hProperties.
65619
+ *
65620
+ * @template T
65621
+ * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
65622
+ * @returns {T} object of hProperties
65623
+ */
65581
65624
  const getAttrs = (jsx) => jsx.attributes.reduce((memo, attr) => {
65582
65625
  if ('name' in attr) {
65583
65626
  memo[attr.name] = attr.value;
65584
65627
  }
65585
65628
  return memo;
65586
65629
  }, {});
65630
+ /**
65631
+ * Gets the children of an MDX element and returns them as an array of Text nodes.
65632
+ * Currently only being used by the HTML Block component, which only expects a single text node.
65633
+ *
65634
+ * @template T
65635
+ * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
65636
+ * @returns {Array} array of child text nodes
65637
+ */
65638
+ const getChildren = (jsx) => jsx.children.reduce((memo, child, i) => {
65639
+ memo[i] = {
65640
+ type: 'text',
65641
+ value: child.value,
65642
+ position: child.position,
65643
+ };
65644
+ return memo;
65645
+ }, []);
65646
+ /**
65647
+ * Tests if a node is an MDX element.
65648
+ * TODO: Make this more extensible to all types of nodes. isElement(node, 'type' or ['type1', 'type2']), say
65649
+ *
65650
+ * @param {Node} node
65651
+ * @returns {(node is MdxJsxFlowElement | MdxJsxTextElement)}
65652
+ */
65587
65653
  const isMDXElement = (node) => {
65588
65654
  return ['mdxJsxFlowElement', 'mdxJsxTextElement'].includes(node.type);
65589
65655
  };
65656
+ /**
65657
+ * Takes an HTML string and formats it for display in the editor. Removes leading/trailing newlines
65658
+ * and unindents the HTML.
65659
+ *
65660
+ * @param {string} html
65661
+ * @returns {string} formatted HTML
65662
+ */
65663
+ const formatHTML = (html) => {
65664
+ // Remove leading/trailing backticks if present, since they're used to keep the HTML
65665
+ // from being parsed prematurely
65666
+ if (html.startsWith('`') && html.endsWith('`')) {
65667
+ html = html.slice(1, -1);
65668
+ }
65669
+ // Removes the leading/trailing newlines
65670
+ const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
65671
+ // // Get the number of spaces in the first line to determine the tab size
65672
+ // const tab = cleaned.match(/^\s*/)[0].length;
65673
+ // // Remove the first indentation level from each line
65674
+ // const tabRegex = new RegExp(`^\\s{${tab}}`, 'gm');
65675
+ // const unindented = cleaned.replace(tabRegex, '');
65676
+ return cleaned;
65677
+ };
65678
+ /**
65679
+ * Reformat HTML for the markdown/mdx by adding an indentation to each line. This assures that the
65680
+ * HTML is indentend properly within the HTMLBlock component when rendered in the markdown/mdx.
65681
+ *
65682
+ * @param {string} html
65683
+ * @param {number} [indent=2]
65684
+ * @returns {string} re-formatted HTML
65685
+ */
65686
+ const reformatHTML = (html, indent = 2) => {
65687
+ // Remove leading/trailing newlines
65688
+ const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
65689
+ // // Create a tab/indent with the specified number of spaces
65690
+ // const tab = ' '.repeat(indent);
65691
+ // // Indent each line of the HTML (converts to an array, indents each line, then joins back)
65692
+ // const indented = cleaned.split('\n').map((line: string) => `${tab}${line}`).join('\n');
65693
+ return cleaned;
65694
+ };
65590
65695
 
65591
65696
  ;// CONCATENATED MODULE: ./processor/transform/readme-components.ts
65592
65697
 
@@ -65599,6 +65704,7 @@ const readme_components_types = {
65599
65704
  EmbedBlock: NodeTypes['embed-block'],
65600
65705
  Glossary: NodeTypes['glossary'],
65601
65706
  ImageBlock: NodeTypes['image-block'],
65707
+ HTMLBlock: NodeTypes.htmlBlock,
65602
65708
  Table: 'table',
65603
65709
  Variable: NodeTypes['variable'],
65604
65710
  td: 'tableCell',
@@ -65640,6 +65746,22 @@ const coerceJsxToMd = ({ components = {} } = {}) => (node, index, parent) => {
65640
65746
  };
65641
65747
  parent.children[index] = mdNode;
65642
65748
  }
65749
+ else if (node.name === 'HTMLBlock') {
65750
+ const { position } = node;
65751
+ const children = getChildren(node);
65752
+ const { runScripts } = getAttrs(node);
65753
+ const html = formatHTML(children.map(({ value }) => value).join(''));
65754
+ const mdNode = {
65755
+ position,
65756
+ children: [{ type: 'text', value: html }],
65757
+ type: NodeTypes.htmlBlock,
65758
+ data: {
65759
+ hName: 'html-block',
65760
+ hProperties: Object.assign(Object.assign({}, (runScripts && { runScripts })), { html }),
65761
+ },
65762
+ };
65763
+ parent.children[index] = mdNode;
65764
+ }
65643
65765
  else if (node.name === 'Table') {
65644
65766
  const { children, position } = node;
65645
65767
  const { align = [...new Array(node.children.length)].map(() => null) } = getAttrs(node);
@@ -93448,11 +93570,12 @@ const gemoji_gemoji = (node) => `:${node.name}:`;
93448
93570
  /* harmony default export */ const compile_gemoji = (gemoji_gemoji);
93449
93571
 
93450
93572
  ;// CONCATENATED MODULE: ./processor/compile/html-block.ts
93573
+
93451
93574
  const htmlBlock = (node) => {
93452
- var _a;
93453
- const html = node.data.hProperties.html;
93454
- const attributes = Object.keys((_a = node.data) === null || _a === void 0 ? void 0 : _a.hProperties).map(key => { var _a; return `${key}="${(_a = node.data) === null || _a === void 0 ? void 0 : _a.hProperties[key]}"`; }).join(' ');
93455
- return `<HTMLBlock${attributes && ' ' + attributes}>{\`${html}\`}</HTMLBlock>`;
93575
+ const { runScripts, html } = getHProps(node);
93576
+ return `<HTMLBlock${runScripts != null ? ` runScripts="${runScripts}"` : ''}>{\`
93577
+ ${reformatHTML(html)}
93578
+ \`}</HTMLBlock>`;
93456
93579
  };
93457
93580
  /* harmony default export */ const html_block = (htmlBlock);
93458
93581
 
@@ -94459,7 +94582,7 @@ const makeUseMDXComponents = (more = {}) => {
94459
94582
  map[`h${index + 1}`] = components_Heading((index + 1));
94460
94583
  return map;
94461
94584
  }, {});
94462
- const components = Object.assign(Object.assign(Object.assign(Object.assign({}, components_namespaceObject), { Variable: (variable_default()), code: components_Code, embed: components_Embed, img: components_Image, table: components_Table, 'code-tabs': components_CodeTabs, 'html-block': components_HTMLBlock, 'embed-block': components_Embed, 'image-block': components_Image, 'table-of-contents': components_TableOfContents }), headings), more);
94585
+ const components = Object.assign(Object.assign(Object.assign(Object.assign({}, components_namespaceObject), { Variable: (variable_default()), code: components_Code, embed: components_Embed, img: components_Image, table: components_Table, 'code-tabs': components_CodeTabs, 'embed-block': components_Embed, 'html-block': components_HTMLBlock, 'image-block': components_Image, 'table-of-contents': components_TableOfContents }), headings), more);
94463
94586
  return () => components;
94464
94587
  };
94465
94588
  const run_run = async (string, _opts = {}) => {
package/dist/main.node.js CHANGED
@@ -8997,6 +8997,7 @@ __webpack_require__.r(components_namespaceObject);
8997
8997
  __webpack_require__.d(components_namespaceObject, {
8998
8998
  Anchor: () => (components_Anchor),
8999
8999
  Callout: () => (components_Callout),
9000
+ Cards: () => (components_CardsGrid),
9000
9001
  Code: () => (components_Code),
9001
9002
  CodeTabs: () => (components_CodeTabs),
9002
9003
  Embed: () => (components_Embed),
@@ -9157,6 +9158,16 @@ const Callout = (props) => {
9157
9158
  };
9158
9159
  /* harmony default export */ const components_Callout = (Callout);
9159
9160
 
9161
+ ;// CONCATENATED MODULE: ./components/CardsGrid/index.tsx
9162
+
9163
+
9164
+ const Card = ({ children }) => external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("div", { className: "Card" }, children);
9165
+ const CardsGrid = ({ columns = 2, children }) => {
9166
+ columns = columns >= 2 ? columns : 2;
9167
+ return (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement("div", { className: "CardsGrid", style: { gridTemplateColumns: `repeat(${columns}, 1fr)` } }, external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().Children.map(children, e => (external_amd_react_commonjs_react_commonjs2_react_root_React_umd_react_default().createElement(Card, null, e)))));
9168
+ };
9169
+ /* harmony default export */ const components_CardsGrid = (CardsGrid);
9170
+
9160
9171
  // EXTERNAL MODULE: ./node_modules/copy-to-clipboard/index.js
9161
9172
  var copy_to_clipboard = __webpack_require__(965);
9162
9173
  var copy_to_clipboard_default = /*#__PURE__*/__webpack_require__.n(copy_to_clipboard);
@@ -14277,8 +14288,9 @@ const extractScripts = (html = '') => {
14277
14288
  const cleaned = html.replace(MATCH_SCRIPT_TAGS, '');
14278
14289
  return [cleaned, () => scripts.map(js => window.eval(js))];
14279
14290
  };
14280
- const HTMLBlock = ({ children = '', runScripts = false, safeMode = false }) => {
14291
+ const HTMLBlock = ({ children = '', runScripts, safeMode = false }) => {
14281
14292
  let html = children;
14293
+ runScripts = typeof runScripts !== 'boolean' ? (runScripts === 'true' ? true : false) : runScripts;
14282
14294
  if (typeof html !== 'string')
14283
14295
  html = (0,server_namespaceObject.renderToStaticMarkup)(html);
14284
14296
  const [cleanedHtml, exec] = extractScripts(html);
@@ -14399,6 +14411,7 @@ function TableOfContents({ children }) {
14399
14411
 
14400
14412
 
14401
14413
 
14414
+
14402
14415
  ;// CONCATENATED MODULE: ./options.js
14403
14416
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14404
14417
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
@@ -67017,29 +67030,121 @@ const injectComponents = (opts) => () => tree => {
67017
67030
  /* harmony default export */ const inject_components = (injectComponents);
67018
67031
 
67019
67032
  ;// CONCATENATED MODULE: ./processor/utils.ts
67033
+ /**
67034
+ * Formats the hProperties of a node as a string, so they can be compiled back into JSX/MDX.
67035
+ * This currently sets all the values to a string since we process/compile the MDX on the fly
67036
+ * through the editor, and it'll throw errors over malformed JSX. TODO: fix this.
67037
+ *
67038
+ * @template T
67039
+ * @param {Node} node
67040
+ * @returns {string} formatted hProperties as JSX attributes
67041
+ */
67020
67042
  const formatHProps = (node) => {
67021
67043
  const hProps = getHProps(node);
67022
67044
  const hPropKeys = getHPropKeys(node);
67023
67045
  return hPropKeys.map(key => `${key}="${hProps[key]}"`).join(' ');
67024
67046
  };
67047
+ /**
67048
+ * Returns the hProperties of a node.
67049
+ *
67050
+ * @template T
67051
+ * @param {Node} node
67052
+ * @returns {T} hProperties
67053
+ */
67025
67054
  const getHProps = (node) => {
67026
67055
  var _a;
67027
67056
  const hProps = ((_a = node.data) === null || _a === void 0 ? void 0 : _a.hProperties) || {};
67028
67057
  return hProps;
67029
67058
  };
67059
+ /**
67060
+ * Returns array of hProperty keys.
67061
+ *
67062
+ * @template T
67063
+ * @param {Node} node
67064
+ * @returns {Array} array of hProperty keys
67065
+ */
67030
67066
  const getHPropKeys = (node) => {
67031
67067
  const hProps = getHProps(node);
67032
67068
  return Object.keys(hProps) || [];
67033
67069
  };
67070
+ /**
67071
+ * Gets the attributes of an MDX element and returns them as an object of hProperties.
67072
+ *
67073
+ * @template T
67074
+ * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
67075
+ * @returns {T} object of hProperties
67076
+ */
67034
67077
  const getAttrs = (jsx) => jsx.attributes.reduce((memo, attr) => {
67035
67078
  if ('name' in attr) {
67036
67079
  memo[attr.name] = attr.value;
67037
67080
  }
67038
67081
  return memo;
67039
67082
  }, {});
67083
+ /**
67084
+ * Gets the children of an MDX element and returns them as an array of Text nodes.
67085
+ * Currently only being used by the HTML Block component, which only expects a single text node.
67086
+ *
67087
+ * @template T
67088
+ * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
67089
+ * @returns {Array} array of child text nodes
67090
+ */
67091
+ const utils_getChildren = (jsx) => jsx.children.reduce((memo, child, i) => {
67092
+ memo[i] = {
67093
+ type: 'text',
67094
+ value: child.value,
67095
+ position: child.position,
67096
+ };
67097
+ return memo;
67098
+ }, []);
67099
+ /**
67100
+ * Tests if a node is an MDX element.
67101
+ * TODO: Make this more extensible to all types of nodes. isElement(node, 'type' or ['type1', 'type2']), say
67102
+ *
67103
+ * @param {Node} node
67104
+ * @returns {(node is MdxJsxFlowElement | MdxJsxTextElement)}
67105
+ */
67040
67106
  const isMDXElement = (node) => {
67041
67107
  return ['mdxJsxFlowElement', 'mdxJsxTextElement'].includes(node.type);
67042
67108
  };
67109
+ /**
67110
+ * Takes an HTML string and formats it for display in the editor. Removes leading/trailing newlines
67111
+ * and unindents the HTML.
67112
+ *
67113
+ * @param {string} html
67114
+ * @returns {string} formatted HTML
67115
+ */
67116
+ const formatHTML = (html) => {
67117
+ // Remove leading/trailing backticks if present, since they're used to keep the HTML
67118
+ // from being parsed prematurely
67119
+ if (html.startsWith('`') && html.endsWith('`')) {
67120
+ html = html.slice(1, -1);
67121
+ }
67122
+ // Removes the leading/trailing newlines
67123
+ const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
67124
+ // // Get the number of spaces in the first line to determine the tab size
67125
+ // const tab = cleaned.match(/^\s*/)[0].length;
67126
+ // // Remove the first indentation level from each line
67127
+ // const tabRegex = new RegExp(`^\\s{${tab}}`, 'gm');
67128
+ // const unindented = cleaned.replace(tabRegex, '');
67129
+ return cleaned;
67130
+ };
67131
+ /**
67132
+ * Reformat HTML for the markdown/mdx by adding an indentation to each line. This assures that the
67133
+ * HTML is indentend properly within the HTMLBlock component when rendered in the markdown/mdx.
67134
+ *
67135
+ * @param {string} html
67136
+ * @param {number} [indent=2]
67137
+ * @returns {string} re-formatted HTML
67138
+ */
67139
+ const reformatHTML = (html, indent = 2) => {
67140
+ // Remove leading/trailing newlines
67141
+ const cleaned = html.replace(/^\s*\n|\n\s*$/g, '');
67142
+ // // Create a tab/indent with the specified number of spaces
67143
+ // const tab = ' '.repeat(indent);
67144
+ // // Indent each line of the HTML (converts to an array, indents each line, then joins back)
67145
+ // const indented = cleaned.split('\n').map((line: string) => `${tab}${line}`).join('\n');
67146
+ return cleaned;
67147
+ };
67043
67148
 
67044
67149
  ;// CONCATENATED MODULE: ./processor/transform/readme-components.ts
67045
67150
 
@@ -67052,6 +67157,7 @@ const readme_components_types = {
67052
67157
  EmbedBlock: NodeTypes['embed-block'],
67053
67158
  Glossary: NodeTypes['glossary'],
67054
67159
  ImageBlock: NodeTypes['image-block'],
67160
+ HTMLBlock: NodeTypes.htmlBlock,
67055
67161
  Table: 'table',
67056
67162
  Variable: NodeTypes['variable'],
67057
67163
  td: 'tableCell',
@@ -67093,6 +67199,22 @@ const coerceJsxToMd = ({ components = {} } = {}) => (node, index, parent) => {
67093
67199
  };
67094
67200
  parent.children[index] = mdNode;
67095
67201
  }
67202
+ else if (node.name === 'HTMLBlock') {
67203
+ const { position } = node;
67204
+ const children = utils_getChildren(node);
67205
+ const { runScripts } = getAttrs(node);
67206
+ const html = formatHTML(children.map(({ value }) => value).join(''));
67207
+ const mdNode = {
67208
+ position,
67209
+ children: [{ type: 'text', value: html }],
67210
+ type: NodeTypes.htmlBlock,
67211
+ data: {
67212
+ hName: 'html-block',
67213
+ hProperties: Object.assign(Object.assign({}, (runScripts && { runScripts })), { html }),
67214
+ },
67215
+ };
67216
+ parent.children[index] = mdNode;
67217
+ }
67096
67218
  else if (node.name === 'Table') {
67097
67219
  const { children, position } = node;
67098
67220
  const { align = [...new Array(node.children.length)].map(() => null) } = getAttrs(node);
@@ -94901,11 +95023,12 @@ const gemoji_gemoji = (node) => `:${node.name}:`;
94901
95023
  /* harmony default export */ const compile_gemoji = (gemoji_gemoji);
94902
95024
 
94903
95025
  ;// CONCATENATED MODULE: ./processor/compile/html-block.ts
95026
+
94904
95027
  const htmlBlock = (node) => {
94905
- var _a;
94906
- const html = node.data.hProperties.html;
94907
- const attributes = Object.keys((_a = node.data) === null || _a === void 0 ? void 0 : _a.hProperties).map(key => { var _a; return `${key}="${(_a = node.data) === null || _a === void 0 ? void 0 : _a.hProperties[key]}"`; }).join(' ');
94908
- return `<HTMLBlock${attributes && ' ' + attributes}>{\`${html}\`}</HTMLBlock>`;
95028
+ const { runScripts, html } = getHProps(node);
95029
+ return `<HTMLBlock${runScripts != null ? ` runScripts="${runScripts}"` : ''}>{\`
95030
+ ${reformatHTML(html)}
95031
+ \`}</HTMLBlock>`;
94909
95032
  };
94910
95033
  /* harmony default export */ const html_block = (htmlBlock);
94911
95034
 
@@ -95912,7 +96035,7 @@ const makeUseMDXComponents = (more = {}) => {
95912
96035
  map[`h${index + 1}`] = components_Heading((index + 1));
95913
96036
  return map;
95914
96037
  }, {});
95915
- const components = Object.assign(Object.assign(Object.assign(Object.assign({}, components_namespaceObject), { Variable: (dist_default()), code: components_Code, embed: components_Embed, img: components_Image, table: components_Table, 'code-tabs': components_CodeTabs, 'html-block': components_HTMLBlock, 'embed-block': components_Embed, 'image-block': components_Image, 'table-of-contents': components_TableOfContents }), headings), more);
96038
+ const components = Object.assign(Object.assign(Object.assign(Object.assign({}, components_namespaceObject), { Variable: (dist_default()), code: components_Code, embed: components_Embed, img: components_Image, table: components_Table, 'code-tabs': components_CodeTabs, 'embed-block': components_Embed, 'html-block': components_HTMLBlock, 'image-block': components_Image, 'table-of-contents': components_TableOfContents }), headings), more);
95916
96039
  return () => components;
95917
96040
  };
95918
96041
  const run_run = async (string, _opts = {}) => {
@@ -1,7 +1,70 @@
1
1
  import { Node } from 'mdast';
2
2
  import { MdxJsxFlowElement, MdxJsxTextElement } from 'mdast-util-mdx';
3
- export declare const formatHProps: <T>(node: Node) => T;
3
+ /**
4
+ * Formats the hProperties of a node as a string, so they can be compiled back into JSX/MDX.
5
+ * This currently sets all the values to a string since we process/compile the MDX on the fly
6
+ * through the editor, and it'll throw errors over malformed JSX. TODO: fix this.
7
+ *
8
+ * @template T
9
+ * @param {Node} node
10
+ * @returns {string} formatted hProperties as JSX attributes
11
+ */
12
+ export declare const formatHProps: <T>(node: Node) => string;
13
+ /**
14
+ * Returns the hProperties of a node.
15
+ *
16
+ * @template T
17
+ * @param {Node} node
18
+ * @returns {T} hProperties
19
+ */
4
20
  export declare const getHProps: <T>(node: Node) => T;
5
- export declare const getHPropKeys: <T>(node: Node) => string[] | T;
6
- export declare const getAttrs: <T>(jsx: MdxJsxFlowElement | MdxJsxTextElement) => T;
21
+ /**
22
+ * Returns array of hProperty keys.
23
+ *
24
+ * @template T
25
+ * @param {Node} node
26
+ * @returns {Array} array of hProperty keys
27
+ */
28
+ export declare const getHPropKeys: <T>(node: Node) => any;
29
+ /**
30
+ * Gets the attributes of an MDX element and returns them as an object of hProperties.
31
+ *
32
+ * @template T
33
+ * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
34
+ * @returns {T} object of hProperties
35
+ */
36
+ export declare const getAttrs: <T>(jsx: MdxJsxFlowElement | MdxJsxTextElement) => any;
37
+ /**
38
+ * Gets the children of an MDX element and returns them as an array of Text nodes.
39
+ * Currently only being used by the HTML Block component, which only expects a single text node.
40
+ *
41
+ * @template T
42
+ * @param {(MdxJsxFlowElement | MdxJsxTextElement)} jsx
43
+ * @returns {Array} array of child text nodes
44
+ */
45
+ export declare const getChildren: <T>(jsx: MdxJsxFlowElement | MdxJsxTextElement) => any;
46
+ /**
47
+ * Tests if a node is an MDX element.
48
+ * TODO: Make this more extensible to all types of nodes. isElement(node, 'type' or ['type1', 'type2']), say
49
+ *
50
+ * @param {Node} node
51
+ * @returns {(node is MdxJsxFlowElement | MdxJsxTextElement)}
52
+ */
7
53
  export declare const isMDXElement: (node: Node) => node is MdxJsxFlowElement | MdxJsxTextElement;
54
+ /**
55
+ * Takes an HTML string and formats it for display in the editor. Removes leading/trailing newlines
56
+ * and unindents the HTML.
57
+ *
58
+ * @param {string} html
59
+ * @returns {string} formatted HTML
60
+ */
61
+ export declare const formatHTML: (html: string) => string;
62
+ /**
63
+ * Reformat HTML for the markdown/mdx by adding an indentation to each line. This assures that the
64
+ * HTML is indentend properly within the HTMLBlock component when rendered in the markdown/mdx.
65
+ *
66
+ * @param {string} html
67
+ * @param {number} [indent=2]
68
+ * @returns {string} re-formatted HTML
69
+ */
70
+ export declare const reformatHTML: (html: string, indent?: number) => string;
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.58",
5
+ "version": "6.75.0-beta.60",
6
6
  "main": "dist/main.node.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "browser": "dist/main.js",