@readme/markdown 7.6.6 → 7.7.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.
Files changed (86) hide show
  1. package/README.md +60 -79
  2. package/components/Code/index.tsx +7 -3
  3. package/components/Code/style.scss +6 -0
  4. package/components/CodeTabs/index.tsx +25 -2
  5. package/components/Image/style.scss +7 -4
  6. package/dist/10.js +22718 -0
  7. package/dist/10.node.js +22721 -0
  8. package/dist/11.js +1440 -0
  9. package/dist/11.node.js +1443 -0
  10. package/dist/120.js +19 -0
  11. package/dist/120.node.js +22 -0
  12. package/dist/134.js +19 -0
  13. package/dist/134.node.js +22 -0
  14. package/dist/150.js +1888 -0
  15. package/dist/150.node.js +1891 -0
  16. package/dist/17.js +1373 -0
  17. package/dist/17.node.js +1376 -0
  18. package/dist/246.js +1929 -0
  19. package/dist/246.node.js +1932 -0
  20. package/dist/351.js +2400 -0
  21. package/dist/351.node.js +2403 -0
  22. package/dist/366.js +1181 -0
  23. package/dist/366.node.js +1184 -0
  24. package/dist/403.js +2192 -0
  25. package/dist/403.node.js +2195 -0
  26. package/dist/429.js +11130 -0
  27. package/dist/429.node.js +11133 -0
  28. package/dist/485.js +514 -0
  29. package/dist/485.node.js +517 -0
  30. package/dist/488.js +55 -0
  31. package/dist/488.node.js +58 -0
  32. package/dist/489.js +18472 -0
  33. package/dist/489.node.js +18475 -0
  34. package/dist/510.js +246 -0
  35. package/dist/510.node.js +249 -0
  36. package/dist/52.js +808 -0
  37. package/dist/52.node.js +811 -0
  38. package/dist/550.node.js +1456 -0
  39. package/dist/551.js +2722 -0
  40. package/dist/551.node.js +2725 -0
  41. package/dist/617.js +19 -0
  42. package/dist/617.node.js +22 -0
  43. package/dist/687.js +3671 -0
  44. package/dist/687.node.js +3674 -0
  45. package/dist/745.js +7504 -0
  46. package/dist/745.node.js +7507 -0
  47. package/dist/775.js +1900 -0
  48. package/dist/775.node.js +1903 -0
  49. package/dist/786.js +31378 -0
  50. package/dist/786.node.js +31381 -0
  51. package/dist/788.js +1021 -0
  52. package/dist/788.node.js +1024 -0
  53. package/dist/81.js +382 -0
  54. package/dist/81.node.js +385 -0
  55. package/dist/849.js +2586 -0
  56. package/dist/849.node.js +2589 -0
  57. package/dist/863.js +19 -0
  58. package/dist/863.node.js +22 -0
  59. package/dist/867.js +1414 -0
  60. package/dist/867.node.js +1417 -0
  61. package/dist/871.js +1533 -0
  62. package/dist/881.js +1276 -0
  63. package/dist/881.node.js +1279 -0
  64. package/dist/885.js +48 -0
  65. package/dist/885.node.js +51 -0
  66. package/dist/896.js +1613 -0
  67. package/dist/896.node.js +1616 -0
  68. package/dist/906.js +1815 -0
  69. package/dist/906.node.js +1818 -0
  70. package/dist/91.js +19 -0
  71. package/dist/91.node.js +22 -0
  72. package/dist/940.js +3359 -0
  73. package/dist/940.node.js +3362 -0
  74. package/dist/952.js +243 -0
  75. package/dist/952.node.js +246 -0
  76. package/dist/995.js +5734 -0
  77. package/dist/995.node.js +5737 -0
  78. package/dist/components/Code/index.d.ts +1 -1
  79. package/dist/lib/ast-processor.d.ts +3 -1
  80. package/dist/lib/compile.d.ts +2 -1
  81. package/dist/main.css +1 -1
  82. package/dist/main.js +94787 -73737
  83. package/dist/main.node.js +103724 -82783
  84. package/dist/processor/transform/code-tabs.d.ts +3 -1
  85. package/dist/processor/transform/index.d.ts +12 -1
  86. package/package.json +3 -3
package/README.md CHANGED
@@ -1,129 +1,110 @@
1
- # @readme/markdown
1
+ # <img align="right" width="26%" src="https://owlbertsio-resized.s3.amazonaws.com/Reading.psd.full.png"> `@readme/markdown`
2
2
 
3
- <img align="right" width="26%" src="https://owlbertsio-resized.s3.amazonaws.com/Reading.psd.full.png">
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)!)*
4
5
 
