This commit is contained in:
1 parent
7574b928d6
commit
22bdfc259f
2 files changed
+20
-1
No files matched your search
@@ -67,6 +67,24 @@ describe('replaceHugoAdmonitions', () => {
|
||||
);
|
||||
expect(singleQuoted).toContain('<aside data-type="tip">Best practice:body</aside>');
|
||||
});
|
||||
|
||||
it('handles shortcodes written inline with the body', () => {
|
||||
const inline = replaceHugoAdmonitions(
|
||||
'{{< admonition abstract >}}在使用 Docker 时,可以配置镜像加速器。{{< /admonition >}}',
|
||||
render
|
||||
);
|
||||
expect(inline).toContain(
|
||||
'<aside data-type="abstract">摘要:在使用 Docker 时,可以配置镜像加速器。</aside>'
|
||||
);
|
||||
});
|
||||
|
||||
it('handles multi-line bodies that start on the same line as the open tag', () => {
|
||||
const multiline = replaceHugoAdmonitions(
|
||||
'{{< admonition note >}}第一行\n\n第二段\n{{< /admonition >}}',
|
||||
render
|
||||
);
|
||||
expect(multiline).toContain('<aside data-type="note">注意:第一行\n\n第二段</aside>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('heading IDs', () => {
|
||||
|
||||
@@ -57,8 +57,9 @@ export function replaceGithubAdmonitions(markdown: string, render: AdmonitionRen
|
||||
* 标题可选,且可以是 `"标题"`、`'标题'` 或裸文本。
|
||||
*/
|
||||
export function replaceHugoAdmonitions(html: string, render: AdmonitionRenderer): string {
|
||||
// 开/闭标签与正文之间允许任意空白(含同一行紧挨着写的情况)
|
||||
const pattern =
|
||||
/\{\{<\s*admonition\s+([a-zA-Z][\w-]*)([^>]*?)>\}\}\r?\n([\s\S]*?)\{\{<\s*\/admonition\s*>\}\}/gi;
|
||||
/\{\{<\s*admonition\s+([a-zA-Z][\w-]*)([^>]*?)>\}\}\s*([\s\S]*?)\s*\{\{<\s*\/admonition\s*>\}\}/gi;
|
||||
|
||||
return html.replace(pattern, (_match, type: string, rawTitle: string, content: string) =>
|
||||
render(type, rawTitle.trim(), content)
|
||||
|
||||
Reference in new issue
Block a user