mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-13 09:07:29 +02:00
feat(v2): add beforeDefaultRemarkPlugins/beforeDefaultRehypePlugins options to all md content plugins (#3467)
* fix(plugin-content-docs): add beforeDefaultRemarkPlugins + beforeDefaultRehypePlugins options * fix(plugin-content-blog): add beforeDefaultRemarkPlugins + beforeDefaultRehypePlugins options * fix(plugin-content-pages): add beforeDefaultRemarkPlugins + beforeDefaultRehypePlugins options * feat(website-docs): overriding remark-rehype plugins * fix(plugin-content): update beforeDefaultRehypePlugins/beforeDefaultRemarkPlugins types * fix(plugin-content-docs): fix tests
This commit is contained in:
parent
f343450e85
commit
d3a01458a3
10 changed files with 57 additions and 3 deletions
|
@ -30,6 +30,8 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
docItemComponent: '@theme/DocItem',
|
||||
remarkPlugins: [markdownPluginsObjectStub],
|
||||
rehypePlugins: [markdownPluginsFunctionStub],
|
||||
beforeDefaultRehypePlugins: [],
|
||||
beforeDefaultRemarkPlugins: [],
|
||||
showLastUpdateTime: true,
|
||||
showLastUpdateAuthor: true,
|
||||
admonitions: {},
|
||||
|
@ -55,6 +57,8 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
test('should accept correctly defined remark and rehype plugin options', async () => {
|
||||
const userOptions = {
|
||||
...DEFAULT_OPTIONS,
|
||||
beforeDefaultRemarkPlugins: [],
|
||||
beforeDefaultRehypePlugins: [markdownPluginsFunctionStub],
|
||||
remarkPlugins: [[markdownPluginsFunctionStub, {option1: '42'}]],
|
||||
rehypePlugins: [
|
||||
markdownPluginsObjectStub,
|
||||
|
|
|
@ -295,7 +295,12 @@ export default function pluginContentDocs(
|
|||
|
||||
configureWebpack(_config, isServer, utils) {
|
||||
const {getBabelLoader, getCacheLoader} = utils;
|
||||
const {rehypePlugins, remarkPlugins} = options;
|
||||
const {
|
||||
rehypePlugins,
|
||||
remarkPlugins,
|
||||
beforeDefaultRehypePlugins,
|
||||
beforeDefaultRemarkPlugins,
|
||||
} = options;
|
||||
|
||||
const docsMarkdownOptions: DocsMarkdownOption = {
|
||||
siteDir,
|
||||
|
@ -323,6 +328,8 @@ export default function pluginContentDocs(
|
|||
options: {
|
||||
remarkPlugins,
|
||||
rehypePlugins,
|
||||
beforeDefaultRehypePlugins,
|
||||
beforeDefaultRemarkPlugins,
|
||||
staticDir: path.join(siteDir, STATIC_DIR_NAME),
|
||||
metadataPath: (mdxPath: string) => {
|
||||
// Note that metadataPath must be the same/in-sync as
|
||||
|
|
|
@ -27,6 +27,8 @@ export const DEFAULT_OPTIONS: Omit<PluginOptions, 'id'> = {
|
|||
docItemComponent: '@theme/DocItem',
|
||||
remarkPlugins: [],
|
||||
rehypePlugins: [],
|
||||
beforeDefaultRemarkPlugins: [],
|
||||
beforeDefaultRehypePlugins: [],
|
||||
showLastUpdateTime: false,
|
||||
showLastUpdateAuthor: false,
|
||||
admonitions: {},
|
||||
|
@ -60,6 +62,12 @@ export const OptionsSchema = Joi.object({
|
|||
docItemComponent: Joi.string().default(DEFAULT_OPTIONS.docItemComponent),
|
||||
remarkPlugins: RemarkPluginsSchema.default(DEFAULT_OPTIONS.remarkPlugins),
|
||||
rehypePlugins: RehypePluginsSchema.default(DEFAULT_OPTIONS.rehypePlugins),
|
||||
beforeDefaultRemarkPlugins: RemarkPluginsSchema.default(
|
||||
DEFAULT_OPTIONS.beforeDefaultRemarkPlugins,
|
||||
),
|
||||
beforeDefaultRehypePlugins: RehypePluginsSchema.default(
|
||||
DEFAULT_OPTIONS.beforeDefaultRehypePlugins,
|
||||
),
|
||||
admonitions: AdmonitionsSchema.default(DEFAULT_OPTIONS.admonitions),
|
||||
showLastUpdateTime: Joi.bool().default(DEFAULT_OPTIONS.showLastUpdateTime),
|
||||
showLastUpdateAuthor: Joi.bool().default(
|
||||
|
|
|
@ -59,6 +59,8 @@ export type PluginOptions = MetadataOptions &
|
|||
docItemComponent: string;
|
||||
remarkPlugins: ([Function, object] | Function)[];
|
||||
rehypePlugins: string[];
|
||||
beforeDefaultRemarkPlugins: ([Function, object] | Function)[];
|
||||
beforeDefaultRehypePlugins: ([Function, object] | Function)[];
|
||||
admonitions: any;
|
||||
disableVersioning: boolean;
|
||||
excludeNextVersionDocs?: boolean;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue