@readme/markdown 11.7.6 → 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.
- package/components/CodeTabs/index.tsx +6 -1
- package/components/HTMLBlock/index.tsx +17 -6
- package/dist/components/HTMLBlock/index.d.ts +4 -3
- package/dist/index.d.ts +1 -1
- package/dist/lib/ast-processor.d.ts +2 -0
- package/dist/lib/index.d.ts +5 -0
- package/dist/lib/mdxish.d.ts +16 -0
- package/dist/lib/mix.d.ts +4 -0
- package/dist/lib/renderMdxish.d.ts +14 -0
- package/dist/lib/utils/extractMagicBlocks.d.ts +1 -2
- package/dist/lib/utils/mdxish/mdxish-get-component-name.d.ts +11 -0
- package/dist/lib/utils/mdxish/mdxish-load-components.d.ts +7 -0
- package/dist/lib/utils/mdxish/mdxish-render-utils.d.ts +25 -0
- package/dist/main.js +11190 -5041
- package/dist/main.node.js +11914 -5765
- package/dist/main.node.js.map +1 -1
- package/dist/processor/plugin/mdxish-components.d.ts +19 -0
- package/dist/processor/plugin/mdxish-handlers.d.ts +2 -0
- package/dist/processor/plugin/toc.d.ts +7 -1
- package/dist/processor/transform/images.d.ts +3 -1
- package/dist/processor/transform/index.d.ts +13 -3
- package/dist/processor/transform/mdxish/evaluate-expressions.d.ts +11 -0
- package/dist/processor/transform/mdxish/mdxish-component-blocks.d.ts +6 -0
- package/dist/processor/transform/mdxish/mdxish-html-blocks.d.ts +6 -0
- package/dist/processor/transform/mdxish/mdxish-magic-blocks.d.ts +25 -0
- package/dist/processor/transform/mdxish/mdxish-tables.d.ts +9 -0
- package/dist/processor/transform/mdxish/preprocess-jsx-expressions.d.ts +17 -0
- package/dist/processor/transform/mdxish/variables-text.d.ts +9 -0
- package/dist/processor/utils.d.ts +8 -0
- package/dist/utils/common-html-words.d.ts +23 -0
- package/package.json +9 -2
|
@@ -56,7 +56,12 @@ const CodeTabs = (props: Props) => {
|
|
|
56
56
|
<div className={`CodeTabs CodeTabs_initial theme-${theme}`}>
|
|
57
57
|
<div className="CodeTabs-toolbar">
|
|
58
58
|
{(Array.isArray(children) ? children : [children]).map((pre, i) => {
|
|
59
|
-
|
|
59
|
+
// the first or only child should be our Code component
|
|
60
|
+
const codeComponent = Array.isArray(pre.props?.children)
|
|
61
|
+
? pre.props.children[0]
|
|
62
|
+
: pre.props?.children;
|
|
63
|
+
const lang = codeComponent?.props?.lang;
|
|
64
|
+
const meta = codeComponent?.props?.meta;
|
|
60
65
|
|
|
61
66
|
/* istanbul ignore next */
|
|
62
67
|
return (
|
|
@@ -14,20 +14,31 @@ const extractScripts = (html: string = ''): [string, () => void] => {
|
|
|
14
14
|
};
|
|
15
15
|
|
|
16
16
|
interface Props {
|
|
17
|
-
children
|
|
17
|
+
children?: React.ReactElement | string;
|
|
18
|
+
html?: string;
|
|
18
19
|
runScripts?: boolean | string;
|
|
19
|
-
safeMode?: boolean;
|
|
20
|
+
safeMode?: boolean | string;
|
|
20
21
|
}
|
|
21
22
|
|
|
22
|
-
const HTMLBlock = ({ children = '', runScripts, safeMode = false }: Props) => {
|
|
23
|
-
|
|
24
|
-
|
|
23
|
+
const HTMLBlock = ({ children = '', html: htmlProp, runScripts, safeMode: safeModeRaw = false }: Props) => {
|
|
24
|
+
// Determine HTML source: MDXish uses html prop (from HAST), MDX uses children
|
|
25
|
+
let html: string = '';
|
|
26
|
+
if (htmlProp !== undefined) {
|
|
27
|
+
html = htmlProp;
|
|
28
|
+
} else {
|
|
29
|
+
if (typeof children !== 'string') {
|
|
30
|
+
throw new TypeError('HTMLBlock: children must be a string');
|
|
31
|
+
}
|
|
32
|
+
html = children;
|
|
25
33
|
}
|
|
26
34
|
|
|
27
|
-
const html = children;
|
|
28
35
|
// eslint-disable-next-line no-param-reassign
|
|
29
36
|
runScripts = typeof runScripts !== 'boolean' ? runScripts === 'true' : runScripts;
|
|
30
37
|
|
|
38
|
+
// In MDX mode, safeMode is passed in as a boolean from JSX parsing
|
|
39
|
+
// In MDXish mode, safeMode comes in as a string from HAST props
|
|
40
|
+
const safeMode = typeof safeModeRaw !== 'boolean' ? safeModeRaw === 'true' : safeModeRaw;
|
|
41
|
+
|
|
31
42
|
const [cleanedHtml, exec] = extractScripts(html);
|
|
32
43
|
|
|
33
44
|
useEffect(() => {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
interface Props {
|
|
3
|
-
children
|
|
3
|
+
children?: React.ReactElement | string;
|
|
4
|
+
html?: string;
|
|
4
5
|
runScripts?: boolean | string;
|
|
5
|
-
safeMode?: boolean;
|
|
6
|
+
safeMode?: boolean | string;
|
|
6
7
|
}
|
|
7
|
-
declare const HTMLBlock: ({ children, runScripts, safeMode }: Props) => React.JSX.Element;
|
|
8
|
+
declare const HTMLBlock: ({ children, html: htmlProp, runScripts, safeMode: safeModeRaw }: Props) => React.JSX.Element;
|
|
8
9
|
export default HTMLBlock;
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare const utils: {
|
|
|
6
6
|
getHref: typeof getHref;
|
|
7
7
|
calloutIcons: {};
|
|
8
8
|
};
|
|
9
|
-
export { compile, exports, hast, run, mdast, mdastV6, mdx, migrate, plain, remarkPlugins, stripComments, tags } from './lib';
|
|
9
|
+
export { compile, exports, hast, run, mdast, mdastV6, mdx, mdxish, migrate, mix, plain, renderMdxish, remarkPlugins, stripComments, tags, } from './lib';
|
|
10
10
|
export { default as Owlmoji } from './lib/owlmoji';
|
|
11
11
|
export { Components, utils };
|
|
12
12
|
export { tailwindCompiler } from './utils/tailwind-compiler';
|
|
@@ -9,6 +9,8 @@ export interface MdastOpts {
|
|
|
9
9
|
}
|
|
10
10
|
export declare const remarkPlugins: ((() => (tree: import("mdast").Root) => void) | (({ copyButtons }?: {
|
|
11
11
|
copyButtons?: boolean;
|
|
12
|
+
}) => (tree: import("mdast").Node) => import("mdast").Node) | (({ isMdxish }?: {
|
|
13
|
+
isMdxish?: boolean;
|
|
12
14
|
}) => (tree: import("mdast").Node) => import("mdast").Node) | typeof remarkFrontmatter | typeof remarkGfm)[];
|
|
13
15
|
export declare const rehypePlugins: (typeof rehypeSlug | (() => (tree: import("unist").Node) => import("unist").Node))[];
|
|
14
16
|
declare const astProcessor: (opts?: MdastOpts) => import("unified").Processor<import("mdast").Root, import("mdast").Root, import("mdast").Root, import("mdast").Root, string>;
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -6,8 +6,13 @@ export { default as hast } from './hast';
|
|
|
6
6
|
export { default as mdast } from './mdast';
|
|
7
7
|
export { default as mdastV6 } from './mdastV6';
|
|
8
8
|
export { default as mdx } from './mdx';
|
|
9
|
+
export { default as mix } from './mix';
|
|
10
|
+
export { default as mdxish } from './mdxish';
|
|
11
|
+
export type { MdxishOpts } from './mdxish';
|
|
9
12
|
export { default as migrate } from './migrate';
|
|
10
13
|
export { default as plain } from './plain';
|
|
14
|
+
export { default as renderMdxish } from './renderMdxish';
|
|
15
|
+
export type { RenderMdxishOpts } from './renderMdxish';
|
|
11
16
|
export { default as run } from './run';
|
|
12
17
|
export { default as tags } from './tags';
|
|
13
18
|
export { default as stripComments } from './stripComments';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { CustomComponents } from '../types';
|
|
2
|
+
import type { Root } from 'hast';
|
|
3
|
+
import { type JSXContext } from '../processor/transform/mdxish/preprocess-jsx-expressions';
|
|
4
|
+
export interface MdxishOpts {
|
|
5
|
+
components?: CustomComponents;
|
|
6
|
+
jsxContext?: JSXContext;
|
|
7
|
+
useTailwind?: boolean;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Process markdown content with MDX syntax support.
|
|
11
|
+
* Detects and renders custom component tags from the components hash.
|
|
12
|
+
*
|
|
13
|
+
* @see {@link https://github.com/readmeio/rmdx/blob/main/docs/mdxish-flow.md}
|
|
14
|
+
*/
|
|
15
|
+
export declare function mdxish(mdContent: string, opts?: MdxishOpts): Root;
|
|
16
|
+
export default mdxish;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { RMDXModule } from '../types';
|
|
2
|
+
import type { Root } from 'hast';
|
|
3
|
+
import { type RenderOpts } from './utils/mdxish/mdxish-render-utils';
|
|
4
|
+
export type { RenderOpts as RenderMdxishOpts };
|
|
5
|
+
/**
|
|
6
|
+
* Converts a HAST tree to a React component.
|
|
7
|
+
* @param tree - The HAST tree to convert
|
|
8
|
+
* @param opts - The options for the render
|
|
9
|
+
* @returns The React component
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://github.com/readmeio/rmdx/blob/main/docs/mdxish-flow.md}
|
|
12
|
+
*/
|
|
13
|
+
declare const renderMdxish: (tree: Root, opts?: RenderOpts) => RMDXModule;
|
|
14
|
+
export default renderMdxish;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
interface BlockHit {
|
|
1
|
+
export interface BlockHit {
|
|
2
2
|
raw: string;
|
|
3
3
|
token: string;
|
|
4
4
|
}
|
|
@@ -14,4 +14,3 @@ export declare function extractMagicBlocks(markdown: string): {
|
|
|
14
14
|
* Restore extracted magic blocks back into a markdown string.
|
|
15
15
|
*/
|
|
16
16
|
export declare function restoreMagicBlocks(replaced: string, blocks: BlockHit[]): string;
|
|
17
|
-
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CustomComponents } from '../../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Find a component in the components hash using case-insensitive matching.
|
|
4
|
+
* Returns the actual key from the map, or null if not found.
|
|
5
|
+
*
|
|
6
|
+
* Matching priority:
|
|
7
|
+
* 1. Exact match
|
|
8
|
+
* 2. PascalCase version
|
|
9
|
+
* 3. Case-insensitive match
|
|
10
|
+
*/
|
|
11
|
+
export declare function getComponentName(componentName: string, components: CustomComponents): string | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CustomComponents } from '../../../types';
|
|
2
|
+
/**
|
|
3
|
+
* Load components from the components directory and wrap them in RMDXModule format
|
|
4
|
+
* Similar to prototype.js getAvailableComponents, but for React components instead of MDX files
|
|
5
|
+
* This allows mix to use React components directly without MDX compilation
|
|
6
|
+
*/
|
|
7
|
+
export declare function loadComponents(): CustomComponents;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { GlossaryTerm } from '../../../contexts/GlossaryTerms';
|
|
2
|
+
import type { CustomComponents, IndexableElements, RMDXModule, TocList, Variables } from '../../../types';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
export interface RenderOpts {
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
components?: CustomComponents;
|
|
7
|
+
copyButtons?: boolean;
|
|
8
|
+
imports?: Record<string, unknown>;
|
|
9
|
+
terms?: GlossaryTerm[];
|
|
10
|
+
theme?: 'dark' | 'light';
|
|
11
|
+
useTailwind?: boolean;
|
|
12
|
+
variables?: Variables;
|
|
13
|
+
}
|
|
14
|
+
/** Flatten CustomComponents into a component map for rehype-react */
|
|
15
|
+
export declare function exportComponentsForRehype(components: CustomComponents): Record<string, React.ComponentType>;
|
|
16
|
+
/** Create a rehype-react processor */
|
|
17
|
+
export declare function createRehypeReactProcessor(components: Record<string, React.ComponentType>): import("unified").Processor<undefined, undefined, undefined, undefined, undefined>;
|
|
18
|
+
/** Create a TOC React component from headings */
|
|
19
|
+
export declare function createTocComponent(tocHast: TocList): React.FC<{
|
|
20
|
+
heading?: string;
|
|
21
|
+
}>;
|
|
22
|
+
/** Create the default wrapper component with contexts */
|
|
23
|
+
export declare function createDefaultComponent(content: React.ReactNode, opts: Pick<RenderOpts, 'baseUrl' | 'copyButtons' | 'terms' | 'theme' | 'variables'>): React.FC;
|
|
24
|
+
/** Build the RMDXModule result object */
|
|
25
|
+
export declare function buildRMDXModule(content: React.ReactNode, headings: IndexableElements[], tocHast: TocList | null, opts: Pick<RenderOpts, 'baseUrl' | 'copyButtons' | 'terms' | 'theme' | 'variables'>): RMDXModule;
|