feat: 完善导出设置与打印预览
This commit is contained in:
@@ -78,6 +78,7 @@ const markdown = new MarkdownIt(markdownOptions)
|
||||
|
||||
const defaultFenceRenderer = markdown.renderer.rules.fence;
|
||||
const lengthStylePattern = /^-?\d+(?:\.\d+)?(?:em|ex|px|%)$/u;
|
||||
const tableTextAlignStylePattern = /^(?:left|center|right)$/u;
|
||||
|
||||
markdown.renderer.rules.fence = (
|
||||
tokens,
|
||||
@@ -131,8 +132,8 @@ const safeHtmlOptions: sanitizeHtml.IOptions = {
|
||||
li: ["class", "value"],
|
||||
ol: ["class", "start"],
|
||||
span: ["class", "style"],
|
||||
td: ["colspan", "rowspan"],
|
||||
th: ["colspan", "rowspan", "scope"]
|
||||
td: ["colspan", "rowspan", "style"],
|
||||
th: ["colspan", "rowspan", "scope", "style"]
|
||||
},
|
||||
allowedSchemes: ["http", "https", "mailto"],
|
||||
allowedSchemesByTag: {
|
||||
@@ -149,6 +150,12 @@ const safeHtmlOptions: sanitizeHtml.IOptions = {
|
||||
"padding-left": [lengthStylePattern],
|
||||
"vertical-align": [lengthStylePattern],
|
||||
"border-bottom-width": [lengthStylePattern]
|
||||
},
|
||||
td: {
|
||||
"text-align": [tableTextAlignStylePattern]
|
||||
},
|
||||
th: {
|
||||
"text-align": [tableTextAlignStylePattern]
|
||||
}
|
||||
},
|
||||
transformTags: {
|
||||
|
||||
@@ -33,6 +33,21 @@ const answer = 42;
|
||||
);
|
||||
});
|
||||
|
||||
it("保留 Markdown 表格的列对齐语义", () => {
|
||||
const result = renderMarkdown(`
|
||||
| 左对齐 | 居中 | 右对齐 |
|
||||
| :--- | :---: | ---: |
|
||||
| A | B | C |
|
||||
`);
|
||||
|
||||
expect(result.bodyHtml).toContain('<th style="text-align:left">左对齐</th>');
|
||||
expect(result.bodyHtml).toContain('<th style="text-align:center">居中</th>');
|
||||
expect(result.bodyHtml).toContain('<th style="text-align:right">右对齐</th>');
|
||||
expect(result.bodyHtml).toContain('<td style="text-align:left">A</td>');
|
||||
expect(result.bodyHtml).toContain('<td style="text-align:center">B</td>');
|
||||
expect(result.bodyHtml).toContain('<td style="text-align:right">C</td>');
|
||||
});
|
||||
|
||||
it("读取并规范化 Front Matter 元数据", () => {
|
||||
const result = renderMarkdown(`---
|
||||
title: 项目报告
|
||||
@@ -74,6 +89,29 @@ flowchart LR
|
||||
);
|
||||
});
|
||||
|
||||
it("完整保留 Mermaid 区块内的 config frontmatter", () => {
|
||||
const result = renderMarkdown(`
|
||||
\`\`\`mermaid
|
||||
---
|
||||
title: Frontmatter 示例
|
||||
config:
|
||||
theme: forest
|
||||
look: handDrawn
|
||||
flowchart:
|
||||
curve: basis
|
||||
---
|
||||
flowchart LR
|
||||
A[开始] --> B[结束]
|
||||
\`\`\`
|
||||
`);
|
||||
|
||||
expect(result.bodyHtml).toContain("title: Frontmatter 示例");
|
||||
expect(result.bodyHtml).toContain("theme: forest");
|
||||
expect(result.bodyHtml).toContain("look: handDrawn");
|
||||
expect(result.bodyHtml).toContain("curve: basis");
|
||||
expect(result.bodyHtml).toContain("flowchart LR");
|
||||
});
|
||||
|
||||
it("阻止原始 HTML 和危险链接形成可执行内容", () => {
|
||||
const result = renderMarkdown(`
|
||||
<script>alert("xss")</script>
|
||||
|
||||
Reference in New Issue
Block a user