@readme/markdown 11.7.7 → 11.8.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 (31) hide show
  1. package/components/CodeTabs/index.tsx +6 -1
  2. package/components/HTMLBlock/index.tsx +17 -6
  3. package/dist/components/HTMLBlock/index.d.ts +4 -3
  4. package/dist/index.d.ts +1 -1
  5. package/dist/lib/ast-processor.d.ts +2 -0
  6. package/dist/lib/index.d.ts +5 -0
  7. package/dist/lib/mdxish.d.ts +16 -0
  8. package/dist/lib/mix.d.ts +4 -0
  9. package/dist/lib/renderMdxish.d.ts +14 -0
  10. package/dist/lib/utils/extractMagicBlocks.d.ts +1 -2
  11. package/dist/lib/utils/mdxish/mdxish-get-component-name.d.ts +11 -0
  12. package/dist/lib/utils/mdxish/mdxish-load-components.d.ts +7 -0
  13. package/dist/lib/utils/mdxish/mdxish-render-utils.d.ts +25 -0
  14. package/dist/main.js +11219 -5073
  15. package/dist/main.node.js +11768 -5622
  16. package/dist/main.node.js.map +1 -1
  17. package/dist/processor/plugin/mdxish-components.d.ts +19 -0
  18. package/dist/processor/plugin/mdxish-handlers.d.ts +2 -0
  19. package/dist/processor/plugin/toc.d.ts +7 -1
  20. package/dist/processor/transform/images.d.ts +3 -1
  21. package/dist/processor/transform/index.d.ts +13 -3
  22. package/dist/processor/transform/mdxish/evaluate-expressions.d.ts +11 -0
  23. package/dist/processor/transform/mdxish/mdxish-component-blocks.d.ts +6 -0
  24. package/dist/processor/transform/mdxish/mdxish-html-blocks.d.ts +6 -0
  25. package/dist/processor/transform/mdxish/mdxish-magic-blocks.d.ts +25 -0
  26. package/dist/processor/transform/mdxish/mdxish-tables.d.ts +9 -0
  27. package/dist/processor/transform/mdxish/preprocess-jsx-expressions.d.ts +17 -0
  28. package/dist/processor/transform/mdxish/variables-text.d.ts +9 -0
  29. package/dist/processor/utils.d.ts +8 -0
  30. package/dist/utils/common-html-words.d.ts +23 -0
  31. package/package.json +9 -2
@@ -0,0 +1,19 @@
1
+ import type { CustomComponents } from '../../types';
2
+ import type { Root } from 'hast';
3
+ import type { Transformer } from 'unified';
4
+ interface Options {
5
+ components: CustomComponents;
6
+ processMarkdown: (markdownContent: string) => Root;
7
+ }
8
+ /**
9
+ * Identifies custom MDX components and recursively parses markdown children.
10
+ * Replaces tagName with PascalCase component name for React component resolution.
11
+ *
12
+ * @see {@link https://github.com/readmeio/rmdx/blob/main/docs/mdxish-flow.md}
13
+ * @param {Options} options - Configuration options
14
+ * @param {CustomComponents} options.components - Available custom components
15
+ * @param {Function} options.processMarkdown - Function to process markdown content
16
+ * @returns {Transformer<Root, Root>} The transformer function
17
+ */
18
+ export declare const rehypeMdxishComponents: ({ components, processMarkdown }: Options) => Transformer<Root, Root>;
19
+ export {};
@@ -0,0 +1,2 @@
1
+ import type { Handlers } from 'mdast-util-to-hast';
2
+ export declare const mdxComponentHandlers: Handlers;
@@ -1,9 +1,15 @@
1
- import type { CustomComponents, IndexableElements, RMDXModule } from '../../types';
1
+ import type { CustomComponents, HastHeading, IndexableElements, RMDXModule, TocList } from '../../types';
2
2
  import type { Root } from 'hast';
3
3
  import type { Transformer } from 'unified';
4
4
  interface Options {
5
5
  components?: CustomComponents;
6
6
  }
7
+ /** Extract all heading elements (h1-h6) from a HAST tree, excluding those inside custom components
8
+ * Used to generate toc for mdxish
9
+ */
10
+ export declare function extractToc(tree: Root, components?: CustomComponents): HastHeading[];
11
+ /** A rehype plugin to generate a flat list of top-level headings or jsx flow elements. */
7
12
  export declare const rehypeToc: ({ components }: Options) => Transformer<Root, Root>;
13
+ export declare const tocToHast: (headings?: HastHeading[]) => TocList;
8
14
  export declare const tocHastToMdx: (toc: IndexableElements[] | undefined, components: Record<string, RMDXModule["toc"]>) => string;
9
15
  export {};
@@ -1,3 +1,5 @@
1
1
  import type { Node } from 'mdast';
2
- declare const imageTransformer: () => (tree: Node) => Node;
2
+ declare const imageTransformer: ({ isMdxish }?: {
3
+ isMdxish?: boolean;
4
+ }) => (tree: Node) => Node;
3
5
  export default imageTransformer;
@@ -3,6 +3,7 @@ import divTransformer from './div';
3
3
  import handleMissingComponents from './handle-missing-components';
4
4
  import injectComponents from './inject-components';
5
5
  import mdxToHast from './mdx-to-hast';
6
+ import mdxishTables from './mdxish/mdxish-tables';
6
7
  import mermaidTransformer from './mermaid';
7
8
  import readmeComponentsTransformer from './readme-components';
8
9
  import readmeToMdx from './readme-to-mdx';
@@ -10,17 +11,26 @@ import tablesToJsx from './tables-to-jsx';
10
11
  import tailwindTransformer from './tailwind';
11
12
  import validateMCPIntro from './validate-mcpintro';
12
13
  import variablesTransformer from './variables';
13
- export { compatabilityTransfomer, divTransformer, injectComponents, mdxToHast, mermaidTransformer, readmeComponentsTransformer, readmeToMdx, tablesToJsx, tailwindTransformer, handleMissingComponents, validateMCPIntro, variablesTransformer, };
14
+ export { compatabilityTransfomer, divTransformer, injectComponents, mdxToHast, mdxishTables, mermaidTransformer, readmeComponentsTransformer, readmeToMdx, tablesToJsx, tailwindTransformer, handleMissingComponents, validateMCPIntro, variablesTransformer, };
14
15
  export declare const defaultTransforms: {
15
16
  calloutTransformer: () => (tree: import("mdast").Root) => void;
16
17
  codeTabsTransformer: ({ copyButtons }?: {
17
18
  copyButtons?: boolean;
18
19
  }) => (tree: import("mdast").Node) => import("mdast").Node;
19
20
  embedTransformer: () => (tree: import("mdast").Node) => void;
20
- imageTransformer: () => (tree: import("mdast").Node) => import("mdast").Node;
21
+ imageTransformer: ({ isMdxish }?: {
22
+ isMdxish?: boolean;
23
+ }) => (tree: import("mdast").Node) => import("mdast").Node;
21
24
  gemojiTransformer: () => (tree: import("mdast").Root) => import("mdast").Root;
22
25
  };
26
+ export declare const mdxishTransformers: ((() => (tree: import("mdast").Root) => void) | (({ copyButtons }?: {
27
+ copyButtons?: boolean;
28
+ }) => (tree: import("mdast").Node) => import("mdast").Node) | (({ isMdxish }?: {
29
+ isMdxish?: boolean;
30
+ }) => (tree: import("mdast").Node) => import("mdast").Node))[];
23
31
  declare const _default: ((() => (tree: import("mdast").Root) => void) | (({ copyButtons }?: {
24
32
  copyButtons?: boolean;
25
- }) => (tree: import("mdast").Node) => import("mdast").Node) | (() => (tree: import("mdast").Node) => void) | (() => (tree: import("mdast").Root) => import("mdast").Root) | (() => (tree: import("mdast").Node) => import("mdast").Node))[];
33
+ }) => (tree: import("mdast").Node) => import("mdast").Node) | (() => (tree: import("mdast").Node) => void) | (() => (tree: import("mdast").Root) => import("mdast").Root) | (({ isMdxish }?: {
34
+ isMdxish?: boolean;
35
+ }) => (tree: import("mdast").Node) => import("mdast").Node))[];
26
36
  export default _default;
