mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-21 13:06:58 +02:00
feat(v2): docs, make numberPrefixParser configurable, better defaults, minor breaking-changes (#4655)
* make number prefix parsing logic configurable * Make numberPrefixParser configurable + rename frontmatter + avoid parsing date/version patterns by default * add more tests * more test cases
This commit is contained in:
parent
d0d29f43cc
commit
c04e613ffe
14 changed files with 325 additions and 82 deletions
packages/docusaurus-plugin-content-docs/src/__tests__
|
@ -8,6 +8,10 @@
|
|||
import {OptionsSchema, DEFAULT_OPTIONS} from '../options';
|
||||
import {normalizePluginOptions} from '@docusaurus/utils-validation';
|
||||
import {DefaultSidebarItemsGenerator} from '../sidebarItemsGenerator';
|
||||
import {
|
||||
DefaultNumberPrefixParser,
|
||||
DisabledNumberPrefixParser,
|
||||
} from '../numberPrefix';
|
||||
|
||||
// the type of remark/rehype plugins is function
|
||||
const markdownPluginsFunctionStub = () => {};
|
||||
|
@ -28,6 +32,7 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
include: ['**/*.{md,mdx}'], // Extensions to include.
|
||||
sidebarPath: 'my-sidebar', // Path to sidebar configuration for showing a list of markdown pages.
|
||||
sidebarItemsGenerator: DefaultSidebarItemsGenerator,
|
||||
numberPrefixParser: DefaultNumberPrefixParser,
|
||||
docLayoutComponent: '@theme/DocPage',
|
||||
docItemComponent: '@theme/DocItem',
|
||||
remarkPlugins: [markdownPluginsObjectStub],
|
||||
|
@ -84,6 +89,46 @@ describe('normalizeDocsPluginOptions', () => {
|
|||
expect(error).toBe(undefined);
|
||||
});
|
||||
|
||||
test('should accept numberPrefixParser function', () => {
|
||||
function customNumberPrefixParser() {}
|
||||
expect(
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
...DEFAULT_OPTIONS,
|
||||
numberPrefixParser: customNumberPrefixParser,
|
||||
}),
|
||||
).toEqual({
|
||||
...DEFAULT_OPTIONS,
|
||||
id: 'default',
|
||||
numberPrefixParser: customNumberPrefixParser,
|
||||
});
|
||||
});
|
||||
|
||||
test('should accept numberPrefixParser false', () => {
|
||||
expect(
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
...DEFAULT_OPTIONS,
|
||||
numberPrefixParser: false,
|
||||
}),
|
||||
).toEqual({
|
||||
...DEFAULT_OPTIONS,
|
||||
id: 'default',
|
||||
numberPrefixParser: DisabledNumberPrefixParser,
|
||||
});
|
||||
});
|
||||
|
||||
test('should accept numberPrefixParser true', () => {
|
||||
expect(
|
||||
normalizePluginOptions(OptionsSchema, {
|
||||
...DEFAULT_OPTIONS,
|
||||
numberPrefixParser: true,
|
||||
}),
|
||||
).toEqual({
|
||||
...DEFAULT_OPTIONS,
|
||||
id: 'default',
|
||||
numberPrefixParser: DefaultNumberPrefixParser,
|
||||
});
|
||||
});
|
||||
|
||||
test('should reject admonitions true', async () => {
|
||||
const admonitionsTrue = {
|
||||
...DEFAULT_OPTIONS,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue