@jacobbubu/md-to-lark 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/LICENSE +15 -0
- package/README.md +171 -0
- package/dist/btt/build-tree.js +79 -0
- package/dist/btt/index.js +1 -0
- package/dist/btt/types.js +1 -0
- package/dist/cli/publish-md-to-lark.js +15 -0
- package/dist/commands/publish-md/args.js +224 -0
- package/dist/commands/publish-md/command.js +97 -0
- package/dist/commands/publish-md/index.js +1 -0
- package/dist/commands/publish-md/input-resolver.js +48 -0
- package/dist/commands/publish-md/mermaid-render.js +17 -0
- package/dist/commands/publish-md/pipeline-transform.js +4 -0
- package/dist/commands/publish-md/preset-loader.js +113 -0
- package/dist/commands/publish-md/presets/medium.js +7 -0
- package/dist/commands/publish-md/presets/zh-format.js +8 -0
- package/dist/commands/publish-md/title-policy.js +93 -0
- package/dist/index.js +1 -0
- package/dist/interop/btt-to-last.js +79 -0
- package/dist/interop/codec-btt-to-last.js +435 -0
- package/dist/interop/codec-last-to-btt.js +383 -0
- package/dist/interop/codec-shared.js +722 -0
- package/dist/interop/index.js +2 -0
- package/dist/interop/last-to-btt.js +17 -0
- package/dist/lark/block-types.js +42 -0
- package/dist/lark/client.js +36 -0
- package/dist/lark/docx/ops.js +596 -0
- package/dist/lark/docx/render-btt.js +156 -0
- package/dist/lark/docx/render-models.js +1 -0
- package/dist/lark/docx/render-payload.js +338 -0
- package/dist/lark/docx/render-post-process.js +98 -0
- package/dist/lark/docx/render-table.js +87 -0
- package/dist/lark/docx/render-types.js +7 -0
- package/dist/lark/index.js +2 -0
- package/dist/lark/types.js +1 -0
- package/dist/last/api.js +1687 -0
- package/dist/last/index.js +3 -0
- package/dist/last/preview-terminal.js +296 -0
- package/dist/last/textual-block-types.js +19 -0
- package/dist/last/to-markdown.js +303 -0
- package/dist/last/types.js +11 -0
- package/dist/pipeline/hast-to-last.js +946 -0
- package/dist/pipeline/index.js +3 -0
- package/dist/pipeline/markdown/md-to-hast.js +34 -0
- package/dist/pipeline/markdown/prepare-markdown.js +1049 -0
- package/dist/preview/index.js +1 -0
- package/dist/preview/markdown-terminal.js +350 -0
- package/dist/publish/asset-adapter.js +123 -0
- package/dist/publish/btt-patch.js +65 -0
- package/dist/publish/common.js +139 -0
- package/dist/publish/ids.js +9 -0
- package/dist/publish/index.js +7 -0
- package/dist/publish/last-normalize.js +327 -0
- package/dist/publish/process-file.js +228 -0
- package/dist/publish/runtime.js +133 -0
- package/dist/publish/stage-cache.js +56 -0
- package/dist/shared/rate-limiter.js +18 -0
- package/dist/shared/retry.js +141 -0
- package/package.json +78 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { unified } from 'unified';
|
|
2
|
+
import remarkParse from 'remark-parse';
|
|
3
|
+
import remarkGfm from 'remark-gfm';
|
|
4
|
+
import remarkMath from 'remark-math';
|
|
5
|
+
import remarkRehype from 'remark-rehype';
|
|
6
|
+
// Keep leading frontmatter visible in render output while avoiding accidental
|
|
7
|
+
// setext-heading parsing. We re-encode it as a fenced code block.
|
|
8
|
+
function rewriteLeadingFrontmatterAsCodeFence(markdown) {
|
|
9
|
+
const hasBom = markdown.startsWith('\uFEFF');
|
|
10
|
+
const source = hasBom ? markdown.slice(1) : markdown;
|
|
11
|
+
const fmMatch = source.match(/^((?:[ \t]*\r?\n)*)(-{3}|\+{3})[ \t]*\r?\n([\s\S]*?)\r?\n(?:-{3}|\+{3}|\.{3})[ \t]*(?:\r?\n|$)/);
|
|
12
|
+
if (!fmMatch || !fmMatch[0])
|
|
13
|
+
return markdown;
|
|
14
|
+
const leadingBlankLines = fmMatch[1] ?? '';
|
|
15
|
+
const opener = fmMatch[2];
|
|
16
|
+
const body = fmMatch[3] ?? '';
|
|
17
|
+
const language = opener === '+++' ? 'toml' : 'yaml';
|
|
18
|
+
const rest = source.slice(fmMatch[0].length);
|
|
19
|
+
const normalizedBody = body.replace(/\r\n/g, '\n');
|
|
20
|
+
const trailing = normalizedBody.endsWith('\n') ? '' : '\n';
|
|
21
|
+
const rewritten = `${leadingBlankLines}\`\`\`${language}\n${normalizedBody}${trailing}\`\`\`\n${rest}`;
|
|
22
|
+
return hasBom ? `\uFEFF${rewritten}` : rewritten;
|
|
23
|
+
}
|
|
24
|
+
export async function markdownToHast(markdown) {
|
|
25
|
+
const content = rewriteLeadingFrontmatterAsCodeFence(markdown);
|
|
26
|
+
const processor = unified()
|
|
27
|
+
.use(remarkParse)
|
|
28
|
+
.use(remarkGfm)
|
|
29
|
+
.use(remarkMath)
|
|
30
|
+
.use(remarkRehype, { allowDangerousHtml: false });
|
|
31
|
+
const mdast = processor.parse(content);
|
|
32
|
+
const hast = await processor.run(mdast);
|
|
33
|
+
return hast;
|
|
34
|
+
}
|