@@ -0,0 +1,11 @@
1
+ import type { JSXContext } from './preprocess-jsx-expressions';
2
+ import type { Root } from 'mdast';
3
+ import type { Plugin } from 'unified';
4
+ /**
5
+ * AST transformer to evaluate MDX expressions using the provided context.
6
+ * Replaces mdxFlowExpression and mdxTextExpression nodes with their evaluated values.
7
+ */
8
+ declare const evaluateExpressions: Plugin<[{
9
+ context?: JSXContext;
10
+ }], Root>;
11
+ export default evaluateExpressions;
@@ -0,0 +1,6 @@
1
+ import type { Parent } from 'mdast';
2
+ import type { MdxJsxAttribute } from 'mdast-util-mdx-jsx';
3
+ import type { Plugin } from 'unified';
4
+ export declare const parseAttributes: (raw: string) => MdxJsxAttribute[];
5
+ declare const mdxishComponentBlocks: Plugin<[], Parent>;
6
+ export default mdxishComponentBlocks;
@@ -0,0 +1,6 @@
1
+ import type { Transform } from 'mdast-util-from-markdown';
2
+ /**
3
+ * Transforms HTMLBlock MDX JSX to html-block nodes. Handles <HTMLBlock>{`...`}</HTMLBlock> syntax.
4
+ */
5
+ declare const mdxishHtmlBlocks: () => Transform;
6
+ export default mdxishHtmlBlocks;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Legacy magic block parser for RDMD compatibility.
3
+ * Parses `[block:TYPE]JSON[/block]` syntax and returns MDAST nodes.
4
+ * Taken from the v6 branch with some modifications to be more type safe
5
+ * and adapted with the mdxish flow.
6
+ */
7
+ import type { BlockHit } from '../../../lib/utils/extractMagicBlocks';
8
+ import type { Root as MdastRoot } from 'mdast';
9
+ import type { Plugin } from 'unified';
10
+ export interface ParseMagicBlockOptions {
11
+ alwaysThrow?: boolean;
12
+ compatibilityMode?: boolean;
13
+ safeMode?: boolean;
14
+ }
15
+ /**
16
+ * Unified plugin that restores magic blocks from placeholder tokens.
17
+ *
18
+ * During preprocessing, extractMagicBlocks replaces [block:TYPE]...[/block]
19
+ * with inline code tokens like `__MAGIC_BLOCK_0__`. This plugin finds those
20
+ * tokens in the parsed MDAST and replaces them with the parsed block content.
21
+ */
22
+ declare const magicBlockRestorer: Plugin<[{
23
+ blocks: BlockHit[];
24
+ }], MdastRoot>;
25
+ export default magicBlockRestorer;
@@ -0,0 +1,9 @@
1
+ import type { Transform } from 'mdast-util-from-markdown';
2
+ /**
3
+ * Converts JSX Table elements to markdown table nodes and re-parses markdown in cells.
4
+ *
5
+ * Since mdxish doesn't use remarkMdx, we manually parse cell contents through
6
+ * remarkParse and remarkGfm to convert markdown to MDAST nodes.
7
+ */
8
+ declare const mdxishTables: () => Transform;
9
+ export default mdxishTables;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Pre-processes JSX-like expressions before markdown parsing.
3
+ * Converts href={'value'} to href="value", evaluates {expressions}, etc.
4
+ */
5
+ export type JSXContext = Record<string, unknown>;
6
+ export declare function base64Decode(str: string): string;
7
+ export declare const HTML_BLOCK_CONTENT_START = "<!--RDMX_HTMLBLOCK:";
8
+ export declare const HTML_BLOCK_CONTENT_END = ":RDMX_HTMLBLOCK-->";
9
+ /**
10
+ * Preprocesses JSX-like expressions in markdown before parsing.
11
+ * Inline expressions are handled separately; attribute expressions are processed here.
12
+ *
13
+ * @param content
14
+ * @param context
15
+ * @returns Preprocessed content ready for markdown parsing
16
+ */
17
+ export declare function preprocessJSXExpressions(content: string, context?: JSXContext): string;
@@ -0,0 +1,9 @@
1
+ import type { Plugin } from 'unified';
2
+ /**
3
+ * A remark plugin that parses {user.<field>} patterns from text nodes
4
+ * without requiring remarkMdx. Creates Variable nodes for runtime resolution.
5
+ *
6
+ * Supports any user field: name, email, email_verified, exp, iat, etc.
7
+ */
8
+ declare const variablesTextTransformer: Plugin;
9
+ export default variablesTextTransformer;
@@ -67,6 +67,14 @@ export declare const isMDXElement: (node: Node) => node is MdxJsxFlowElement | M
67
67
  * @returns {boolean}
