|
@@ -1,4 +1,5 @@
|
|
|
import csvToMarkdownTable from 'csv-to-markdown-table';
|
|
import csvToMarkdownTable from 'csv-to-markdown-table';
|
|
|
|
|
+import type { Code, Table } from 'mdast';
|
|
|
import { fromMarkdown } from 'mdast-util-from-markdown';
|
|
import { fromMarkdown } from 'mdast-util-from-markdown';
|
|
|
import { gfmTableFromMarkdown } from 'mdast-util-gfm-table';
|
|
import { gfmTableFromMarkdown } from 'mdast-util-gfm-table';
|
|
|
import { gfmTable } from 'micromark-extension-gfm-table';
|
|
import { gfmTable } from 'micromark-extension-gfm-table';
|
|
@@ -8,7 +9,7 @@ import { visit } from 'unist-util-visit';
|
|
|
|
|
|
|
|
type Lang = 'csv' | 'csv-h' | 'tsv' | 'tsv-h';
|
|
type Lang = 'csv' | 'csv-h' | 'tsv' | 'tsv-h';
|
|
|
|
|
|
|
|
-function isXsv(lang: unknown): lang is Lang {
|
|
|
|
|
|
|
+function isXsv(lang?: string | null | undefined): lang is Lang {
|
|
|
return /^(csv|csv-h|tsv|tsv-h)$/.test(lang as string);
|
|
return /^(csv|csv-h|tsv|tsv-h)$/.test(lang as string);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -28,7 +29,7 @@ function rewriteNode(node: Node, lang: Lang) {
|
|
|
// replace node
|
|
// replace node
|
|
|
if (tableTree.children[0] != null) {
|
|
if (tableTree.children[0] != null) {
|
|
|
node.type = 'table';
|
|
node.type = 'table';
|
|
|
- node.children = tableTree.children[0].children;
|
|
|
|
|
|
|
+ (node as Table).children = tableTree.children[0].children;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -36,8 +37,8 @@ export const remarkPlugin: Plugin = function() {
|
|
|
return (tree) => {
|
|
return (tree) => {
|
|
|
visit(tree, (node) => {
|
|
visit(tree, (node) => {
|
|
|
if (node.type === 'code') {
|
|
if (node.type === 'code') {
|
|
|
- if (isXsv(node.lang)) {
|
|
|
|
|
- rewriteNode(node, node.lang);
|
|
|
|
|
|
|
+ if (isXsv((node as Code).lang)) {
|
|
|
|
|
+ rewriteNode((node as Code), (node as Code).lang as Lang);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|