mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 01:58:53 +01:00
Merge pull request #77151 from connor4312/feat/markdown-render-command
feat(markdown): add render command (fixes #75612)
This commit is contained in:
@@ -118,7 +118,7 @@ export class MarkdownEngine {
|
||||
return md;
|
||||
}
|
||||
|
||||
private tokenize(
|
||||
private tokenizeDocument(
|
||||
document: SkinnyTextDocument,
|
||||
config: MarkdownItConfig,
|
||||
engine: MarkdownIt
|
||||
@@ -131,16 +131,23 @@ export class MarkdownEngine {
|
||||
this.currentDocument = document.uri;
|
||||
this._slugCount = new Map<string, number>();
|
||||
|
||||
const text = document.getText();
|
||||
const tokens = engine.parse(text.replace(UNICODE_NEWLINE_REGEX, ''), {});
|
||||
const tokens = this.tokenizeString(document.getText(), engine);
|
||||
this._tokenCache.update(document, config, tokens);
|
||||
return tokens;
|
||||
}
|
||||
|
||||
public async render(document: SkinnyTextDocument): Promise<string> {
|
||||
const config = this.getConfig(document.uri);
|
||||
private tokenizeString(text: string, engine: MarkdownIt) {
|
||||
return engine.parse(text.replace(UNICODE_NEWLINE_REGEX, ''), {});
|
||||
}
|
||||
|
||||
public async render(document: SkinnyTextDocument | string): Promise<string> {
|
||||
const config = this.getConfig(typeof document === 'string' ? undefined : document.uri);
|
||||
const engine = await this.getEngine(config);
|
||||
return engine.renderer.render(this.tokenize(document, config, engine), {
|
||||
const tokens = typeof document === 'string'
|
||||
? this.tokenizeString(document, engine)
|
||||
: this.tokenizeDocument(document, config, engine);
|
||||
|
||||
return engine.renderer.render(tokens, {
|
||||
...(engine as any).options,
|
||||
...config
|
||||
}, {});
|
||||
@@ -149,14 +156,14 @@ export class MarkdownEngine {
|
||||
public async parse(document: SkinnyTextDocument): Promise<Token[]> {
|
||||
const config = this.getConfig(document.uri);
|
||||
const engine = await this.getEngine(config);
|
||||
return this.tokenize(document, config, engine);
|
||||
return this.tokenizeDocument(document, config, engine);
|
||||
}
|
||||
|
||||
public cleanCache(): void {
|
||||
this._tokenCache.clean();
|
||||
}
|
||||
|
||||
private getConfig(resource: vscode.Uri): MarkdownItConfig {
|
||||
private getConfig(resource?: vscode.Uri): MarkdownItConfig {
|
||||
const config = vscode.workspace.getConfiguration('markdown', resource);
|
||||
return {
|
||||
breaks: config.get<boolean>('preview.breaks', false),
|
||||
|
||||
Reference in New Issue
Block a user