mirror of
https://github.com/facebook/docusaurus.git
synced 2025-06-02 10:52:35 +02:00
refactor: replace non-prop interface with type; allow plugin lifecycles to have sync type (#7080)
* refactor: replace non-prop interface with type; allow plugin lifecycles to have sync type * fix
This commit is contained in:
parent
ce2b631455
commit
24c205a835
38 changed files with 145 additions and 138 deletions
4
packages/docusaurus-mdx-loader/src/deps.d.ts
vendored
4
packages/docusaurus-mdx-loader/src/deps.d.ts
vendored
|
@ -10,13 +10,13 @@ declare module '@mdx-js/mdx' {
|
|||
import type {Processor} from 'unified';
|
||||
import type {RemarkOrRehypePlugin} from '@docusaurus/mdx-loader';
|
||||
|
||||
export interface Options {
|
||||
export type Options = {
|
||||
filepath?: string;
|
||||
skipExport?: boolean;
|
||||
wrapExport?: string;
|
||||
remarkPlugins?: RemarkOrRehypePlugin[];
|
||||
rehypePlugins?: RemarkOrRehypePlugin[];
|
||||
}
|
||||
};
|
||||
|
||||
export function sync(content: string, options?: Options): string;
|
||||
export function createMdxAstCompiler(options?: Options): Processor;
|
||||
|
|
|
@ -182,9 +182,9 @@ export default async function mdxLoader(
|
|||
// Partial are not expected to have associated metadata files or front matter
|
||||
const isMDXPartial = options.isMDXPartial?.(filePath);
|
||||
if (isMDXPartial && hasFrontMatter) {
|
||||
const errorMessage = `Docusaurus MDX partial files should not contain FrontMatter.
|
||||
const errorMessage = `Docusaurus MDX partial files should not contain front matter.
|
||||
Those partial files use the _ prefix as a convention by default, but this is configurable.
|
||||
File at ${filePath} contains FrontMatter that will be ignored:
|
||||
File at ${filePath} contains front matter that will be ignored:
|
||||
${JSON.stringify(frontMatter, null, 2)}`;
|
||||
|
||||
if (!options.isMDXPartialFrontMatterWarningDisabled) {
|
||||
|
|
|
@ -9,9 +9,8 @@
|
|||
|
||||
import {parseMarkdownHeadingId, createSlugger} from '@docusaurus/utils';
|
||||
import visit from 'unist-util-visit';
|
||||
import toString from 'mdast-util-to-string';
|
||||
import mdastToString from 'mdast-util-to-string';
|
||||
import type {Transformer} from 'unified';
|
||||
import type {Parent} from 'unist';
|
||||
import type {Heading, Text} from 'mdast';
|
||||
|
||||
export default function plugin(): Transformer {
|
||||
|
@ -30,10 +29,8 @@ export default function plugin(): Transformer {
|
|||
const headingTextNodes = headingNode.children.filter(
|
||||
({type}) => !['html', 'jsx'].includes(type),
|
||||
);
|
||||
const heading = toString(
|
||||
headingTextNodes.length > 0
|
||||
? ({children: headingTextNodes} as Parent)
|
||||
: headingNode,
|
||||
const heading = mdastToString(
|
||||
headingTextNodes.length > 0 ? headingTextNodes : headingNode,
|
||||
);
|
||||
|
||||
// Support explicit heading IDs
|
||||
|
|
|
@ -27,9 +27,9 @@ const isImport = (child: Node): child is Literal => child.type === 'import';
|
|||
const hasImports = (index: number) => index > -1;
|
||||
const isExport = (child: Node): child is Literal => child.type === 'export';
|
||||
|
||||
interface PluginOptions {
|
||||
type PluginOptions = {
|
||||
name?: string;
|
||||
}
|
||||
};
|
||||
|
||||
const isTarget = (child: Literal, name: string) => {
|
||||
let found = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue