@readme/markdown 13.8.5 → 14.1.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/dist/example/components.d.ts +1 -0
- package/dist/lib/constants.d.ts +18 -0
- package/dist/lib/mdast-util/mdx-component/index.d.ts +15 -0
- package/dist/lib/mdxish.d.ts +0 -2
- package/dist/lib/micromark/jsx-comment/index.d.ts +1 -0
- package/dist/lib/micromark/jsx-comment/pattern.d.ts +10 -0
- package/dist/lib/micromark/jsx-comment/syntax.d.ts +2 -0
- package/dist/lib/micromark/mdx-component/index.d.ts +1 -0
- package/dist/lib/micromark/mdx-component/syntax.d.ts +30 -0
- package/dist/lib/utils/mdxish/mdxish-component-tag-parser.d.ts +33 -0
- package/dist/main.css +1 -1
- package/dist/main.css.map +1 -1
- package/dist/main.js +5533 -4552
- package/dist/main.node.js +5617 -4636
- package/dist/main.node.js.map +1 -1
- package/dist/processor/transform/mdxish/components/inline-html.d.ts +22 -0
- package/dist/processor/transform/mdxish/{mdxish-inline-components.d.ts → components/inline-mdx-blocks.d.ts} +3 -3
- package/dist/processor/transform/mdxish/components/mdx-blocks.d.ts +34 -0
- package/dist/processor/transform/mdxish/components/utils.d.ts +29 -0
- package/dist/processor/transform/mdxish/evaluate-expressions.d.ts +5 -5
- package/dist/processor/transform/mdxish/normalize-mdx-jsx-nodes.d.ts +15 -0
- package/dist/processor/transform/mdxish/preprocess-jsx-expressions.d.ts +6 -24
- package/dist/processor/transform/mdxish/restore-snake-case-component-name.d.ts +1 -1
- package/dist/processor/utils.d.ts +14 -0
- package/package.json +1 -1
- package/styles/gfm.scss +2 -2
- package/types.d.ts +26 -1
- package/dist/processor/transform/mdxish/constants.d.ts +0 -5
- package/dist/processor/transform/mdxish/mdxish-component-blocks.d.ts +0 -69
- /package/dist/processor/transform/mdxish/{mdxish-self-closing-blocks.d.ts → components/self-closing-blocks.d.ts} +0 -0
- /package/dist/processor/transform/mdxish/{mdxish-snake-case-components.d.ts → components/snake-case-components.d.ts} +0 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Root } from 'mdast';
|
|
2
|
+
import type { Plugin } from 'unified';
|
|
3
|
+
/**
|
|
4
|
+
* Transform inline html nodes with expression attributes
|
|
5
|
+
* inside paragraphs into `mdxJsxTextElement`s.
|
|
6
|
+
*
|
|
7
|
+
* Runs after `mdxishComponentBlocks`, which skips paragraph-parented html
|
|
8
|
+
* nodes and leaves them for this pass. Two producers put html nodes inside
|
|
9
|
+
* paragraphs:
|
|
10
|
+
* 1. The `mdxComponent` text tokenizer, for lowercase tags with `{…}`
|
|
11
|
+
* attribute expressions (e.g. `<a href={url}>here</a>`).
|
|
12
|
+
* 2. CommonMark's built-in html-text tokenizer, for PascalCase components
|
|
13
|
+
* (e.g. a single html node for self-closing `<C />`).
|
|
14
|
+
*
|
|
15
|
+
* Eligibility mirrors `mdxishComponentBlocks`: lowercase tags only promote
|
|
16
|
+
* when they carry an expression attribute; plain inline HTML like
|
|
17
|
+
* `<a href="x">` stays as an html node for rehype-raw.
|
|
18
|
+
*/
|
|
19
|
+
declare const mdxishInlineMdxHtmlBlocks: Plugin<[{
|
|
20
|
+
safeMode?: boolean;
|
|
21
|
+
}?], Root>;
|
|
22
|
+
export default mdxishInlineMdxHtmlBlocks;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Parent } from 'mdast';
|
|
2
2
|
import type { Plugin } from 'unified';
|
|
3
3
|
/**
|
|
4
|
-
* Transforms inline html
|
|
4
|
+
* Transforms inline MDX blocks inside html nodes (e.g. <Anchor>) into proper MDAST phrasing content.
|
|
5
5
|
*
|
|
6
6
|
* Inline components are excluded from mdxishComponentBlocks (which only handles block-level
|
|
7
7
|
* elements), so they remain as scattered html/text/html sibling nodes inside a paragraph.
|
|
8
8
|
* This plugin merges them into a single typed MDAST node.
|
|
9
9
|
*/
|
|
10
|
-
declare const
|
|
11
|
-
export default
|
|
10
|
+
declare const mdxishInlineMdxComponents: Plugin<[], Parent>;
|
|
11
|
+
export default mdxishInlineMdxComponents;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { Parent } from 'mdast';
|
|
2
|
+
import type { Plugin } from 'unified';
|
|
3
|
+
export { parseAttributes, parseTag } from '../../../../lib/utils/mdxish/mdxish-component-tag-parser';
|
|
4
|
+
/**
|
|
5
|
+
* Transform PascalCase HTML nodes into mdxJsxFlowElement nodes.
|
|
6
|
+
*
|
|
7
|
+
* Remark parses unknown/custom component tags as raw HTML nodes.
|
|
8
|
+
* These are the custom readme MDX syntax for components.
|
|
9
|
+
* This transformer identifies these patterns and converts them to proper MDX JSX elements so they
|
|
10
|
+
* can be accurately recognized and rendered later with their component definition code.
|
|
11
|
+
*
|
|
12
|
+
* The mdx-component micromark tokenizer ensures that multi-line components are captured
|
|
13
|
+
* as single HTML nodes, so this transformer only needs to handle two cases:
|
|
14
|
+
*
|
|
15
|
+
* ### 1. Self-closing tags
|
|
16
|
+
* ```
|
|
17
|
+
* <Component />
|
|
18
|
+
* ```
|
|
19
|
+
* Parsed as: `html: "<Component />"`
|
|
20
|
+
*
|
|
21
|
+
* ### 2. Self-contained blocks (entire component in single HTML node)
|
|
22
|
+
* ```
|
|
23
|
+
* <Component>
|
|
24
|
+
* content
|
|
25
|
+
* </Component>
|
|
26
|
+
* ```
|
|
27
|
+
* Parsed as: `html: "<Component>\n content\n</Component>"`
|
|
28
|
+
* The opening tag, content, and closing tag are all captured in one HTML node
|
|
29
|
+
* (guaranteed by the mdx-component tokenizer).
|
|
30
|
+
*/
|
|
31
|
+
declare const mdxishMdxComponentBlocks: Plugin<[{
|
|
32
|
+
safeMode?: boolean;
|
|
33
|
+
}?], Parent>;
|
|
34
|
+
export default mdxishMdxComponentBlocks;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Html, PhrasingContent } from 'mdast';
|
|
2
|
+
import type { MdxJsxAttribute, MdxJsxExpressionAttribute, MdxJsxTextElement } from 'mdast-util-mdx-jsx';
|
|
3
|
+
export type MdxAttributes = (MdxJsxAttribute | MdxJsxExpressionAttribute)[];
|
|
4
|
+
/**
|
|
5
|
+
* Shared unified processor for re-parsing the body of an MDX-ish component.
|
|
6
|
+
* Used by both the block and inline-block transformers so a nested component
|
|
7
|
+
* (e.g. `<Anchor>text with <b>bold</b></Anchor>`) goes through the same
|
|
8
|
+
* tokenizer chain as the top-level parse.
|
|
9
|
+
*/
|
|
10
|
+
export declare const inlineMdProcessor: import("unified").Processor<import("mdast").Root, undefined, undefined, undefined, undefined>;
|
|
11
|
+
/**
|
|
12
|
+
* True when a tag name starts with an uppercase letter — ReadMe's marker for
|
|
13
|
+
* a custom MDX component (vs a lowercase HTML tag).
|
|
14
|
+
*/
|
|
15
|
+
export declare const isPascalCase: (tag: string) => boolean;
|
|
16
|
+
/**
|
|
17
|
+
* True when the attribute list contains at least one JSX expression value
|
|
18
|
+
* (e.g. `href={url}`). The `mdxComponent` tokenizer only claims lowercase
|
|
19
|
+
* tags when they carry one of these; both block transformers use the same
|
|
20
|
+
* signal to decide eligibility.
|
|
21
|
+
*/
|
|
22
|
+
export declare const hasExpressionAttr: (attributes: MdxAttributes) => boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Factory for the `mdxJsxTextElement` node shape. `position` is optional
|
|
25
|
+
* because the two call sites differ: the tokenized-tag path carries the
|
|
26
|
+
* original html node's position forward, while the sibling-merge path
|
|
27
|
+
* composes children from pre-existing nodes with no outer position.
|
|
28
|
+
*/
|
|
29
|
+
export declare const toMdxJsxTextElement: (name: string, attributes: MdxAttributes, children: PhrasingContent[], position?: Html["position"]) => MdxJsxTextElement;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import type { Root } from 'mdast';
|
|
2
2
|
import type { Plugin } from 'unified';
|
|
3
|
-
import { type JSXContext } from './preprocess-jsx-expressions';
|
|
4
3
|
/**
|
|
5
|
-
* AST transformer to evaluate MDX expressions
|
|
4
|
+
* AST transformer to evaluate MDX expressions.
|
|
6
5
|
* Replaces mdxFlowExpression and mdxTextExpression nodes with their evaluated values.
|
|
6
|
+
* Runs with no scope, so only self-contained expressions resolve
|
|
7
|
+
* (e.g. `{1+1}`, `{"hi".toUpperCase()}`); anything that references an external
|
|
8
|
+
* identifier falls through to the error branch and is kept as literal `{...}` text.
|
|
7
9
|
*/
|
|
8
|
-
declare const evaluateExpressions: Plugin<[
|
|
9
|
-
context?: JSXContext;
|
|
10
|
-
}], Root>;
|
|
10
|
+
declare const evaluateExpressions: Plugin<[], Root>;
|
|
11
11
|
export default evaluateExpressions;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Root } from 'hast';
|
|
2
|
+
import type { Plugin } from 'unified';
|
|
3
|
+
/**
|
|
4
|
+
* Rewrite `mdx-jsx` nodes (stitched through rehypeRaw untouched) into standard
|
|
5
|
+
* `element` nodes so rehype-react and downstream element-walking plugins handle
|
|
6
|
+
* them normally. Non-primitive attribute values — objects, arrays, numbers —
|
|
7
|
+
* stay as real JS values here because they never went through parse5.
|
|
8
|
+
*
|
|
9
|
+
* Tag names that match a standard HTML element are lowercased to match what
|
|
10
|
+
* parse5 used to produce during the rehypeRaw round-trip (e.g. `<Table>` that
|
|
11
|
+
* slipped past the mdxishTables transformer still ends up as `<table>`).
|
|
12
|
+
* PascalCase custom component names are left alone for `rehypeMdxishComponents`.
|
|
13
|
+
*/
|
|
14
|
+
declare const normalizeMdxJsxNodes: Plugin<[], Root>;
|
|
15
|
+
export default normalizeMdxJsxNodes;
|
|
@@ -1,26 +1,6 @@
|
|
|
1
1
|
export declare function base64Decode(str: string): string;
|
|
2
|
-
export declare const JSON_VALUE_MARKER = "__MDXISH_JSON__";
|
|
3
2
|
export declare const HTML_BLOCK_CONTENT_START = "<!--RDMX_HTMLBLOCK:";
|
|
4
3
|
export declare const HTML_BLOCK_CONTENT_END = ":RDMX_HTMLBLOCK-->";
|
|
5
|
-
/**
|
|
6
|
-
* Pre-processes JSX-like expressions before markdown parsing.
|
|
7
|
-
* Converts href={'value'} to href="value", evaluates {expressions}, etc.
|
|
8
|
-
*/
|
|
9
|
-
export type JSXContext = Record<string, unknown>;
|
|
10
|
-
/**
|
|
11
|
-
* Evaluates a JavaScript expression using context variables.
|
|
12
|
-
*
|
|
13
|
-
* @param expression
|
|
14
|
-
* @param context
|
|
15
|
-
* @returns The evaluated result
|
|
16
|
-
* @example
|
|
17
|
-
* ```typescript
|
|
18
|
-
* const context = { baseUrl: 'https://example.com', path: '/api' };
|
|
19
|
-
* evaluateExpression('baseUrl + path', context)
|
|
20
|
-
* // Returns: 'https://example.com/api'
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
export declare function evaluateExpression(expression: string, context: JSXContext): any;
|
|
24
4
|
/**
|
|
25
5
|
* Removes JSX-style comments (e.g., { /* comment *\/ }) from content.
|
|
26
6
|
*
|
|
@@ -34,11 +14,13 @@ export declare function evaluateExpression(expression: string, context: JSXConte
|
|
|
34
14
|
*/
|
|
35
15
|
export declare function removeJSXComments(content: string): string;
|
|
36
16
|
/**
|
|
37
|
-
* Preprocesses JSX-like
|
|
38
|
-
*
|
|
17
|
+
* Preprocesses JSX-like markdown content before parsing.
|
|
18
|
+
*
|
|
19
|
+
* JSX attribute expressions (`href={baseUrl}`) are no longer rewritten here —
|
|
20
|
+
* they flow through the tokenizer as `mdxJsxAttributeValueExpression` nodes
|
|
21
|
+
* and are evaluated at the hast handler step.
|
|
39
22
|
*
|
|
40
23
|
* @param content
|
|
41
|
-
* @param context
|
|
42
24
|
* @returns Preprocessed content ready for markdown parsing
|
|
43
25
|
*/
|
|
44
|
-
export declare function preprocessJSXExpressions(content: string
|
|
26
|
+
export declare function preprocessJSXExpressions(content: string): string;
|
|
@@ -2,6 +2,20 @@ import type { Root as HastRoot } from 'hast';
|
|
|
2
2
|
import type { Node, Root as MdastRoot, Root } from 'mdast';
|
|
3
3
|
import type { MdxJsxFlowElement, MdxJsxTextElement, MdxjsEsm } from 'mdast-util-mdx';
|
|
4
4
|
import type { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
|
|
5
|
+
/**
|
|
6
|
+
* Evaluate a JavaScript expression source and return its value.
|
|
7
|
+
*
|
|
8
|
+
* Wrapping in parens lets object literals (`{color: 'red'}`) parse as
|
|
9
|
+
* expressions. Runs with no scope, so only self-contained literals resolve.
|
|
10
|
+
*
|
|
11
|
+
* > ☢️ **Danger**: this `eval`s JavaScript. Only call when safeMode is off —
|
|
12
|
+
* > safeMode's contract is that expression syntax is never evaluated, and the
|
|
13
|
+
* > pipeline guards against reaching this path by keeping attribute expressions
|
|
14
|
+
* > as literal strings and skipping the expression transformer entirely.
|
|
15
|
+
*
|
|
16
|
+
* Throws on parse/runtime error; callers decide the fallback.
|
|
17
|
+
*/
|
|
18
|
+
export declare function evaluate(source: string): any;
|
|
5
19
|
/**
|
|
6
20
|
* Formats the hProperties of a node as a string, so they can be compiled back into JSX/MDX.
|
|
7
21
|
* This currently sets all the values to a string since we process/compile the MDX on the fly
|
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": "
|
|
5
|
+
"version": "14.1.0",
|
|
6
6
|
"main": "dist/main.node.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
8
|
"browser": "dist/main.js",
|
package/styles/gfm.scss
CHANGED
|
@@ -209,14 +209,14 @@
|
|
|
209
209
|
|
|
210
210
|
ol ol,
|
|
211
211
|
ul ol {
|
|
212
|
-
list-style-type: lower-
|
|
212
|
+
list-style-type: lower-alpha;
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
ol ol ol,
|
|
216
216
|
ol ul ol,
|
|
217
217
|
ul ol ol,
|
|
218
218
|
ul ul ol {
|
|
219
|
-
list-style-type: lower-
|
|
219
|
+
list-style-type: lower-roman;
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
dd {
|
package/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { NodeTypes } from './enums';
|
|
2
|
-
import type { Element } from 'hast';
|
|
2
|
+
import type { Element, ElementContent, Properties } from 'hast';
|
|
3
3
|
import type {
|
|
4
4
|
Code,
|
|
5
5
|
Data,
|
|
@@ -19,6 +19,31 @@ import type { MdxJsxFlowElementHast } from 'mdast-util-mdx-jsx';
|
|
|
19
19
|
import type { MDXModule } from 'mdx/types';
|
|
20
20
|
import type { Position } from 'unist';
|
|
21
21
|
|
|
22
|
+
/**
|
|
23
|
+
* Custom hast node emitted by `mdxJsxElementHandler` for every MDX JSX element.
|
|
24
|
+
* Registered with hast below so the unified/unist tooling (remark-rehype handlers,
|
|
25
|
+
* unist-util-visit, rehype-raw's passThrough) recognizes it as a first-class
|
|
26
|
+
* hast node. `properties` intentionally widens `hast`'s `Properties` type because
|
|
27
|
+
* attribute expressions evaluate to real JS values (objects, arrays, numbers)
|
|
28
|
+
* which don't fit hast's HTML-attribute-oriented `PropertyValue` union.
|
|
29
|
+
*/
|
|
30
|
+
export interface MdxJsx {
|
|
31
|
+
children: ElementContent[];
|
|
32
|
+
position?: Position;
|
|
33
|
+
properties: Properties;
|
|
34
|
+
tagName: string;
|
|
35
|
+
type: 'mdx-jsx';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
declare module 'hast' {
|
|
39
|
+
interface RootContentMap {
|
|
40
|
+
'mdx-jsx': MdxJsx;
|
|
41
|
+
}
|
|
42
|
+
interface ElementContentMap {
|
|
43
|
+
'mdx-jsx': MdxJsx;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
22
47
|
export type Callout = Omit<Blockquote, 'children' | 'type'> & {
|
|
23
48
|
children: BlockContent[];
|
|
24
49
|
data: Data & {
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type { Parent } from 'mdast';
|
|
2
|
-
import type { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
|
|
3
|
-
import type { Plugin } from 'unified';
|
|
4
|
-
/**
|
|
5
|
-
* Convert raw attribute string into mdxJsxAttribute entries.
|
|
6
|
-
* Handles both key-value attributes (theme="info") and boolean attributes (empty).
|
|
7
|
-
*/
|
|
8
|
-
export declare const parseAttributes: (raw: string) => MdxJsxAttribute[];
|
|
9
|
-
/**
|
|
10
|
-
* Transform PascalCase HTML nodes into mdxJsxFlowElement nodes.
|
|
11
|
-
*
|
|
12
|
-
* Remark parses unknown/custom component tags as raw HTML nodes.
|
|
13
|
-
* These are the custom readme MDX syntax for components.
|
|
14
|
-
* This transformer identifies these patterns and converts them to proper MDX JSX elements so they
|
|
15
|
-
* can be accurately recognized and rendered later with their component definition code.
|
|
16
|
-
* Though for some tags, we need to handle them specially
|
|
17
|
-
*
|
|
18
|
-
* ## Supported HTML Structures
|
|
19
|
-
*
|
|
20
|
-
* ### 1. Self-closing tags
|
|
21
|
-
* ```
|
|
22
|
-
* <Component />
|
|
23
|
-
* ```
|
|
24
|
-
* Parsed as: `html: "<Component />"`
|
|
25
|
-
*
|
|
26
|
-
* ### 2. Self-contained blocks (entire component in single HTML node)
|
|
27
|
-
* ```
|
|
28
|
-
* <Button>Click me</Button>
|
|
29
|
-
* ```
|
|
30
|
-
* ```
|
|
31
|
-
* <Component>
|
|
32
|
-
* <h2>Title</h2>
|
|
33
|
-
* <p>Content</p>
|
|
34
|
-
* </Component>
|
|
35
|
-
* ```
|
|
36
|
-
* Parsed as: `html: "<Component>\n <h2>Title</h2>\n <p>Content</p>\n</Component>"`
|
|
37
|
-
* The opening tag, content, and closing tag are all captured in one HTML node.
|
|
38
|
-
*
|
|
39
|
-
* ### 3. Multi-sibling components (closing tag in a following sibling)
|
|
40
|
-
* Handles various structures where the closing tag is in a later sibling, such as:
|
|
41
|
-
*
|
|
42
|
-
* #### 3a. Block components (closing tag in sibling paragraph)
|
|
43
|
-
* ```
|
|
44
|
-
* <Callout>
|
|
45
|
-
* Some **markdown** content
|
|
46
|
-
* </Callout>
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* #### 3b. Multi-paragraph components (closing tag several siblings away)
|
|
50
|
-
* ```
|
|
51
|
-
* <Callout>
|
|
52
|
-
*
|
|
53
|
-
* First paragraph
|
|
54
|
-
*
|
|
55
|
-
* Second paragraph
|
|
56
|
-
* </Callout>
|
|
57
|
-
* ```
|
|
58
|
-
*
|
|
59
|
-
* #### 3c. Nested components split by blank lines (closing tag embedded in HTML sibling)
|
|
60
|
-
* ```
|
|
61
|
-
* <Outer>
|
|
62
|
-
* <Inner>content</Inner>
|
|
63
|
-
*
|
|
64
|
-
* <Inner>content</Inner>
|
|
65
|
-
* </Outer>
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
declare const mdxishComponentBlocks: Plugin<[], Parent>;
|
|
69
|
-
export default mdxishComponentBlocks;
|
|
File without changes
|
|
File without changes
|