68
68
  */
69
69
  export declare const isMDXEsm: (node: Node) => node is MdxjsEsm;
70
+ /**
71
+ * Takes an HTML string and formats it for display in the editor. Removes leading/trailing newlines
72
+ * and unindents the HTML.
73
+ *
74
+ * @param {string} html - HTML content from template literal
75
+ * @returns {string} processed HTML
76
+ */
77
+ export declare function formatHtmlForMdxish(html: string): string;
70
78
  /**
71
79
  * Takes an HTML string and formats it for display in the editor. Removes leading/trailing newlines
72
80
  * and unindents the HTML.
@@ -0,0 +1,23 @@
1
+ /**
2
+ * React HTML element props word boundaries (e.g., "on", "data", "aria", "accept", "auto")
3
+ * Extracted from react-html-attributes package
4
+ */
5
+ export declare const REACT_HTML_PROP_BOUNDARIES: string[];
6
+ /**
7
+ * CSS style property word boundaries (e.g., "border", "margin", "padding", "flex", "align")
8
+ * Extracted from react-native-known-styling-properties package
9
+ */
10
+ export declare const CSS_STYLE_PROP_BOUNDARIES: string[];
11
+ /**
12
+ * Custom component prop word boundaries not in React HTML or CSS boundaries.
13
+ */
14
+ export declare const CUSTOM_PROP_BOUNDARIES: string[];
15
+ /**
16
+ * Tags that should be passed through and handled at runtime (not by the mdxish plugin)
17
+ */
18
+ export declare const RUNTIME_COMPONENT_TAGS: Set<string>;
19
+ /**
20
+ * Standard HTML tags that should never be treated as custom components.
21
+ * Uses the html-tags package, converted to a Set<string> for efficient lookups.
22
+ */
23
+ export declare const STANDARD_HTML_TAGS: Set<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": "11.7.7",
5
+ "version": "11.8.0",
6
6
  "main": "dist/main.node.js",
7
7
  "types": "dist/index.d.ts",
8
8
  "browser": "dist/main.js",
@@ -37,19 +37,26 @@
37
37
  "hast-util-from-html": "^2.0.1",
38
38
  "hast-util-sanitize": "^4.0.0",
39
39
  "hastscript": "^9.0.0",
40
+ "html-tags": "^5.1.0",
40
41
  "lodash.escape": "^4.0.1",
41
42
  "lodash.kebabcase": "^4.1.1",
42
43
  "mdast-util-find-and-replace": "^3.0.1",
44
+ "mdast-util-mdx-expression": "^2.0.1",
43
45
  "mdast-util-phrasing": "^4.1.0",
44
46
  "mdast-util-to-markdown": "^2.1.2",
47
+ "micromark-extension-mdx-expression": "^3.0.1",
45
48
  "path-browserify": "^1.0.1",
46
49
  "postcss": "^8.5.1",
47
50
  "postcss-prefix-selector": "^2.1.0",
48
51
  "process": "^0.11.10",
52
+ "react-html-attributes": "^1.4.6",
53
+ "react-native-known-styling-properties": "^1.3.0",
49
54
  "rehype-raw": "^7.0.0",
55
+ "rehype-react": "^6.2.1",
50
56
  "rehype-remark": "^10.0.0",
51
57
  "rehype-sanitize": "^6.0.0",
52
58
  "rehype-slug": "^6.0.0",
59
+ "rehype-stringify": "^10.0.1",
53
60
  "remark": "^15.0.1",
54
61
  "remark-frontmatter": "^5.0.0",
55
62
  "remark-gfm": "^4.0.0",
@@ -149,7 +156,7 @@
149
156
  },
150
157
  {
151
158
  "path": "dist/main.node.js",
152
- "maxSize": "750KB"
159
+ "maxSize": "780KB"
153
160
  }
154
161
  ]
155
162
  },