mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-20 02:08:47 +00:00
Align rendered header id generation with markdown language service (#221742)
Fixes #220064
This commit is contained in:
@@ -313,7 +313,7 @@ export class MarkdownItEngine implements IMdParser {
|
||||
private _addNamedHeaders(md: MarkdownIt): void {
|
||||
const original = md.renderer.rules.heading_open;
|
||||
md.renderer.rules.heading_open = (tokens: Token[], idx: number, options, env, self) => {
|
||||
const title = tokens[idx + 1].children!.reduce<string>((acc, t) => acc + t.content, '');
|
||||
const title = this._tokenToPlainText(tokens[idx + 1]);
|
||||
let slug = this.slugifier.fromHeading(title);
|
||||
|
||||
if (this._slugCount.has(slug.value)) {
|
||||
@@ -334,6 +334,21 @@ export class MarkdownItEngine implements IMdParser {
|
||||
};
|
||||
}
|
||||
|
||||
private _tokenToPlainText(token: Token): string {
|
||||
if (token.children) {
|
||||
return token.children.map(x => this._tokenToPlainText(x)).join('');
|
||||
}
|
||||
|
||||
switch (token.type) {
|
||||
case 'text':
|
||||
case 'emoji':
|
||||
case 'code_inline':
|
||||
return token.content;
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
private _addLinkRenderer(md: MarkdownIt): void {
|
||||
const original = md.renderer.rules.link_open;
|
||||
|
||||
@@ -441,4 +456,4 @@ function normalizeHighlightLang(lang: string | undefined) {
|
||||
default:
|
||||
return lang;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user