From 7086fb76ec54aca98c4ef340cb1914ee8f13938e Mon Sep 17 00:00:00 2001 From: Matt Bierner Date: Thu, 27 Dec 2018 19:28:57 -0600 Subject: [PATCH] Take document as parameter instead document components --- .../src/features/foldingProvider.ts | 4 ++-- .../src/features/previewContentProvider.ts | 2 +- .../src/markdownEngine.ts | 18 ++++++++++-------- .../src/tableOfContentsProvider.ts | 2 +- 4 files changed, 14 insertions(+), 12 deletions(-) diff --git a/extensions/markdown-language-features/src/features/foldingProvider.ts b/extensions/markdown-language-features/src/features/foldingProvider.ts index 594baaadb82..9e98cfd67b3 100644 --- a/extensions/markdown-language-features/src/features/foldingProvider.ts +++ b/extensions/markdown-language-features/src/features/foldingProvider.ts @@ -25,7 +25,7 @@ export default class MarkdownFoldingProvider implements vscode.FoldingRangeProvi (isStartRegion(token.content) || isEndRegion(token.content)); - const tokens = await this.engine.parse(document.uri, document.getText()); + const tokens = await this.engine.parse(document); const regionMarkers = tokens.filter(isRegionMarker) .map(token => ({ line: token.map[0], isStart: isStartRegion(token.content) })); @@ -84,7 +84,7 @@ export default class MarkdownFoldingProvider implements vscode.FoldingRangeProvi } }; - const tokens = await this.engine.parse(document.uri, document.getText()); + const tokens = await this.engine.parse(document); const multiLineListItems = tokens.filter(isFoldableToken); return multiLineListItems.map(listItem => { const start = listItem.map[0]; diff --git a/extensions/markdown-language-features/src/features/previewContentProvider.ts b/extensions/markdown-language-features/src/features/previewContentProvider.ts index 30767b88c5d..403fc9249d8 100644 --- a/extensions/markdown-language-features/src/features/previewContentProvider.ts +++ b/extensions/markdown-language-features/src/features/previewContentProvider.ts @@ -68,7 +68,7 @@ export class MarkdownContentProvider { const nonce = new Date().getTime() + '' + new Date().getMilliseconds(); const csp = this.getCspForResource(sourceUri, nonce); - const body = await this.engine.render(sourceUri, config.previewFrontMatter === 'hide', markdownDocument.getText()); + const body = await this.engine.render(markdownDocument, config.previewFrontMatter === 'hide'); return ` diff --git a/extensions/markdown-language-features/src/markdownEngine.ts b/extensions/markdown-language-features/src/markdownEngine.ts index 35b8d19495d..9ad45ea3dd2 100644 --- a/extensions/markdown-language-features/src/markdownEngine.ts +++ b/extensions/markdown-language-features/src/markdownEngine.ts @@ -3,12 +3,13 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ +import * as crypto from 'crypto'; import { MarkdownIt, Token } from 'markdown-it'; import * as path from 'path'; import * as vscode from 'vscode'; -import * as crypto from 'crypto'; import { MarkdownContributions } from './markdownExtensions'; import { Slugifier } from './slugify'; +import { SkinnyTextDocument } from './tableOfContentsProvider'; import { getUriForLinkWithKnownExternalScheme } from './util/links'; const FrontMatterRegex = /^---\s*[^]*?(-{3}|\.{3})\s*/; @@ -93,28 +94,29 @@ export class MarkdownEngine { return { text, offset }; } - public async render(document: vscode.Uri, stripFrontmatter: boolean, text: string): Promise { + public async render(document: SkinnyTextDocument, stripFrontmatter: boolean): Promise { let offset = 0; + let text = document.getText(); if (stripFrontmatter) { const markdownContent = this.stripFrontmatter(text); offset = markdownContent.offset; text = markdownContent.text; } - this.currentDocument = document; + this.currentDocument = document.uri; this.firstLine = offset; this._slugCount = new Map(); - const engine = await this.getEngine(document); + const engine = await this.getEngine(document.uri); return engine.render(text); } - public async parse(document: vscode.Uri, source: string): Promise { + public async parse(document: SkinnyTextDocument): Promise { const UNICODE_NEWLINE_REGEX = /\u2028|\u2029/g; - const { text, offset } = this.stripFrontmatter(source); - this.currentDocument = document; + const { text, offset } = this.stripFrontmatter(document.getText()); + this.currentDocument = document.uri; this._slugCount = new Map(); - const engine = await this.getEngine(document); + const engine = await this.getEngine(document.uri); return engine.parse(text.replace(UNICODE_NEWLINE_REGEX, ''), {}).map(token => { if (token.map) { diff --git a/extensions/markdown-language-features/src/tableOfContentsProvider.ts b/extensions/markdown-language-features/src/tableOfContentsProvider.ts index bbb30b7cea6..d2b041c2523 100644 --- a/extensions/markdown-language-features/src/tableOfContentsProvider.ts +++ b/extensions/markdown-language-features/src/tableOfContentsProvider.ts @@ -49,7 +49,7 @@ export class TableOfContentsProvider { private async buildToc(document: SkinnyTextDocument): Promise { const toc: TocEntry[] = []; - const tokens = await this.engine.parse(document.uri, document.getText()); + const tokens = await this.engine.parse(document); const slugCount = new Map();