diff --git a/core/README.md b/core/README.md index 931b7f8..6d7f3fd 100644 --- a/core/README.md +++ b/core/README.md @@ -99,6 +99,8 @@ export type Options = { * Add babel plugins. */ babelPlugins?: PluginItem[]; + /**Do you want to parse the title*/ + isHeading?: boolean } ``` @@ -112,6 +114,7 @@ import mdObj from 'markdown-react-code-preview-loader/README.md'; mdObj.source // => `README.md` raw string text mdObj.components // => The component index object, the React component converted from the markdown indexed example. (need to configure meta) mdObj.data // => The component source code index object, the sample source code indexed from markdown. (need to configure meta) +mdObj.headings // => This is the parsed header data ``` ```js @@ -133,7 +136,8 @@ mdObj.data // => The component source code index object, the sample source } }, components: { 77: ƒ, demo12: ƒ }, - source: "# Alert 确认对话框...." + source: "# Alert 确认对话框....", + headings:[{depth:1,value:"标题", ...},...] } ``` @@ -155,6 +159,7 @@ export type CodeBlockData = { source: string; components: Record; data: Record; + headings?: HeadingItem[] }; ``` diff --git a/core/src/index.ts b/core/src/index.ts index 5754ea9..0502889 100644 --- a/core/src/index.ts +++ b/core/src/index.ts @@ -1,7 +1,7 @@ import React from 'react'; import { PluginItem } from '@babel/core'; import { Options as RIOptions } from 'babel-plugin-transform-remove-imports'; -import { getProcessor, getCodeBlock, getHeadings } from './utils'; +import { getProcessor, getCodeBlock, getHeadings, HeadingItem } from './utils'; import { LoaderDefinitionFunction } from 'webpack'; export * from './utils'; @@ -22,6 +22,7 @@ export type CodeBlockData = { source: string; components: Record; data: Record; + headings?: HeadingItem[]; }; export const FUNNAME_PREFIX = '__BaseCode__'; @@ -40,6 +41,8 @@ export type Options = { * Add babel plugins. */ babelPlugins?: PluginItem[]; + /**是否进行标题解析*/ + isHeading?: boolean; }; const codePreviewLoader: LoaderDefinitionFunction = function (source) { @@ -57,7 +60,7 @@ const codePreviewLoader: LoaderDefinitionFunction = function (source) { this.emitError(error); } - const headings = getHeadings(child); + const headings = options.isHeading ? getHeadings(child) : []; return `\nexport default { components: { ${components} },