提交 7a24ced6 编写于 作者: M Matt Bierner

Make sure fenced code blocks properly get line numbers assigned

Fixes #51095
上级 2d4dc132
......@@ -44,10 +44,10 @@ export class MarkdownEngine {
}
if (lang && hljs.getLanguage(lang)) {
try {
return `<pre class="hljs"><code><div>${hljs.highlight(lang, str, true).value}</div></code></pre>`;
return `<div>${hljs.highlight(lang, str, true).value}</div>`;
} catch (error) { }
}
return `<pre class="hljs"><code><div>${this.md!.utils.escapeHtml(str)}</div></code></pre>`;
return `<code><div>${this.md!.utils.escapeHtml(str)}</div>`;
}
}).use(mdnh, {
slugify: (header: string) => this.slugifier.fromHeading(header).value
......@@ -57,10 +57,12 @@ export class MarkdownEngine {
this.usePlugin(await plugin);
}
for (const renderName of ['paragraph_open', 'heading_open', 'image', 'code_block', 'blockquote_open', 'list_item_open']) {
for (const renderName of ['paragraph_open', 'heading_open', 'image', 'code_block', 'fence', 'blockquote_open', 'list_item_open']) {
this.addLineNumberRenderer(this.md, renderName);
}
this.addFencedRenderer(this.md);
this.addLinkNormalizer(this.md);
this.addLinkValidator(this.md);
}
......@@ -127,6 +129,18 @@ export class MarkdownEngine {
};
}
private addFencedRenderer(md: any): void {
const original = md.renderer.rules['fenced'];
md.renderer.rules['fenced'] = (tokens: any, idx: number, options: any, env: any, self: any) => {
const token = tokens[idx];
if (token.map && token.map.length) {
token.attrJoin('class', 'hljs');
}
return original(tokens, idx, options, env, self);
};
}
private addLinkNormalizer(md: any): void {
const normalizeLink = md.normalizeLink;
md.normalizeLink = (link: string) => {
......
......@@ -18,7 +18,7 @@ export class MarkdownFileTopmostLineMonitor {
vscode.window.onDidChangeTextEditorVisibleRanges(event => {
if (isMarkdownFile(event.textEditor.document)) {
const line = getVisibleLine(event.textEditor);
if (line) {
if (typeof line === 'number') {
this.updateLine(event.textEditor.document.uri, line);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册