5
- ReadMe's MDX rendering engine and custom component collection. <img align=center src=https://github.com/readmeio/markdown/workflows/CI/badge.svg alt="RDMD CI Status">
6
+ ## Getting Started
7
+
8
+ To use the engine, install it from NPM:
6
9
 
7
10
  ```
8
11
  npm install --save @readme/markdown
9
12
  ```
10
13
 
11
- ## Usage
14
+ Then [`compile`](#compile) and [`run`](#run) your MDX:
12
15
 
13
16
  ```jsx
14
- import React from 'react';
15
- import rmdx from '@readme/markdown';
17
+ import RMDX from '@readme/markdown';
16
18
 
17
- export default ({ body }) => <div className="markdown-body">{run(compile(body))}</div>;
19
+ export default ({ body }) => (
20
+ <div className="markdown-body">
21
+ {RMDX.run(RMDX.compile(body))}
22
+ </div>
23
+ );
18
24
  ```
19
25
 
20
- ### API
26
+ ## API
21
27
 
22
- #### `compile`
28
+ ### `compile`
23
29
 
24
- Compiles MDX to JS. Essentially a wrapper around [`mdx.compile`](https://mdxjs.com/packages/mdx/#compilefile-options). You usually only need this when calling `run` as well. It's been left as a seperate step as a potential caching opportunity.
30
+ Compiles MDX to JS. Essentially a wrapper around [`mdx.compile`](https://mdxjs.com/packages/mdx/#compilefile-options). Used before calling [`run`](#run); it has been left as a seperate method for potential caching opportunities.
25
31
 
26
- ###### Parameters
32
+ #### Parameters
27
33
 
28
- - `string` (`string`) -- an MDX document
29
- - `opts` ([`CompileOpts`](#compileopts), optional) -- a configuration object
34
+ - **`string`** (`string`)an MDX document
35
+ - **`opts`** ([`CompileOpts`](#compileopts), optional)a configuration object
30
36
 
31
- ###### Returns
37
+ #### Returns
32
38
 
33
- compiled code (`string`)
39
+ A string of compiled Javascript module code.
34
40
 
35
- #### `run`
41
+ ### `run`
36
42
 
37
43
  > [!CAUTION]
38
- > **This will `eval` the compiled MDX**! Essentially a wrapper around [`mdx.run`](https://mdxjs.com/packages/mdx/#runcode-options).
39
-
40
- ###### Parameters
41
-
42
- - `string` (`string`) -- A compiled mdx document
43
- - `opts` (`RunOpts`, optional) -- configuration
44
-
45
- ###### Returns
46
-
47
- A module ([`RMDXModule`](#rmdxmodule)) of renderable components
48
-
49
- #### `mdx`
50
-
51
- Compiles an ast to mdx.
52
-
53
- ###### Parameters
54
-
55
- Extends [`remark-stringify` options](https://github.com/remarkjs/remark/tree/main/packages/remark-stringify#options).
56
-
57
- ###### Returns
44
+ > 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.
58
52
 
59
- An mdx string.
53
+ ### `mdx`
60
54
 
61
- #### `mdast`
55
+ Compiles an AST to a string of MDX syntax.
62
56
 
63
- Parses mdx to an mdast.
57
+ #### Parameters
64
58
 
65
- #### `hast`
59
+ - **`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.
66
61
 
67
- Parses mdx to an hast.
62
+ #### Returns
68
63
 
69
- #### `plain`
64
+ An MDX string.
70
65
 
71
- Parses mdx to a plain string. (This **does** not `eval` the doc.)
66
+ ### Other Methods
72
67
 
73
- #### `tags`
68
+ - **`mdast`**: parse MDX syntax to MDAST.
69
+ - **`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.)
72
+ - **`utils`**: additional defaults, helper methods, components, and so on.
74
73
 
75
- Returns a list of tag names from the doc. (This **does** not `eval` the doc.)
76
-
77
- #### `utils`
78
-
79
- Additional defaults, helpers, components, etc.
74
+ ## Types
80
75
 
81
76
  ### `CompileOpts`
82
77
 
83
78
  Extends [`CompileOptions`](https://mdxjs.com/packages/mdx/#compileoptions)
84
79
 
85
- ###### Additional Properties
80
+ ##### Additional Properties
86
81
 
87
- - `lazyImages` (`boolean`, optional) -- load images lazily
88
- - `safeMode` (`boolean`, optional) -- extract script tags from `HTMLBlock`s
89
- - `components` (`Record<string, string>`, optional) -- an object of tag names to mdx.
90
- - `copyButtons` (`Boolean`, optional) — add a copy button to code blocks
82
+ - **`lazyImages`** (`boolean`, optional)load images lazily
83
+ - **`safeMode`** (`boolean`, optional)extract script tags from `HTMLBlock`s
84
+ - **`components`** (`Record<string, string>`, optional)an object of tag names to mdx.
85
+ - **`copyButtons`** (`Boolean`, optional) — add a copy button to code blocks
91
86
 
92
87
  ### `RunOpts`
93
88
 
94
89
  Extends [`RunOptions`](https://mdxjs.com/packages/mdx/#runoptions)
95
90
 
96
- ###### Additional Properties
91
+ ##### Additional Properties
97
92
 
98
- - `components` (`Record<string, MDXModule>`, optional) -- a set of custom MDX components
99
- - `imports` (`Record<string, unknown>`, optional) -- an set of modules to import globally
100
- - `terms` (`GlossaryTerm[]`, optional)
101
- - `variables` (`Variables`, optional) -- an object containing [user variables](https://github.com/readmeio/variable)
93
+ - **`components`** (`Record<string, MDXModule>`, optional)a set of custom MDX components
94
+ - **`imports`** (`Record<string, unknown>`, optional)an set of modules to import globally
95
+ - **`terms`** (`GlossaryTerm[]`, optional)
96
+ - **`variables`** (`Variables`, optional)an object containing [user variables](https://github.com/readmeio/variable)
102
97
 
103
98
  ### `RMDXModule`
104
99
 
105
- ###### Properties
106
-
107
- - `default` (`() => MDXContent`) -- the MDX douments default export
108
- - `toc` (`HastHeading[]`) -- a list of headings in the document
109
- - `Toc` (`() => MDCContent`) -- a table of contents component
100
+ ##### Properties
110
101
 
111
- ## Flavored Syntax
102
+ - **`default`** (`() => MDXContent`)—the MDX douments default export
103
+ - **`toc`** (`HastHeading[]`)—a list of headings in the document
104
+ - **`Toc`** (`() => MDCContent`)—a table of contents component
112
105
 
113
- We've also sprinkled a bit of our own custom components in to help you supercharge your docs. [**Learn more about ReadMe's new MDX engine!**](https://docs.readme.com/rdmd/page/mdx-engine)
114
-
115
- ## Local Development
106
+ ## Local Development and Testing
116
107
 
117
108
  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`!
118
109
 
119
- ### Environment setup
120
-
121
- Running the browser tests requires `docker`. Follow the docker [install instructions for mac](https://docs.docker.com/docker-for-mac/install/). You may want to increase the [memory usage](https://docs.docker.com/docker-for-mac/#resources). If you have not already, you'll need to create an account for `docker hub` and [sign-in locally](https://docs.docker.com/docker-for-mac/#docker-hub).
122
-
123
- ### Running visual regression tests
124
-
125
- If you make changes to the docs or how the markdown is rendered, you may need to update the visual regression snapshots. You can run the visual regression tests in a docker container with:
126
-
127
- ```
128
- make updateSnapshot
129
- ```
110
+ If you make changes to the docs or how the markdown is rendered, you may need to update the visual regression snapshots by running `make updateSnapshot`. Running these browser tests requires `docker`. Follow the docker [install instructions for mac](https://docs.docker.com/docker-for-mac/install/). You may want to increase the [memory usage](https://docs.docker.com/docker-for-mac/#resources). If you have not already, you'll need to create an account for `docker hub` and [sign-in locally](https://docs.docker.com/docker-for-mac/#docker-hub).
@@ -16,20 +16,20 @@ if (typeof window !== 'undefined') {
16
16
 
17
17
  function CopyCode({ codeRef, rootClass = 'rdmd-code-copy', className = '' }) {
18
18
  const copyClass = `${rootClass}_copied`;
19
- const button = createRef<HTMLButtonElement>();
19
+ const buttonRef = createRef<HTMLButtonElement>();
20
20
 
21
21
  const copier = () => {
22
22
  const code = codeRef.current.textContent;
23
23
 
24
24
  if (copy(code)) {
25
- const el = button.current;
25
+ const el = buttonRef.current;
26
26
  el.classList.add(copyClass);
27
27
 
28
28
  setTimeout(() => el.classList.remove(copyClass), 1500);
29
29
  }
30
30
  };
31
31
 
32
- return <button ref={button} aria-label="Copy Code" className={`${rootClass} ${className}`} onClick={copier} />;
32
+ return <button ref={buttonRef} aria-label="Copy Code" className={`${rootClass} ${className}`} onClick={copier} />;
33
33
  }
34
34
 
35
35
  interface CodeProps {
@@ -57,6 +57,10 @@ const Code = (props: CodeProps) => {
57
57
  const code = value ?? (Array.isArray(children) ? children[0] : children) ?? '';
58
58
  const highlightedCode = syntaxHighlighter && code ? syntaxHighlighter(code, language, codeOpts, { mdx: true }) : code;
59
59
 
60
+ if (language === 'mermaid') {
61
+ return code;
62
+ }
63
+
60
64
  return (
61
65
  <>
62
66
  {copyButtons && <CopyCode className="fa" codeRef={codeRef} />}
@@ -84,6 +84,12 @@
84
84
  word-wrap: normal;
85
85
  }
86
86
 
87
+ pre.mermaid {
88
+ &_single {
89
+ background: var(--color-bg-page, white);
90
+ }
91
+ }
92
+
87
93
  kbd {
88
94
  background-color: $background;
89
95
  background-color: var(--d-code-background, $background);
@@ -1,9 +1,17 @@
1
1
  import { uppercase } from '@readme/syntax-highlighter';
2
- import React from 'react';
2
+ import React, { useEffect } from 'react';
3
+ import mermaid from 'mermaid';
3
4
 
4
5
  const CodeTabs = props => {
5
6
  const { children, theme } = props;
6
7
 
8
+ // set Mermaid theme
9
+ useEffect(() => {
10
+ mermaid.initialize({
11
+ theme: theme === 'dark' ? 'dark' : 'default',
12
+ });
13
+ }, [theme])
14
+
7
15
  function handleClick({ target }, index: number) {
8
16
  const $wrap = target.parentElement.parentElement;
9
17
  const $open = [].slice.call($wrap.querySelectorAll('.CodeTabs_active'));
@@ -14,6 +22,21 @@ const CodeTabs = props => {
14
22
  codeblocks[index].classList.add('CodeTabs_active');
15
23
 
16
24
  target.classList.add('CodeTabs_active');
25
+
26
+ if (target.value === 'mermaid') {
27
+ const $openMermaid = [].slice.call($wrap.querySelectorAll('.mermaid'));
28
+ $openMermaid.forEach((el: Element) => el.classList.remove('mermaid'));
29
+ codeblocks[index].classList.add('mermaid');
30
+ mermaid.contentLoaded();
31
+ }
32
+ }
33
+
34
+ // render single Mermaid diagram
35
+ if (!Array.isArray(children) && children.props?.children.props.lang === 'mermaid') {
36
+ const value = children.props.children.props.value;
37
+ return (
38
+ <pre className="mermaid mermaid_single">{value}</pre>
39
+ )
17
40
  }
18
41
 
19
42
  return (
@@ -24,7 +47,7 @@ const CodeTabs = props => {
24
47
 
25
48
  /* istanbul ignore next */
26
49
  return (
27
- <button key={i} onClick={e => handleClick(e, i)} type="button">
50
+ <button key={i} onClick={e => handleClick(e, i)} type="button" value={lang}>
28
51
  {meta || `${!lang ? 'Text' : uppercase(lang)}`}
29
52
  </button>
30
53
  );
@@ -28,15 +28,19 @@
28
28
  outline: none !important;
29
29
  vertical-align: middle;
30
30
 
31
+ &.img-align-right,
31
32
  &[align='right'],
32
33
  &[alt~='align-right'] {
33
34
  @extend %img-align-right;
34
35
  }
35
36
 
37
+ &.img-align-left,
36
38
  &[align='left'],
37
39
  &[alt~='align-left'] {
38
40
  @extend %img-align-left;
41
+
39
42
  }
43
+ &.img-align-center,
40
44
  &[align='middle'], // hack to fix Firefox; see: https://stackoverflow.com/a/45901819/1341949
41
45
  &[align='center'],
42
46
  &[alt~='align-center'] {
@@ -65,8 +69,10 @@
65
69
  }
66
70
  }
67
71
 
72
+ > .img,
68
73
  > img,
69
74
  figure > img {
75
+ display: block;
70
76
  @extend %img-align-center;
71
77
  }
72
78
 
@@ -97,16 +103,13 @@
97
103
  content: '\f00d';
98
104
  cursor: pointer;
99
105
  display: inline-block;
100
- font: normal normal normal 2em/1 FontAwesome;
106
+ font-family: var(--fa-style-family, 'Font Awesome 6 Pro');
101
107
  font-size: inherit;
102
- -webkit-font-smoothing: antialiased;
103
- -moz-osx-font-smoothing: grayscale;
104
108
  opacity: 1;
105
109
  position: fixed;
106
110
  right: 1em;
107
111
  text-rendering: auto;
108
112
  top: 1em;
109
- transform: translate(0, 0);
110
113
  transform: scale(1.5);
111
114
  transition: 0.3s 0.3s ease-in;
112
115
  }