pd-markdown 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +26 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/index.d.ts +4 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/index.d.ts.map +1 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/index.js +5 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/index.js.map +1 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/index.d.ts +4 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/index.d.ts.map +1 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/index.js +4 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/index.js.map +1 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/transform/heading.d.ts +6 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/transform/heading.d.ts.map +1 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/transform/heading.js +36 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/transform/heading.js.map +1 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/transform/list.d.ts +14 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/transform/list.d.ts.map +1 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/transform/list.js +18 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/transform/list.js.map +1 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/transform/table.d.ts +27 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/transform/table.d.ts.map +1 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/transform/table.js +37 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/plugins/transform/table.js.map +1 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/processor.d.ts +22 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/processor.d.ts.map +1 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/processor.js +95 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/processor.js.map +1 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/types/index.d.ts +55 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/types/index.d.ts.map +1 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/types/index.js +2 -0
- package/packages/parser/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/parser/dist/types/index.js.map +1 -0
- package/packages/parser/__tests__/frontmatter.test.ts +69 -0
- package/packages/parser/__tests__/gfm.test.ts +83 -0
- package/packages/parser/__tests__/processor.test.ts +136 -0
- package/packages/parser/__tests__/transform/heading.test.ts +56 -0
- package/packages/parser/__tests__/transform/list.test.ts +67 -0
- package/packages/parser/__tests__/transform/table.test.ts +85 -0
- package/packages/parser/dist/index.cjs +191 -0
- package/packages/parser/dist/index.cjs.map +1 -0
- package/packages/parser/dist/index.d.ts +4 -0
- package/packages/parser/dist/index.d.ts.map +1 -0
- package/packages/parser/dist/index.mjs +185 -0
- package/packages/parser/dist/index.mjs.map +1 -0
- package/packages/parser/dist/plugins/index.d.ts +4 -0
- package/packages/parser/dist/plugins/index.d.ts.map +1 -0
- package/packages/parser/dist/plugins/transform/heading.d.ts +6 -0
- package/packages/parser/dist/plugins/transform/heading.d.ts.map +1 -0
- package/packages/parser/dist/plugins/transform/list.d.ts +14 -0
- package/packages/parser/dist/plugins/transform/list.d.ts.map +1 -0
- package/packages/parser/dist/plugins/transform/table.d.ts +27 -0
- package/packages/parser/dist/plugins/transform/table.d.ts.map +1 -0
- package/packages/parser/dist/processor.d.ts +22 -0
- package/packages/parser/dist/processor.d.ts.map +1 -0
- package/packages/parser/dist/types/index.d.ts +55 -0
- package/packages/parser/dist/types/index.d.ts.map +1 -0
- package/packages/parser/node_modules/.bin/yaml +17 -0
- package/packages/parser/package.json +38 -0
- package/packages/parser/rollup.config.ts +38 -0
- package/packages/parser/src/index.ts +15 -0
- package/packages/parser/src/plugins/index.ts +3 -0
- package/packages/parser/src/plugins/transform/heading.ts +40 -0
- package/packages/parser/src/plugins/transform/list.ts +29 -0
- package/packages/parser/src/plugins/transform/table.ts +62 -0
- package/packages/parser/src/processor.ts +119 -0
- package/packages/parser/src/types/index.ts +60 -0
- package/packages/parser/tsconfig.json +9 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/ast/query.d.ts +36 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/ast/query.d.ts.map +1 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/ast/query.js +99 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/ast/query.js.map +1 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/ast/traverse.d.ts +22 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/ast/traverse.d.ts.map +1 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/ast/traverse.js +46 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/ast/traverse.js.map +1 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/index.d.ts +7 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/index.d.ts.map +1 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/index.js +8 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/index.js.map +1 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/string/sanitize.d.ts +22 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/string/sanitize.d.ts.map +1 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/string/sanitize.js +140 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/string/sanitize.js.map +1 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/string/slugify.d.ts +16 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/string/slugify.d.ts.map +1 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/string/slugify.js +39 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/string/slugify.js.map +1 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/types/index.d.ts +49 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/types/index.d.ts.map +1 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/types/index.js +19 -0
- package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/types/index.js.map +1 -0
- package/packages/utils/__tests__/query.test.ts +155 -0
- package/packages/utils/__tests__/sanitize.test.ts +96 -0
- package/packages/utils/__tests__/slugify.test.ts +71 -0
- package/packages/utils/__tests__/traverse.test.ts +131 -0
- package/packages/utils/dist/ast/query.d.ts +36 -0
- package/packages/utils/dist/ast/query.d.ts.map +1 -0
- package/packages/utils/dist/ast/traverse.d.ts +22 -0
- package/packages/utils/dist/ast/traverse.d.ts.map +1 -0
- package/packages/utils/dist/index.cjs +358 -0
- package/packages/utils/dist/index.cjs.map +1 -0
- package/packages/utils/dist/index.d.ts +7 -0
- package/packages/utils/dist/index.d.ts.map +1 -0
- package/packages/utils/dist/index.mjs +343 -0
- package/packages/utils/dist/index.mjs.map +1 -0
- package/packages/utils/dist/string/sanitize.d.ts +22 -0
- package/packages/utils/dist/string/sanitize.d.ts.map +1 -0
- package/packages/utils/dist/string/slugify.d.ts +16 -0
- package/packages/utils/dist/string/slugify.d.ts.map +1 -0
- package/packages/utils/dist/types/index.d.ts +49 -0
- package/packages/utils/dist/types/index.d.ts.map +1 -0
- package/packages/utils/package.json +27 -0
- package/packages/utils/rollup.config.ts +26 -0
- package/packages/utils/src/ast/query.ts +127 -0
- package/packages/utils/src/ast/traverse.ts +73 -0
- package/packages/utils/src/index.ts +20 -0
- package/packages/utils/src/string/sanitize.ts +155 -0
- package/packages/utils/src/string/slugify.ts +43 -0
- package/packages/utils/src/types/index.ts +72 -0
- package/packages/utils/tsconfig.json +8 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/MarkdownRenderer.d.ts +27 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/MarkdownRenderer.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/MarkdownRenderer.js +39 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/MarkdownRenderer.js.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/NodeRenderer.d.ts +10 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/NodeRenderer.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/NodeRenderer.js +130 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/NodeRenderer.js.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/context.d.ts +17 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/context.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/context.js +14 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/context.js.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Blockquote.d.ts +8 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Blockquote.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Blockquote.js +5 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Blockquote.js.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Code.d.ts +13 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Code.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Code.js +9 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Code.js.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Heading.d.ts +8 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Heading.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Heading.js +7 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Heading.js.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Image.d.ts +7 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Image.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Image.js +5 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Image.js.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Link.d.ts +8 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Link.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Link.js +7 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Link.js.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/List.d.ts +13 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/List.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/List.js +14 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/List.js.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Paragraph.d.ts +8 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Paragraph.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Paragraph.js +5 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Paragraph.js.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Table.d.ts +19 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Table.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Table.js +18 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/Table.js.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/index.d.ts +34 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/index.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/index.js +28 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/components/defaults/index.js.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/hooks/useMarkdown.d.ts +11 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/hooks/useMarkdown.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/hooks/useMarkdown.js +28 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/hooks/useMarkdown.js.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/index.d.ts +6 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/index.d.ts.map +1 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/index.js +9 -0
- package/packages/web/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/web/dist/index.js.map +1 -0
- package/packages/web/__tests__/MarkdownRenderer.test.tsx +89 -0
- package/packages/web/__tests__/NodeRenderer.test.tsx +97 -0
- package/packages/web/__tests__/components/Code.test.tsx +71 -0
- package/packages/web/__tests__/components/Heading.test.tsx +65 -0
- package/packages/web/__tests__/components/List.test.tsx +100 -0
- package/packages/web/__tests__/components/Table.test.tsx +105 -0
- package/packages/web/__tests__/useMarkdown.test.ts +63 -0
- package/packages/web/dist/components/MarkdownRenderer.d.ts +27 -0
- package/packages/web/dist/components/MarkdownRenderer.d.ts.map +1 -0
- package/packages/web/dist/components/NodeRenderer.d.ts +10 -0
- package/packages/web/dist/components/NodeRenderer.d.ts.map +1 -0
- package/packages/web/dist/components/context.d.ts +17 -0
- package/packages/web/dist/components/context.d.ts.map +1 -0
- package/packages/web/dist/components/defaults/Blockquote.d.ts +8 -0
- package/packages/web/dist/components/defaults/Blockquote.d.ts.map +1 -0
- package/packages/web/dist/components/defaults/Code.d.ts +13 -0
- package/packages/web/dist/components/defaults/Code.d.ts.map +1 -0
- package/packages/web/dist/components/defaults/Heading.d.ts +8 -0
- package/packages/web/dist/components/defaults/Heading.d.ts.map +1 -0
- package/packages/web/dist/components/defaults/Image.d.ts +7 -0
- package/packages/web/dist/components/defaults/Image.d.ts.map +1 -0
- package/packages/web/dist/components/defaults/Link.d.ts +8 -0
- package/packages/web/dist/components/defaults/Link.d.ts.map +1 -0
- package/packages/web/dist/components/defaults/List.d.ts +13 -0
- package/packages/web/dist/components/defaults/List.d.ts.map +1 -0
- package/packages/web/dist/components/defaults/Paragraph.d.ts +8 -0
- package/packages/web/dist/components/defaults/Paragraph.d.ts.map +1 -0
- package/packages/web/dist/components/defaults/Table.d.ts +19 -0
- package/packages/web/dist/components/defaults/Table.d.ts.map +1 -0
- package/packages/web/dist/components/defaults/index.d.ts +34 -0
- package/packages/web/dist/components/defaults/index.d.ts.map +1 -0
- package/packages/web/dist/hooks/useMarkdown.d.ts +11 -0
- package/packages/web/dist/hooks/useMarkdown.d.ts.map +1 -0
- package/packages/web/dist/index.cjs +306 -0
- package/packages/web/dist/index.cjs.map +1 -0
- package/packages/web/dist/index.d.ts +6 -0
- package/packages/web/dist/index.d.ts.map +1 -0
- package/packages/web/dist/index.mjs +287 -0
- package/packages/web/dist/index.mjs.map +1 -0
- package/packages/web/package.json +40 -0
- package/packages/web/rollup.config.ts +36 -0
- package/packages/web/src/components/MarkdownRenderer.tsx +70 -0
- package/packages/web/src/components/NodeRenderer.tsx +205 -0
- package/packages/web/src/components/context.ts +24 -0
- package/packages/web/src/components/defaults/Blockquote.tsx +11 -0
- package/packages/web/src/components/defaults/Code.tsx +26 -0
- package/packages/web/src/components/defaults/Heading.tsx +14 -0
- package/packages/web/src/components/defaults/Image.tsx +10 -0
- package/packages/web/src/components/defaults/Link.tsx +18 -0
- package/packages/web/src/components/defaults/List.tsx +33 -0
- package/packages/web/src/components/defaults/Paragraph.tsx +11 -0
- package/packages/web/src/components/defaults/Table.tsx +50 -0
- package/packages/web/src/components/defaults/index.tsx +80 -0
- package/packages/web/src/hooks/useMarkdown.ts +32 -0
- package/packages/web/src/index.ts +37 -0
- package/packages/web/tsconfig.json +11 -0
- package/packages/web/vitest.config.ts +9 -0
- package/pnpm-workspace.yaml +2 -0
- package/tsconfig.base.json +26 -0
- package/tsconfig.json +8 -0
- package/vitest.config.ts +28 -0
- package/vitest.setup.ts +1 -0
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { unified } from 'unified'
|
|
2
|
+
import remarkParse from 'remark-parse'
|
|
3
|
+
import remarkGfm from 'remark-gfm'
|
|
4
|
+
import remarkFrontmatter from 'remark-frontmatter'
|
|
5
|
+
import { visit } from 'unist-util-visit'
|
|
6
|
+
import { parse as parseYaml } from 'yaml'
|
|
7
|
+
import type { Root, Yaml } from 'mdast'
|
|
8
|
+
import type { VFile } from 'vfile'
|
|
9
|
+
|
|
10
|
+
import type { Parser, ParserOptions, ParserPlugin, FileData } from './types'
|
|
11
|
+
import { transformHeading, transformList, transformTable } from './plugins'
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Default parser options
|
|
15
|
+
*/
|
|
16
|
+
const DEFAULT_OPTIONS: Required<Omit<ParserOptions, 'plugins'>> = {
|
|
17
|
+
gfm: true,
|
|
18
|
+
frontmatter: true,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create frontmatter extraction plugin
|
|
23
|
+
*/
|
|
24
|
+
function extractFrontmatter() {
|
|
25
|
+
return (tree: Root, file: VFile) => {
|
|
26
|
+
visit(tree, 'yaml', (node: Yaml) => {
|
|
27
|
+
try {
|
|
28
|
+
const data = parseYaml(node.value) as Record<string, unknown>
|
|
29
|
+
;(file.data as FileData).frontmatter = data
|
|
30
|
+
} catch {
|
|
31
|
+
// Invalid YAML, ignore
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Create a markdown parser with the specified options
|
|
39
|
+
*
|
|
40
|
+
* @param options - Parser configuration options
|
|
41
|
+
* @returns Parser instance with parse method
|
|
42
|
+
*/
|
|
43
|
+
export function createParser(options: ParserOptions = {}): Parser {
|
|
44
|
+
const opts = { ...DEFAULT_OPTIONS, ...options }
|
|
45
|
+
const customPlugins = options.plugins || []
|
|
46
|
+
|
|
47
|
+
// Build processor (使用 any 绕过复杂的类型检查)
|
|
48
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
49
|
+
let processor: any = unified().use(remarkParse)
|
|
50
|
+
|
|
51
|
+
// Add GFM support
|
|
52
|
+
if (opts.gfm) {
|
|
53
|
+
processor = processor.use(remarkGfm)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Add frontmatter support
|
|
57
|
+
if (opts.frontmatter) {
|
|
58
|
+
processor = processor.use(remarkFrontmatter, ['yaml'])
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Run custom "before" plugins
|
|
62
|
+
const beforePlugins = customPlugins.filter((p) => p.phase === 'before')
|
|
63
|
+
for (const plugin of beforePlugins) {
|
|
64
|
+
processor = processor.use(() => plugin.transform)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Add frontmatter extraction
|
|
68
|
+
if (opts.frontmatter) {
|
|
69
|
+
processor = processor.use(extractFrontmatter)
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Add built-in transform plugins
|
|
73
|
+
processor = processor
|
|
74
|
+
.use(() => transformHeading)
|
|
75
|
+
.use(() => transformList)
|
|
76
|
+
.use(() => transformTable)
|
|
77
|
+
|
|
78
|
+
// Run custom "after" plugins
|
|
79
|
+
const afterPlugins = customPlugins.filter((p) => p.phase === 'after')
|
|
80
|
+
for (const plugin of afterPlugins) {
|
|
81
|
+
processor = processor.use(() => plugin.transform)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Freeze processor
|
|
85
|
+
processor.freeze()
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
parse(content: string): Root {
|
|
89
|
+
// Parse markdown to AST
|
|
90
|
+
const tree = processor.parse(content) as Root
|
|
91
|
+
|
|
92
|
+
// Run all transform plugins
|
|
93
|
+
processor.runSync(tree)
|
|
94
|
+
|
|
95
|
+
return tree
|
|
96
|
+
},
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Type-safe helper to define a parser plugin
|
|
102
|
+
*
|
|
103
|
+
* @param config - Plugin configuration
|
|
104
|
+
* @returns Parser plugin
|
|
105
|
+
*/
|
|
106
|
+
export function definePlugin<T = void>(
|
|
107
|
+
config: {
|
|
108
|
+
name: string
|
|
109
|
+
phase: 'before' | 'after'
|
|
110
|
+
transform: (options?: T) => (tree: Root, file: VFile) => void
|
|
111
|
+
},
|
|
112
|
+
options?: T
|
|
113
|
+
): ParserPlugin {
|
|
114
|
+
return {
|
|
115
|
+
name: config.name,
|
|
116
|
+
phase: config.phase,
|
|
117
|
+
transform: config.transform(options),
|
|
118
|
+
}
|
|
119
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { Root } from 'mdast'
|
|
2
|
+
import type { VFile } from 'vfile'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Parser plugin configuration
|
|
6
|
+
*/
|
|
7
|
+
export interface ParserPlugin {
|
|
8
|
+
/** Unique plugin name */
|
|
9
|
+
name: string
|
|
10
|
+
/** When to run: before or after built-in transforms */
|
|
11
|
+
phase: 'before' | 'after'
|
|
12
|
+
/** Transform function */
|
|
13
|
+
transform: (tree: Root, file: VFile) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Parser options
|
|
18
|
+
*/
|
|
19
|
+
export interface ParserOptions {
|
|
20
|
+
/** Custom plugins to add */
|
|
21
|
+
plugins?: ParserPlugin[]
|
|
22
|
+
/** Enable GFM syntax (default: true) */
|
|
23
|
+
gfm?: boolean
|
|
24
|
+
/** Enable frontmatter parsing (default: true) */
|
|
25
|
+
frontmatter?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Parser instance
|
|
30
|
+
*/
|
|
31
|
+
export interface Parser {
|
|
32
|
+
/** Parse markdown string to AST */
|
|
33
|
+
parse(content: string): Root
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Plugin definition helper config
|
|
38
|
+
*/
|
|
39
|
+
export interface PluginConfig<T = unknown> {
|
|
40
|
+
/** Plugin name */
|
|
41
|
+
name: string
|
|
42
|
+
/** When to run */
|
|
43
|
+
phase: 'before' | 'after'
|
|
44
|
+
/** Transform function factory */
|
|
45
|
+
transform: (options?: T) => (tree: Root, file: VFile) => void
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Frontmatter data extracted from markdown
|
|
50
|
+
*/
|
|
51
|
+
export interface FrontmatterData {
|
|
52
|
+
[key: string]: unknown
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Extended file data with frontmatter
|
|
57
|
+
*/
|
|
58
|
+
export interface FileData {
|
|
59
|
+
frontmatter?: FrontmatterData
|
|
60
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { Node } from 'unist';
|
|
2
|
+
import type { MdNode, Parent } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Find all nodes of a specific type in the AST
|
|
5
|
+
*
|
|
6
|
+
* @param node - Root node to search from
|
|
7
|
+
* @param type - Node type to find
|
|
8
|
+
* @returns Array of matching nodes
|
|
9
|
+
*/
|
|
10
|
+
export declare function findNodes<T extends Node = MdNode>(node: Node, type: string): T[];
|
|
11
|
+
/**
|
|
12
|
+
* Find the first node of a specific type in the AST
|
|
13
|
+
*
|
|
14
|
+
* @param node - Root node to search from
|
|
15
|
+
* @param type - Node type to find
|
|
16
|
+
* @returns The first matching node or undefined
|
|
17
|
+
*/
|
|
18
|
+
export declare function findNode<T extends Node = MdNode>(node: Node, type: string): T | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Find all nodes matching a predicate
|
|
21
|
+
*
|
|
22
|
+
* @param node - Root node to search from
|
|
23
|
+
* @param predicate - Function to test each node
|
|
24
|
+
* @returns Array of matching nodes
|
|
25
|
+
*/
|
|
26
|
+
export declare function findNodesBy<T extends Node = MdNode>(node: Node, predicate: (node: Node) => boolean): T[];
|
|
27
|
+
/**
|
|
28
|
+
* Get the parent of a node in the AST
|
|
29
|
+
* Note: This requires traversing from root, use sparingly
|
|
30
|
+
*
|
|
31
|
+
* @param root - Root node of the AST
|
|
32
|
+
* @param target - Node to find parent of
|
|
33
|
+
* @returns Parent node or undefined if not found or is root
|
|
34
|
+
*/
|
|
35
|
+
export declare function findParent(root: Node, target: Node): Parent | undefined;
|
|
36
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/ast/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAG9C;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,EAC/C,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,GACX,CAAC,EAAE,CAiBL;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,EAC9C,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,MAAM,GACX,CAAC,GAAG,SAAS,CAsBf;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,EACjD,IAAI,EAAE,IAAI,EACV,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,GACjC,CAAC,EAAE,CAiBL;AAED;;;;;;;GAOG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,GAAG,MAAM,GAAG,SAAS,CAsBvE"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { isParent } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Find all nodes of a specific type in the AST
|
|
4
|
+
*
|
|
5
|
+
* @param node - Root node to search from
|
|
6
|
+
* @param type - Node type to find
|
|
7
|
+
* @returns Array of matching nodes
|
|
8
|
+
*/
|
|
9
|
+
export function findNodes(node, type) {
|
|
10
|
+
const results = [];
|
|
11
|
+
function visit(current) {
|
|
12
|
+
if (current.type === type) {
|
|
13
|
+
results.push(current);
|
|
14
|
+
}
|
|
15
|
+
if (isParent(current)) {
|
|
16
|
+
for (const child of current.children) {
|
|
17
|
+
visit(child);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
visit(node);
|
|
22
|
+
return results;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Find the first node of a specific type in the AST
|
|
26
|
+
*
|
|
27
|
+
* @param node - Root node to search from
|
|
28
|
+
* @param type - Node type to find
|
|
29
|
+
* @returns The first matching node or undefined
|
|
30
|
+
*/
|
|
31
|
+
export function findNode(node, type) {
|
|
32
|
+
let result;
|
|
33
|
+
function visit(current) {
|
|
34
|
+
if (current.type === type) {
|
|
35
|
+
result = current;
|
|
36
|
+
return true; // Found, stop searching
|
|
37
|
+
}
|
|
38
|
+
if (isParent(current)) {
|
|
39
|
+
for (const child of current.children) {
|
|
40
|
+
if (visit(child)) {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
visit(node);
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Find all nodes matching a predicate
|
|
52
|
+
*
|
|
53
|
+
* @param node - Root node to search from
|
|
54
|
+
* @param predicate - Function to test each node
|
|
55
|
+
* @returns Array of matching nodes
|
|
56
|
+
*/
|
|
57
|
+
export function findNodesBy(node, predicate) {
|
|
58
|
+
const results = [];
|
|
59
|
+
function visit(current) {
|
|
60
|
+
if (predicate(current)) {
|
|
61
|
+
results.push(current);
|
|
62
|
+
}
|
|
63
|
+
if (isParent(current)) {
|
|
64
|
+
for (const child of current.children) {
|
|
65
|
+
visit(child);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
visit(node);
|
|
70
|
+
return results;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Get the parent of a node in the AST
|
|
74
|
+
* Note: This requires traversing from root, use sparingly
|
|
75
|
+
*
|
|
76
|
+
* @param root - Root node of the AST
|
|
77
|
+
* @param target - Node to find parent of
|
|
78
|
+
* @returns Parent node or undefined if not found or is root
|
|
79
|
+
*/
|
|
80
|
+
export function findParent(root, target) {
|
|
81
|
+
let result;
|
|
82
|
+
function visit(current, parent) {
|
|
83
|
+
if (current === target) {
|
|
84
|
+
result = parent;
|
|
85
|
+
return true;
|
|
86
|
+
}
|
|
87
|
+
if (isParent(current)) {
|
|
88
|
+
for (const child of current.children) {
|
|
89
|
+
if (visit(child, current)) {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
visit(root, undefined);
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.js","sourceRoot":"","sources":["../../src/ast/query.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC;;;;;;GAMG;AACH,MAAM,UAAU,SAAS,CACvB,IAAU,EACV,IAAY;IAEZ,MAAM,OAAO,GAAQ,EAAE,CAAA;IAEvB,SAAS,KAAK,CAAC,OAAa;QAC1B,IAAI,OAAO,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YAC1B,OAAO,CAAC,IAAI,CAAC,OAAY,CAAC,CAAA;QAC5B,CAAC;QAED,IAAI,QAAQ,CAAC,OAA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,CAAC,IAAI,CAAC,CAAA;IACX,OAAO,OAAO,CAAA;AAChB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,UAAU,CAAC,IAAU,EAAE,MAAY;IACjD,IAAI,MAA0B,CAAA;IAE9B,SAAS,KAAK,CAAC,OAAa,EAAE,MAA0B;QACtD,IAAI,OAAO,KAAK,MAAM,EAAE,CAAC;YACvB,MAAM,GAAG,MAAM,CAAA;YACf,OAAO,IAAI,CAAA;QACb,CAAC;QAED,IAAI,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACtB,KAAK,MAAM,KAAK,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;gBACrC,IAAI,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,EAAE,CAAC;oBAC1B,OAAO,IAAI,CAAA;gBACb,CAAC;YACH,CAAC;QACH,CAAC;QAED,OAAO,KAAK,CAAA;IACd,CAAC;IAED,KAAK,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;IACtB,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Node } from 'unist';
|
|
2
|
+
import type { MdNode, Visitor } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Traverse AST in depth-first order
|
|
5
|
+
*
|
|
6
|
+
* @param node - Root node to start traversal
|
|
7
|
+
* @param visitor - Visitor function called for each node
|
|
8
|
+
* Return `false` to skip children of current node
|
|
9
|
+
* Return `true` or `undefined` to continue
|
|
10
|
+
*/
|
|
11
|
+
export declare function traverseAst<T extends Node = MdNode>(node: T, visitor: Visitor<T>): void;
|
|
12
|
+
/**
|
|
13
|
+
* Traverse AST with enter and leave callbacks
|
|
14
|
+
*
|
|
15
|
+
* @param node - Root node to start traversal
|
|
16
|
+
* @param callbacks - Object with optional enter and leave functions
|
|
17
|
+
*/
|
|
18
|
+
export declare function traverseAstWithCallbacks<T extends Node = MdNode>(node: T, callbacks: {
|
|
19
|
+
enter?: Visitor<T>;
|
|
20
|
+
leave?: Visitor<T>;
|
|
21
|
+
}): void;
|
|
22
|
+
//# sourceMappingURL=traverse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../src/ast/traverse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AACjC,OAAO,KAAK,EAAU,MAAM,EAAE,OAAO,EAAE,MAAM,UAAU,CAAA;AAGvD;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,EACjD,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,GAClB,IAAI,CAsBN;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,CAAC,SAAS,IAAI,GAAG,MAAM,EAC9D,IAAI,EAAE,CAAC,EACP,SAAS,EAAE;IACT,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IAClB,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;CACnB,GACA,IAAI,CAqBN"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isParent } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Traverse AST in depth-first order
|
|
4
|
+
*
|
|
5
|
+
* @param node - Root node to start traversal
|
|
6
|
+
* @param visitor - Visitor function called for each node
|
|
7
|
+
* Return `false` to skip children of current node
|
|
8
|
+
* Return `true` or `undefined` to continue
|
|
9
|
+
*/
|
|
10
|
+
export function traverseAst(node, visitor) {
|
|
11
|
+
function visit(current, index, parent) {
|
|
12
|
+
const result = visitor(current, index, parent);
|
|
13
|
+
// Skip children if visitor returns false
|
|
14
|
+
if (result === false) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
if (isParent(current)) {
|
|
18
|
+
const children = current.children;
|
|
19
|
+
for (let i = 0; i < children.length; i++) {
|
|
20
|
+
visit(children[i], i, current);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
visit(node, undefined, undefined);
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Traverse AST with enter and leave callbacks
|
|
28
|
+
*
|
|
29
|
+
* @param node - Root node to start traversal
|
|
30
|
+
* @param callbacks - Object with optional enter and leave functions
|
|
31
|
+
*/
|
|
32
|
+
export function traverseAstWithCallbacks(node, callbacks) {
|
|
33
|
+
const { enter, leave } = callbacks;
|
|
34
|
+
function visit(current, index, parent) {
|
|
35
|
+
const shouldSkipChildren = enter?.(current, index, parent) === false;
|
|
36
|
+
if (!shouldSkipChildren && isParent(current)) {
|
|
37
|
+
const children = current.children;
|
|
38
|
+
for (let i = 0; i < children.length; i++) {
|
|
39
|
+
visit(children[i], i, current);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
leave?.(current, index, parent);
|
|
43
|
+
}
|
|
44
|
+
visit(node, undefined, undefined);
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=traverse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"traverse.js","sourceRoot":"","sources":["../../src/ast/traverse.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAEnC;;;;;;;GAOG;AACH,MAAM,UAAU,WAAW,CACzB,IAAO,EACP,OAAmB;IAEnB,SAAS,KAAK,CACZ,OAAU,EACV,KAAyB,EACzB,MAA0B;QAE1B,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;QAE9C,yCAAyC;QACzC,IAAI,MAAM,KAAK,KAAK,EAAE,CAAC;YACrB,OAAM;QACR,CAAC;QAED,IAAI,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YACtB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAe,CAAA;YACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACzC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAA4B,CAAC,CAAA;YACrD,CAAC;QACH,CAAC;IACH,CAAC;IAED,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;AACnC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CACtC,IAAO,EACP,SAGC;IAED,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,SAAS,CAAA;IAElC,SAAS,KAAK,CACZ,OAAU,EACV,KAAyB,EACzB,MAA0B;QAE1B,MAAM,kBAAkB,GAAG,KAAK,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,KAAK,CAAA;QAEpE,IAAI,CAAC,kBAAkB,IAAI,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAe,CAAA;YACxC,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;gBACzC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,OAA4B,CAAC,CAAA;YACrD,CAAC;QACH,CAAC;QAED,KAAK,EAAE,CAAC,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IACjC,CAAC;IAED,KAAK,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;AACnC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export type { MdNode, MdRoot, Parent, Literal, Visitor, PluginOptions, Position, Location, } from './types';
|
|
2
|
+
export { isParent, isLiteral, isNodeType } from './types';
|
|
3
|
+
export { traverseAst, traverseAstWithCallbacks } from './ast/traverse';
|
|
4
|
+
export { findNodes, findNode, findNodesBy, findParent } from './ast/query';
|
|
5
|
+
export { slugify, uniqueSlugify } from './string/slugify';
|
|
6
|
+
export { escapeHtml, sanitizeHtml, stripHtml } from './string/sanitize';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,MAAM,EACN,MAAM,EACN,MAAM,EACN,OAAO,EACP,OAAO,EACP,aAAa,EACb,QAAQ,EACR,QAAQ,GACT,MAAM,SAAS,CAAA;AAChB,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAGzD,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAG1E,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA"}
|
package/packages/utils/.rollup.cache/Users/pidan/Work/Learn/pd-markdown/packages/utils/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { isParent, isLiteral, isNodeType } from './types';
|
|
2
|
+
// AST utilities
|
|
3
|
+
export { traverseAst, traverseAstWithCallbacks } from './ast/traverse';
|
|
4
|
+
export { findNodes, findNode, findNodesBy, findParent } from './ast/query';
|
|
5
|
+
// String utilities
|
|
6
|
+
export { slugify, uniqueSlugify } from './string/slugify';
|
|
7
|
+
export { escapeHtml, sanitizeHtml, stripHtml } from './string/sanitize';
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAEzD,gBAAgB;AAChB,OAAO,EAAE,WAAW,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AACtE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAE1E,mBAAmB;AACnB,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AACzD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Escape HTML special characters
|
|
3
|
+
*
|
|
4
|
+
* @param text - Text to escape
|
|
5
|
+
* @returns Escaped text safe for HTML insertion
|
|
6
|
+
*/
|
|
7
|
+
export declare function escapeHtml(text: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Sanitize HTML string by removing dangerous content
|
|
10
|
+
*
|
|
11
|
+
* @param html - HTML string to sanitize
|
|
12
|
+
* @returns Sanitized HTML string
|
|
13
|
+
*/
|
|
14
|
+
export declare function sanitizeHtml(html: string): string;
|
|
15
|
+
/**
|
|
16
|
+
* Strip all HTML tags from a string
|
|
17
|
+
*
|
|
18
|
+
* @param html - HTML string to strip
|
|
19
|
+
* @returns Plain text without HTML tags
|
|
20
|
+
*/
|
|
21
|
+
export declare function stripHtml(html: string): string;
|
|
22
|
+
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.d.ts","sourceRoot":"","sources":["../../src/string/sanitize.ts"],"names":[],"mappings":"AAWA;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AAwED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CA+CjD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE9C"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTML entities that need escaping
|
|
3
|
+
*/
|
|
4
|
+
const HTML_ESCAPE_MAP = {
|
|
5
|
+
'&': '&',
|
|
6
|
+
'<': '<',
|
|
7
|
+
'>': '>',
|
|
8
|
+
'"': '"',
|
|
9
|
+
"'": ''',
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Escape HTML special characters
|
|
13
|
+
*
|
|
14
|
+
* @param text - Text to escape
|
|
15
|
+
* @returns Escaped text safe for HTML insertion
|
|
16
|
+
*/
|
|
17
|
+
export function escapeHtml(text) {
|
|
18
|
+
return text.replace(/[&<>"']/g, (char) => HTML_ESCAPE_MAP[char] || char);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Allowed HTML tags for sanitization
|
|
22
|
+
*/
|
|
23
|
+
const ALLOWED_TAGS = new Set([
|
|
24
|
+
'a',
|
|
25
|
+
'abbr',
|
|
26
|
+
'b',
|
|
27
|
+
'blockquote',
|
|
28
|
+
'br',
|
|
29
|
+
'code',
|
|
30
|
+
'dd',
|
|
31
|
+
'del',
|
|
32
|
+
'div',
|
|
33
|
+
'dl',
|
|
34
|
+
'dt',
|
|
35
|
+
'em',
|
|
36
|
+
'h1',
|
|
37
|
+
'h2',
|
|
38
|
+
'h3',
|
|
39
|
+
'h4',
|
|
40
|
+
'h5',
|
|
41
|
+
'h6',
|
|
42
|
+
'hr',
|
|
43
|
+
'i',
|
|
44
|
+
'img',
|
|
45
|
+
'ins',
|
|
46
|
+
'kbd',
|
|
47
|
+
'li',
|
|
48
|
+
'ol',
|
|
49
|
+
'p',
|
|
50
|
+
'pre',
|
|
51
|
+
'q',
|
|
52
|
+
's',
|
|
53
|
+
'samp',
|
|
54
|
+
'small',
|
|
55
|
+
'span',
|
|
56
|
+
'strong',
|
|
57
|
+
'sub',
|
|
58
|
+
'sup',
|
|
59
|
+
'table',
|
|
60
|
+
'tbody',
|
|
61
|
+
'td',
|
|
62
|
+
'tfoot',
|
|
63
|
+
'th',
|
|
64
|
+
'thead',
|
|
65
|
+
'tr',
|
|
66
|
+
'u',
|
|
67
|
+
'ul',
|
|
68
|
+
]);
|
|
69
|
+
/**
|
|
70
|
+
* Allowed attributes for sanitization
|
|
71
|
+
*/
|
|
72
|
+
const ALLOWED_ATTRS = new Set([
|
|
73
|
+
'href',
|
|
74
|
+
'src',
|
|
75
|
+
'alt',
|
|
76
|
+
'title',
|
|
77
|
+
'class',
|
|
78
|
+
'id',
|
|
79
|
+
'name',
|
|
80
|
+
'target',
|
|
81
|
+
'rel',
|
|
82
|
+
'width',
|
|
83
|
+
'height',
|
|
84
|
+
'align',
|
|
85
|
+
'colspan',
|
|
86
|
+
'rowspan',
|
|
87
|
+
]);
|
|
88
|
+
/**
|
|
89
|
+
* Sanitize HTML string by removing dangerous content
|
|
90
|
+
*
|
|
91
|
+
* @param html - HTML string to sanitize
|
|
92
|
+
* @returns Sanitized HTML string
|
|
93
|
+
*/
|
|
94
|
+
export function sanitizeHtml(html) {
|
|
95
|
+
let result = html;
|
|
96
|
+
// Remove script tags first
|
|
97
|
+
result = result.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
|
|
98
|
+
// Remove event handlers
|
|
99
|
+
result = result.replace(/\s+on\w+\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]*)/gi, '');
|
|
100
|
+
// Remove disallowed tags (keep content) and sanitize attributes
|
|
101
|
+
result = result.replace(/<\/?(\w+)([^>]*)>/g, (match, tagName, attrs) => {
|
|
102
|
+
const tag = tagName.toLowerCase();
|
|
103
|
+
if (!ALLOWED_TAGS.has(tag)) {
|
|
104
|
+
return '';
|
|
105
|
+
}
|
|
106
|
+
// For closing tags, just return them
|
|
107
|
+
if (match.startsWith('</')) {
|
|
108
|
+
return `</${tag}>`;
|
|
109
|
+
}
|
|
110
|
+
// Sanitize attributes
|
|
111
|
+
const sanitizedAttrs = [];
|
|
112
|
+
const attrRegex = /\s+([\w-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|(\S+))/g;
|
|
113
|
+
let attrMatch;
|
|
114
|
+
while ((attrMatch = attrRegex.exec(attrs)) !== null) {
|
|
115
|
+
const [, attrName, v1, v2, v3] = attrMatch;
|
|
116
|
+
const attr = attrName.toLowerCase();
|
|
117
|
+
if (ALLOWED_ATTRS.has(attr)) {
|
|
118
|
+
let value = v1 ?? v2 ?? v3 ?? '';
|
|
119
|
+
// Check for dangerous URLs in href/src
|
|
120
|
+
if ((attr === 'href' || attr === 'src') && /^\s*javascript\s*:/i.test(value)) {
|
|
121
|
+
value = '';
|
|
122
|
+
}
|
|
123
|
+
sanitizedAttrs.push(`${attr}="${value}"`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
const attrStr = sanitizedAttrs.length > 0 ? ' ' + sanitizedAttrs.join(' ') : '';
|
|
127
|
+
return `<${tag}${attrStr}>`;
|
|
128
|
+
});
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Strip all HTML tags from a string
|
|
133
|
+
*
|
|
134
|
+
* @param html - HTML string to strip
|
|
135
|
+
* @returns Plain text without HTML tags
|
|
136
|
+
*/
|
|
137
|
+
export function stripHtml(html) {
|
|
138
|
+
return html.replace(/<[^>]*>/g, '');
|
|
139
|
+
}
|
|
140
|
+
//# sourceMappingURL=sanitize.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize.js","sourceRoot":"","sources":["../../src/string/sanitize.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,eAAe,GAA2B;IAC9C,GAAG,EAAE,OAAO;IACZ,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,MAAM;IACX,GAAG,EAAE,QAAQ;IACb,GAAG,EAAE,OAAO;CACb,CAAA;AAED;;;;;GAKG;AACH,MAAM,UAAU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C,CAAC,GAAG,GAAG,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAA;QAC/E,OAAO,IAAI,GAAG,GAAG,OAAO,GAAG,CAAA;IAC7B,CAAC,CAAC,CAAA;IAEF,OAAO,MAAM,CAAA;AACf,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,IAAY;IACpC,OAAO,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,CAAA;AACrC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convert text to URL-safe slug
|
|
3
|
+
*
|
|
4
|
+
* @param text - Text to slugify
|
|
5
|
+
* @returns URL-safe slug
|
|
6
|
+
*/
|
|
7
|
+
export declare function slugify(text: string): string;
|
|
8
|
+
/**
|
|
9
|
+
* Generate unique slug with counter suffix for duplicates
|
|
10
|
+
*
|
|
11
|
+
* @param text - Text to slugify
|
|
12
|
+
* @param existingSlugs - Set of existing slugs to check against
|
|
13
|
+
* @returns Unique slug
|
|
14
|
+
*/
|
|
15
|
+
export declare function uniqueSlugify(text: string, existingSlugs: Set<string>): string;
|
|
16
|
+
//# sourceMappingURL=slugify.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slugify.d.ts","sourceRoot":"","sources":["../../src/string/slugify.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAe5C;AAED;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,MAAM,CAY9E"}
|