/
githubmirror
/
docusaurus
Обзор
Документация
Войти
/
githubmirror
/
docusaurus
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/docusaurus-mdx-loader/src/format.ts
50 строк
1 KB
Sébastien Lorber
feat(mdx): add siteConfig.markdown.format to configure the default content parser (MDX / CommonMark) (#9097)
23 июн 2023, 19:15
Не верифицирован
23 июн 2023, 19:15
cc6d969
Код
Авторство
О чём код?
/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ import path from 'path'; import type {MDXFrontMatter} from './frontMatter'; import type {Format, FormatInput} from './index'; // Copied from https://mdxjs.com/packages/mdx/#optionsmdextensions // Although we are likely to only use .md / .mdx anyway... const mdFormatExtensions = [ '.md', '.markdown', '.mdown', '.mkdn', '.mkd', '.mdwn', '.mkdown', '.ron', ]; function getExtensionFormat(filepath: string): Format { const isMDFormat = mdFormatExtensions.includes(path.extname(filepath)); // Bias toward mdx if unknown extension return isMDFormat ? 'md' : 'mdx'; } export function getFormat({ filePath, frontMatterFormat, markdownConfigFormat, }: { filePath: string; frontMatterFormat: MDXFrontMatter['format']; markdownConfigFormat: FormatInput; }): Format { if (frontMatterFormat) { if (frontMatterFormat !== 'detect') { return frontMatterFormat; } return getExtensionFormat(filePath); } if (markdownConfigFormat !== 'detect') { return markdownConfigFormat; } return getExtensionFormat(filePath); }