feat(api-history): `isHtml(node)` type guard
https://github.com/electron/website/pull/594#discussion_r1678184944
This commit is contained in:
Родитель
51ab3045c0
Коммит
9481b1caa5
|
@ -9,6 +9,7 @@ import { readFile, writeFile } from 'fs/promises';
|
|||
import { fromHtml } from 'hast-util-from-html';
|
||||
import logger from '@docusaurus/logger';
|
||||
import { parse as parseYaml } from 'yaml';
|
||||
import { isHtml } from '@site/src/util/mdx-utils';
|
||||
|
||||
const apiHistoryRegex = /<!--[\s\S]*?(```[\s\S]*?```)[\s\S]*?-->/;
|
||||
|
||||
|
@ -48,12 +49,13 @@ function findPossibleApiHistoryBlocks(tree: Root) {
|
|||
visit(
|
||||
tree,
|
||||
(node: Node) =>
|
||||
node.type === 'html' &&
|
||||
isHtml(node) &&
|
||||
(node as LiteralString).value.includes('```') &&
|
||||
(node as LiteralString).value.toLowerCase().includes('yaml') &&
|
||||
(node as LiteralString).value.toLowerCase().includes('history'),
|
||||
(node) => {
|
||||
codeBlocks.push(node as Html);
|
||||
if (!isHtml(node)) return; // Should never happen, but TypeScript needs this check
|
||||
codeBlocks.push(node);
|
||||
}
|
||||
);
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
Link,
|
||||
Definition,
|
||||
Code,
|
||||
Html,
|
||||
} from 'mdast';
|
||||
import { MdxjsEsm } from 'mdast-util-mdxjs-esm';
|
||||
import { Node } from 'unist';
|
||||
|
@ -48,6 +49,10 @@ export function isText(node: PhrasingContent): node is Text {
|
|||
return node.type === 'text';
|
||||
}
|
||||
|
||||
export function isHtml(node: Node): node is Html {
|
||||
return node.type === 'html';
|
||||
}
|
||||
|
||||
/**
|
||||
* Imports a component from `@site/src/components`.
|
||||
*
|
||||
|
|
Загрузка…
Ссылка в новой задаче