Fix Markdown TOC Provider for Invalid References (#22553)

Fixes #22494

**Bug**
References without a definition can cause the markdown table of contents provider to break

**Fix**
Pass in an empty environment to markdown-it `parse` to prevent the null dereference on invalid links.
This commit is contained in:
Matt Bierner
2017-03-13 10:49:59 -07:00
committed by GitHub
parent d3fd888711
commit 31d0799fd8
3 changed files with 6 additions and 5 deletions

View File

@@ -17,7 +17,7 @@ export interface IToken {
interface MarkdownIt {
render(text: string): string;
parse(text: string): IToken[];
parse(text: string, env: any): IToken[];
utils: any;
}
@@ -83,9 +83,10 @@ export class MarkdownEngine {
return this.engine.render(text);
}
public parse(source: string): IToken[] {
public parse(document: vscode.Uri, source: string): IToken[] {
const {text, offset} = this.stripFrontmatter(source);
return this.engine.parse(text).map(token => {
this.currentDocument = document;
return this.engine.parse(text, {}).map(token => {
if (token.map) {
token.map[0] += offset;
}