@readme/markdown 8.1.0 → 8.2.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.
package/README.md CHANGED
@@ -1,9 +1,27 @@
1
- # <img align="right" width="26%" src="https://owlbertsio-resized.s3.amazonaws.com/Reading.psd.full.png"> `@readme/markdown`
2
-
3
- <img align=right src=https://github.com/readmeio/markdown/workflows/CI/badge.svg alt="RDMD CI Status"> ReadMe's MDX rendering engine and custom component collection.
4
- <br/>  *(Use ReadMe? [Learn more about our upcoming move to MDX](https://docs.readme.com/rdmd/page/mdx-engine)!)*
5
-
6
- ## Getting Started
1
+ <p align="center">
2
+ <a href="https://npm.im/@readme/markdown">
3
+ <img src="https://owlbertsio-resized.s3.amazonaws.com/Reading.psd.full.png" width="150" alt="rmdx" />
4
+ </a>
5
+ </p>
6
+
7
+ <p align="center">
8
+ ReadMe's MDX rendering engine and custom component collection.<br />
9
+ <sub>
10
+ Use ReadMe? <a href="https://docs.readme.com/rdmd/page/mdx-engine">Learn more about our upcoming move to MDX!</a>
11
+ </sub>
12
+ </p>
13
+
14
+ <p align="center">
15
+ <a href="https://npm.im/@readme/markdown"><img src="https://img.shields.io/npm/v/@readme/markdown?style=for-the-badge" alt="NPM Version" /></a>
16
+ <a href="https://npm.im/@readme/markdown"><img src="https://img.shields.io/npm/l/@readme/markdown?style=for-the-badge" alt="MIT License" /></a>
17
+ <a href="https://github.com/readmeio/markdown"><img src="https://img.shields.io/github/actions/workflow/status/readmeio/markdown/ci.yml?branch=main&style=for-the-badge" alt="Build status" /></a>
18
+ </p>
19
+
20
+ <p align="center">
21
+ <a href="https://readme.com"><img src="https://raw.githubusercontent.com/readmeio/.github/main/oss-badge.svg" /></a>
22
+ </p>
23
+
24
+ ## Usage
7
25
 
8
26
  To use the engine, install it from NPM:
9
27
 
@@ -16,11 +34,7 @@ Then [`compile`](#compile) and [`run`](#run) your MDX:
16
34
  ```jsx
17
35
  import RMDX from '@readme/markdown';
18
36
 
19
- export default ({ body }) => (
20
- <div className="markdown-body">
21
- {RMDX.run(RMDX.compile(body))}
22
- </div>
23
- );
37
+ export default ({ body }) => <div className="markdown-body">{RMDX.run(RMDX.compile(body))}</div>;
24
38
  ```
25
39
 
26
40
  ## API
@@ -42,13 +56,15 @@ A string of compiled Javascript module code.
42
56
 
43
57
  > [!CAUTION]
44
58
  > This is essentially a wrapper around [`mdx.run`](https://mdxjs.com/packages/mdx/#runcode-options) and **it will `eval` the compiled MDX**. Make sure you only call `run` on safe syntax from a trusted author!
45
- >
46
- > #### Parameters
47
- > - **`string`** (`string`)—a compiled mdx document
48
- > - **`opts`** (`RunOpts`, optional)—configuration
49
- >
50
- > #### Returns
51
- > An [`RMDXModule`](#rmdxmodule) of renderable components.
59
+
60
+ #### Parameters
61
+
62
+ - **`string`** (`string`)—a compiled mdx document
63
+ - **`opts`** (`RunOpts`, optional)—configuration
64
+
65
+ #### Returns
66
+
67
+ An [`RMDXModule`](#rmdxmodule) of renderable components.
52
68
 
53
69
  ### `mdx`
54
70
 
@@ -57,7 +73,7 @@ Compiles an AST to a string of MDX syntax.
57
73
  #### Parameters
58
74
 
59
75
  - **`tree`** (`object`)—an abstract syntax tree
60
- - **`opts`** ([`Options`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options "`remark-stringify` Options type"))—`remark-stringify` configuration.
76
+ - **`opts`** ([`Options`](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options '`remark-stringify` Options type'))—`remark-stringify` configuration.
61
77
 
62
78
  #### Returns
63
79
 
@@ -67,8 +83,8 @@ An MDX string.
67
83
 
68
84
  - **`mdast`**: parse MDX syntax to MDAST.
69
85
  - **`hast`**: parse MDX syntax to HAST.
70
- - **`plain`**: parse MDX to a plaintext string with all Markdown syntax removed. (This *does not* `eval` the doc.)
71
- - **`tags`**: get a list of tag names from the doc. (This *does not* `eval` the doc.)
86
+ - **`plain`**: parse MDX to a plaintext string with all Markdown syntax removed. (This _does not_ `eval` the doc.)
87
+ - **`tags`**: get a list of tag names from the doc. (This _does not_ `eval` the doc.)
72
88
  - **`utils`**: additional defaults, helper methods, components, and so on.
73
89
 
74
90
  ## Types
@@ -103,7 +119,7 @@ Extends [`RunOptions`](https://mdxjs.com/packages/mdx/#runoptions)
103
119
  - **`toc`** (`HastHeading[]`)—a list of headings in the document
104
120
  - **`Toc`** (`() => MDCContent`)—a table of contents component
105
121
 
106
- ## Local Development and Testing
122
+ ## Local development and testing
107
123
 
108
124
  To make changes to the RDMD engine locally, run the local development server. Clone the repo, `cd` in to it, `npm install`, and `npm run start`!
109
125
 
package/dist/main.js CHANGED
@@ -52911,6 +52911,72 @@ const hasNamedExport = (tree, name) => {
52911
52911
  });
52912
52912
  return hasExport;
52913
52913
  };
52914
+ /* Example mdast structures to find first export name in a mdxjsEsm node:
52915
+ There are three types of export declarations that we need to consider:
52916
+ 1. VARIABLE DECLARATION
52917
+ "type": "mdxjsEsm",
52918
+ "value": "export const Foo = () => <div>Hello world</div>\nexport const Bar = () => <div>hello darkness my old friend</div>",
52919
+ "data": {
52920
+ "estree": {
52921
+ "type": "Program",
52922
+ "body": [
52923
+ {
52924
+ "type": "ExportNamedDeclaration",
52925
+ "declaration": {
52926
+ "type": "VariableDeclaration",
52927
+ "declarations": [
52928
+ {
52929
+ "type": "VariableDeclarator",
52930
+ "id": {
52931
+ "type": "Identifier",
52932
+ "name": "Foo" // --------> This is the export name
52933
+ },
52934
+ ...
52935
+
52936
+ 2/3. FUNCTION DECLARATION & CLASS DECLARATION
52937
+ "estree": {
52938
+ "type": "Program",
52939
+ "body": [
52940
+ {
52941
+ "type": "ExportNamedDeclaration",
52942
+ "declaration": {
52943
+ "type": "ClassDeclaration" | "FunctionDeclaration",
52944
+ "id": {
52945
+ "type": "Identifier",
52946
+ "name": "Foo" // --------> This is the export name
52947
+ },
52948
+ */
52949
+ const getExports = (tree) => {
52950
+ const set = new Set();
52951
+ visit(tree, isMDXEsm, (node) => {
52952
+ // Once inside an mdxjsEsm node, we need to check for one or more declared exports within data.estree.body
52953
+ // This is because single newlines \n are not considered as a new block, so there may be more than one export statement in a single mdxjsEsm node
52954
+ const body = node.data?.estree.body;
52955
+ if (!body)
52956
+ return;
52957
+ for (const child of body) {
52958
+ if (child.type === 'ExportNamedDeclaration') {
52959
+ // There are three types of ExportNamedDeclaration that we need to consider: VariableDeclaration, FunctionDeclaration, ClassDeclaration
52960
+ const declaration = child.declaration;
52961
+ // FunctionDeclaration and ClassDeclaration have the same structure
52962
+ if (declaration.type !== 'VariableDeclaration') {
52963
+ // Note: declaration.id.type is always 'Identifier' for FunctionDeclarations and ClassDeclarations
52964
+ set.add(declaration.id.name);
52965
+ }
52966
+ else {
52967
+ const declarations = declaration.declarations;
52968
+ for (const declaration of declarations) {
52969
+ const id = declaration.id;
52970
+ if (id.type === 'Identifier') {
52971
+ set.add(id.name);
52972
+ }
52973
+ }
52974
+ }
52975
+ }
52976
+ }
52977
+ });
52978
+ return Array.from(set);
52979
+ };
52914
52980
 
52915
52981
  ;// ./processor/transform/images.ts
52916
52982
 
@@ -71309,9 +71375,13 @@ const injectTailwindRoot = ({ components = {} }) => (node, index, parent) => {
71309
71375
  parent.children.splice(index, 1, wrapper);
71310
71376
  return SKIP;
71311
71377
  };
71312
- const tailwind = ({ components }) => async (tree) => {
71313
- visit(tree, isMDXElement, injectTailwindRoot({ components }));
71314
- await exportTailwindStylesheet(tree, components);
71378
+ const tailwind = ({ components }) => async (tree, vfile) => {
71379
+ const localComponents = getExports(tree).reduce((acc, name) => {
71380
+ acc[name] = String(vfile);
71381
+ return acc;
71382
+ }, {});
71383
+ visit(tree, isMDXElement, injectTailwindRoot({ components: { ...components, ...localComponents } }));
71384
+ await exportTailwindStylesheet(tree, { ...components, ...localComponents });
71315
71385
  return tree;
71316
71386
  };
71317
71387
  /* harmony default export */ const transform_tailwind = (tailwind);
@@ -83527,72 +83597,8 @@ const compile_compile = async (text, { components = {}, copyButtons, useTailwind
83527
83597
  ;// ./lib/exports.ts
83528
83598
 
83529
83599
 
83530
-
83531
- /* Example mdast structures to find first export name in a mdxjsEsm node:
83532
- There are three types of export declarations that we need to consider:
83533
- 1. VARIABLE DECLARATION
83534
- "type": "mdxjsEsm",
83535
- "value": "export const Foo = () => <div>Hello world</div>\nexport const Bar = () => <div>hello darkness my old friend</div>",
83536
- "data": {
83537
- "estree": {
83538
- "type": "Program",
83539
- "body": [
83540
- {
83541
- "type": "ExportNamedDeclaration",
83542
- "declaration": {
83543
- "type": "VariableDeclaration",
83544
- "declarations": [
83545
- {
83546
- "type": "VariableDeclarator",
83547
- "id": {
83548
- "type": "Identifier",
83549
- "name": "Foo" // --------> This is the export name
83550
- },
83551
- ...
83552
-
83553
- 2/3. FUNCTION DECLARATION & CLASS DECLARATION
83554
- "estree": {
83555
- "type": "Program",
83556
- "body": [
83557
- {
83558
- "type": "ExportNamedDeclaration",
83559
- "declaration": {
83560
- "type": "ClassDeclaration" | "FunctionDeclaration",
83561
- "id": {
83562
- "type": "Identifier",
83563
- "name": "Foo" // --------> This is the export name
83564
- },
83565
- */
83566
83600
  const exports_exports = (doc) => {
83567
- const set = new Set();
83568
- visit(lib_mdast(doc), isMDXEsm, (node) => {
83569
- // Once inside an mdxjsEsm node, we need to check for one or more declared exports within data.estree.body
83570
- // This is because single newlines \n are not considered as a new block, so there may be more than one export statement in a single mdxjsEsm node
83571
- const body = node.data?.estree.body;
83572
- if (!body)
83573
- return;
83574
- for (const child of body) {
83575
- if (child.type === 'ExportNamedDeclaration') {
83576
- // There are three types of ExportNamedDeclaration that we need to consider: VariableDeclaration, FunctionDeclaration, ClassDeclaration
83577
- const declaration = child.declaration;
83578
- // FunctionDeclaration and ClassDeclaration have the same structure
83579
- if (declaration.type !== 'VariableDeclaration') {
83580
- // Note: declaration.id.type is always 'Identifier' for FunctionDeclarations and ClassDeclarations
83581
- set.add(declaration.id.name);
83582
- }
83583
- else {
83584
- const declarations = declaration.declarations;
83585
- for (const declaration of declarations) {
83586
- const id = declaration.id;
83587
- if (id.type === 'Identifier') {
83588
- set.add(id.name);
83589
- }
83590
- }
83591
- }
83592
- }
83593
- }
83594
- });
83595
- return Array.from(set);
83601
+ return getExports(lib_mdast(doc));
83596
83602
  };
83597
83603
  /* harmony default export */ const lib_exports = (exports_exports);
83598
83604
 
package/dist/main.node.js CHANGED
@@ -57493,6 +57493,72 @@ const hasNamedExport = (tree, name) => {
57493
57493
  });
57494
57494
  return hasExport;
57495
57495
  };
57496
+ /* Example mdast structures to find first export name in a mdxjsEsm node:
57497
+ There are three types of export declarations that we need to consider:
57498
+ 1. VARIABLE DECLARATION
57499
+ "type": "mdxjsEsm",
57500
+ "value": "export const Foo = () => <div>Hello world</div>\nexport const Bar = () => <div>hello darkness my old friend</div>",
57501
+ "data": {
57502
+ "estree": {
57503
+ "type": "Program",
57504
+ "body": [
57505
+ {
57506
+ "type": "ExportNamedDeclaration",
57507
+ "declaration": {
57508
+ "type": "VariableDeclaration",
57509
+ "declarations": [
57510
+ {
57511
+ "type": "VariableDeclarator",
57512
+ "id": {
57513
+ "type": "Identifier",
57514
+ "name": "Foo" // --------> This is the export name
57515
+ },
57516
+ ...
57517
+
57518
+ 2/3. FUNCTION DECLARATION & CLASS DECLARATION
57519
+ "estree": {
57520
+ "type": "Program",
57521
+ "body": [
57522
+ {
57523
+ "type": "ExportNamedDeclaration",
57524
+ "declaration": {
57525
+ "type": "ClassDeclaration" | "FunctionDeclaration",
57526
+ "id": {
57527
+ "type": "Identifier",
57528
+ "name": "Foo" // --------> This is the export name
57529
+ },
57530
+ */
57531
+ const getExports = (tree) => {
57532
+ const set = new Set();
57533
+ visit(tree, isMDXEsm, (node) => {
57534
+ // Once inside an mdxjsEsm node, we need to check for one or more declared exports within data.estree.body
57535
+ // This is because single newlines \n are not considered as a new block, so there may be more than one export statement in a single mdxjsEsm node
57536
+ const body = node.data?.estree.body;
57537
+ if (!body)
57538
+ return;
57539
+ for (const child of body) {
57540
+ if (child.type === 'ExportNamedDeclaration') {
57541
+ // There are three types of ExportNamedDeclaration that we need to consider: VariableDeclaration, FunctionDeclaration, ClassDeclaration
57542
+ const declaration = child.declaration;
57543
+ // FunctionDeclaration and ClassDeclaration have the same structure
57544
+ if (declaration.type !== 'VariableDeclaration') {
57545
+ // Note: declaration.id.type is always 'Identifier' for FunctionDeclarations and ClassDeclarations
57546
+ set.add(declaration.id.name);
57547
+ }
57548
+ else {
57549
+ const declarations = declaration.declarations;
57550
+ for (const declaration of declarations) {
57551
+ const id = declaration.id;
57552
+ if (id.type === 'Identifier') {
57553
+ set.add(id.name);
57554
+ }
57555
+ }
57556
+ }
57557
+ }
57558
+ }
57559
+ });
57560
+ return Array.from(set);
57561
+ };
57496
57562
 
57497
57563
  ;// ./processor/transform/images.ts
57498
57564
 
@@ -75891,9 +75957,13 @@ const injectTailwindRoot = ({ components = {} }) => (node, index, parent) => {
75891
75957
  parent.children.splice(index, 1, wrapper);
75892
75958
  return SKIP;
75893
75959
  };
75894
- const tailwind = ({ components }) => async (tree) => {
75895
- visit(tree, isMDXElement, injectTailwindRoot({ components }));
75896
- await exportTailwindStylesheet(tree, components);
75960
+ const tailwind = ({ components }) => async (tree, vfile) => {
75961
+ const localComponents = getExports(tree).reduce((acc, name) => {
75962
+ acc[name] = String(vfile);
75963
+ return acc;
75964
+ }, {});
75965
+ visit(tree, isMDXElement, injectTailwindRoot({ components: { ...components, ...localComponents } }));
75966
+ await exportTailwindStylesheet(tree, { ...components, ...localComponents });
75897
75967
  return tree;
75898
75968
  };
75899
75969
  /* harmony default export */ const transform_tailwind = (tailwind);
@@ -88109,72 +88179,8 @@ const compile_compile = async (text, { components = {}, copyButtons, useTailwind
88109
88179
  ;// ./lib/exports.ts
88110
88180
 
88111
88181
 
88112
-
88113
- /* Example mdast structures to find first export name in a mdxjsEsm node:
88114
- There are three types of export declarations that we need to consider:
88115
- 1. VARIABLE DECLARATION
88116
- "type": "mdxjsEsm",
88117
- "value": "export const Foo = () => <div>Hello world</div>\nexport const Bar = () => <div>hello darkness my old friend</div>",
88118
- "data": {
88119
- "estree": {
88120
- "type": "Program",
88121
- "body": [
88122
- {
88123
- "type": "ExportNamedDeclaration",
88124
- "declaration": {
88125
- "type": "VariableDeclaration",
88126
- "declarations": [
88127
- {
88128
- "type": "VariableDeclarator",
88129
- "id": {
88130
- "type": "Identifier",
88131
- "name": "Foo" // --------> This is the export name
88132
- },
88133
- ...
88134
-
88135
- 2/3. FUNCTION DECLARATION & CLASS DECLARATION
88136
- "estree": {
88137
- "type": "Program",
88138
- "body": [
88139
- {
88140
- "type": "ExportNamedDeclaration",
88141
- "declaration": {
88142
- "type": "ClassDeclaration" | "FunctionDeclaration",
88143
- "id": {
88144
- "type": "Identifier",
88145
- "name": "Foo" // --------> This is the export name
88146
- },
88147
- */
88148
88182
  const exports_exports = (doc) => {
88149
- const set = new Set();
88150
- visit(lib_mdast(doc), isMDXEsm, (node) => {
88151
- // Once inside an mdxjsEsm node, we need to check for one or more declared exports within data.estree.body
88152
- // This is because single newlines \n are not considered as a new block, so there may be more than one export statement in a single mdxjsEsm node
88153
- const body = node.data?.estree.body;
88154
- if (!body)
88155
- return;
88156
- for (const child of body) {
88157
- if (child.type === 'ExportNamedDeclaration') {
88158
- // There are three types of ExportNamedDeclaration that we need to consider: VariableDeclaration, FunctionDeclaration, ClassDeclaration
88159
- const declaration = child.declaration;
88160
- // FunctionDeclaration and ClassDeclaration have the same structure
88161
- if (declaration.type !== 'VariableDeclaration') {
88162
- // Note: declaration.id.type is always 'Identifier' for FunctionDeclarations and ClassDeclarations
88163
- set.add(declaration.id.name);
88164
- }
88165
- else {
88166
- const declarations = declaration.declarations;
88167
- for (const declaration of declarations) {
88168
- const id = declaration.id;
88169
- if (id.type === 'Identifier') {
88170
- set.add(id.name);
88171
- }
88172
- }
88173
- }
88174
- }
88175
- }
88176
- });
88177
- return Array.from(set);
88183
+ return getExports(lib_mdast(doc));
88178
88184
  };
88179
88185
  /* harmony default export */ const lib_exports = (exports_exports);
88180
88186