mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-13 23:07:58 +02:00
feat(core): Add siteConfig.markdown.hooks
, deprecate siteConfig.onBrokenMarkdownLinks
(#11283)
This commit is contained in:
parent
ef71ddf937
commit
96c38d5fdd
35 changed files with 1580 additions and 381 deletions
|
@ -275,6 +275,14 @@ By default, it prints a warning, to let you know about your broken anchors.
|
|||
|
||||
### `onBrokenMarkdownLinks` {#onBrokenMarkdownLinks}
|
||||
|
||||
:::warning Deprecated
|
||||
|
||||
Deprecated in Docusaurus v3.9, and will be removed in Docusaurus v4.
|
||||
|
||||
Replaced by [`siteConfig.markdown.hooks.onBrokenMarkdownLinks`](#hooks.onBrokenMarkdownLinks)
|
||||
|
||||
:::
|
||||
|
||||
- Type: `'ignore' | 'log' | 'warn' | 'throw'`
|
||||
|
||||
The behavior of Docusaurus when it detects any broken Markdown link.
|
||||
|
@ -511,6 +519,25 @@ type MarkdownAnchorsConfig = {
|
|||
maintainCase: boolean;
|
||||
};
|
||||
|
||||
type OnBrokenMarkdownLinksFunction = (params: {
|
||||
sourceFilePath: string; // MD/MDX source file relative to cwd
|
||||
url: string; // Link url
|
||||
node: Link | Definition; // mdast Node
|
||||
}) => void | string;
|
||||
|
||||
type OnBrokenMarkdownImagesFunction = (params: {
|
||||
sourceFilePath: string; // MD/MDX source file relative to cwd
|
||||
url: string; // Image url
|
||||
node: Image; // mdast node
|
||||
}) => void | string;
|
||||
|
||||
type ReportingSeverity = 'ignore' | 'log' | 'warn' | 'throw';
|
||||
|
||||
type MarkdownHooks = {
|
||||
onBrokenMarkdownLinks: ReportingSeverity | OnBrokenMarkdownLinksFunction;
|
||||
onBrokenMarkdownImages: ReportingSeverity | OnBrokenMarkdownImagesFunction;
|
||||
};
|
||||
|
||||
type MarkdownConfig = {
|
||||
format: 'mdx' | 'md' | 'detect';
|
||||
mermaid: boolean;
|
||||
|
@ -519,6 +546,7 @@ type MarkdownConfig = {
|
|||
mdx1Compat: MDX1CompatOptions;
|
||||
remarkRehypeOptions: object; // see https://github.com/remarkjs/remark-rehype#options
|
||||
anchors: MarkdownAnchorsConfig;
|
||||
hooks: MarkdownHooks;
|
||||
};
|
||||
```
|
||||
|
||||
|
@ -546,6 +574,10 @@ export default {
|
|||
anchors: {
|
||||
maintainCase: true,
|
||||
},
|
||||
hooks: {
|
||||
onBrokenMarkdownLinks: 'warn',
|
||||
onBrokenMarkdownImages: 'throw',
|
||||
},
|
||||
},
|
||||
};
|
||||
```
|
||||
|
@ -563,6 +595,9 @@ export default {
|
|||
| `mdx1Compat` | `MDX1CompatOptions` | `{comments: true, admonitions: true, headingIds: true}` | Compatibility options to make it easier to upgrade to Docusaurus v3+. |
|
||||
| `anchors` | `MarkdownAnchorsConfig` | `{maintainCase: false}` | Options to control the behavior of anchors generated from Markdown headings |
|
||||
| `remarkRehypeOptions` | `object` | `undefined` | Makes it possible to pass custom [`remark-rehype` options](https://github.com/remarkjs/remark-rehype#options). |
|
||||
| `hooks` | `MarkdownHooks` | `object` | Make it possible to customize the MDX loader behavior with callbacks or built-in options. |
|
||||
| `hooks.onBrokenMarkdownLinks` | `ReportingSeverity \| OnBrokenMarkdownLinksFunction` | `'warn'` | Hook to customize the behavior when encountering a broken Markdown link URL. With the callback function, you can return a new link URL, or alter the link [mdast node](https://github.com/syntax-tree/mdast). |
|
||||
| `hooks.onBrokenMarkdownLinks` | `ReportingSeverity \| OnBrokenMarkdownImagesFunction` | `'throw'` | Hook to customize the behavior when encountering a broken Markdown image URL. With the callback function, you can return a new image URL, or alter the image [mdast node](https://github.com/syntax-tree/mdast). |
|
||||
|
||||
```mdx-code-block
|
||||
</APITable>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue