Change:
<!-- Please search existing issues to avoid creating duplicates. --<!-- Also please test using the latest insiders build to make sure your issue has not already been fixed: --<!-- Use Help Report Issue to prefill these. --- VSCode Version: Windows 7 & Mac 10.14 (Only these 2 Tested) A user of my extension reports duplicate html elements in export markdown, I debug & find this issue as described in header. It doesn't affect the preview rendering, so I cannot tell the step to reproduce. But I can tell, it's reproducible when all extension (except mine) is disabled, and the issue is gone in extension debugging environment. Please find more details here: PS: My extension uses VSCode Markdown render instance to provide WYSIWYG export
Is is causing any use facing problems?
Not really, copy HTML used most in copy & paste to rich text editors, as I know, which could still render right result. Only matters if user cares about the excessive codes, or performance worries (for running many times)
We have two calls to markdown it: Render the markdown to html parse the markdown to a set of tokens Markdown it has an internal render method that takes a list of tokens instead: We could cache the tokens and use this api instead. Marking as help wanted. Here's where the two calls are:
, I am trying this one :)

Discussion:
import { getUriForLinkWithKnownExternalScheme } from './util/links'; const FrontMatterRegex = /^---s*[^]*?(-{3}|.{3})s*/; export class MarkdownEngine { private md?: MarkdownIt; private firstLine?: number; private currentDocument?: vscode.Uri; private _slugCount = new Map<string, number>(); <ins> private cachedTokens = new Map<vscode.Uri, Token[]>(); </ins> public constructor( private readonly extensionPreviewResourceProvider: MarkdownContributions,

return { text, offset }; } <ins> private tokenize(document: SkinnyTextDocument, engine: MarkdownIt): Token[] { const UNICODE_NEWLINE_REGEX = /u2028|u2029/g; const { text, offset } = this.stripFrontmatter(document.getText()); const uri = document.uri; if (this.cachedTokens.has(uri)) { return this.cachedTokens.get(uri)!; } const tokens = engine.parse(text.replace(UNICODE_NEWLINE_REGEX, ''), {}).map(token => { if (token.map) { token.map[0] += offset; token.map[1] += offset; } return token; }); this.cachedTokens.set(uri, tokens); return tokens; } </ins> public async render(document: SkinnyTextDocument, stripFrontmatter: boolean): Promise<string> { let offset = 0; let text = document.getText();

this._slugCount = new Map<string, number>(); const engine = await this.getEngine(document.uri); <del> return engine.render(text); </del> <ins> return engine.renderer.render(this.tokenize(document, engine), this.md, {}); </ins> } public async parse(document: SkinnyTextDocument): Promise<Token[]> { <del> const UNICODE_NEWLINE_REGEX = /u2028|u2029/g; const { text, offset } = this.stripFrontmatter(document.getText()); </del> this.currentDocument = document.uri; this._slugCount = new Map<string, number>(); const engine = await this.getEngine(document.uri); <del> return engine.parse(text.replace(UNICODE_NEWLINE_REGEX, ''), {}).map(token => { if (token.map) { token.map[0] += offset; token.map[1] += offset; } return token; }); </del> <ins> return this.tokenize(document, engine); </ins> } private addLineNumberRenderer(md: any, ruleName: string): void {