feat(v2): various markdown string parsing improvements/fixes (#4590)

* extract createExcerpt code in separate file + add bad test

* almost working markdown parsing refactor

* complete parseMarkdownString refactor

* fix tests

* fix blog test issue

* fix docusaurus utils imports
This commit is contained in:
Sébastien Lorber 2021-04-09 17:09:33 +02:00 committed by GitHub
parent b743edf5fb
commit 4efe6824b3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 895 additions and 563 deletions

View file

@ -0,0 +1,33 @@
/**
* 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 {Joi} from '@docusaurus/utils-validation';
// TODO complete this frontmatter + add unit tests
type DocFrontMatter = {
id?: string;
title?: string;
description?: string;
slug?: string;
sidebar_label?: string;
custom_edit_url?: string;
};
const DocFrontMatterSchema = Joi.object<DocFrontMatter>({
id: Joi.string(),
title: Joi.string(),
description: Joi.string(),
slug: Joi.string(),
sidebar_label: Joi.string(),
custom_edit_url: Joi.string().allow(null),
}).unknown();
export function assertDocFrontMatter(
frontMatter: Record<string, unknown>,
): asserts frontMatter is DocFrontMatter {
Joi.attempt(frontMatter, DocFrontMatterSchema);
}