chore(vscode): update to 1.53.2
These conflicts will be resolved in the following commits. We do it this way so that PR review is possible.
This commit is contained in:
@@ -54,6 +54,15 @@ class TokenCache {
|
||||
}
|
||||
}
|
||||
|
||||
export interface RenderOutput {
|
||||
html: string;
|
||||
containingImages: { src: string }[];
|
||||
}
|
||||
|
||||
interface RenderEnv {
|
||||
containingImages: { src: string }[];
|
||||
}
|
||||
|
||||
export class MarkdownEngine {
|
||||
private md?: Promise<MarkdownIt>;
|
||||
|
||||
@@ -141,7 +150,7 @@ export class MarkdownEngine {
|
||||
return engine.parse(text.replace(UNICODE_NEWLINE_REGEX, ''), {});
|
||||
}
|
||||
|
||||
public async render(input: SkinnyTextDocument | string): Promise<string> {
|
||||
public async render(input: SkinnyTextDocument | string): Promise<RenderOutput> {
|
||||
const config = this.getConfig(typeof input === 'string' ? undefined : input.uri);
|
||||
const engine = await this.getEngine(config);
|
||||
|
||||
@@ -149,10 +158,19 @@ export class MarkdownEngine {
|
||||
? this.tokenizeString(input, engine)
|
||||
: this.tokenizeDocument(input, config, engine);
|
||||
|
||||
return engine.renderer.render(tokens, {
|
||||
const env: RenderEnv = {
|
||||
containingImages: []
|
||||
};
|
||||
|
||||
const html = engine.renderer.render(tokens, {
|
||||
...(engine as any).options,
|
||||
...config
|
||||
}, {});
|
||||
}, env);
|
||||
|
||||
return {
|
||||
html,
|
||||
containingImages: env.containingImages
|
||||
};
|
||||
}
|
||||
|
||||
public async parse(document: SkinnyTextDocument): Promise<Token[]> {
|
||||
@@ -192,12 +210,13 @@ export class MarkdownEngine {
|
||||
|
||||
private addImageStabilizer(md: any): void {
|
||||
const original = md.renderer.rules.image;
|
||||
md.renderer.rules.image = (tokens: any, idx: number, options: any, env: any, self: any) => {
|
||||
md.renderer.rules.image = (tokens: any, idx: number, options: any, env: RenderEnv, self: any) => {
|
||||
const token = tokens[idx];
|
||||
token.attrJoin('class', 'loading');
|
||||
|
||||
const src = token.attrGet('src');
|
||||
if (src) {
|
||||
env.containingImages.push({ src });
|
||||
const imgHash = hash(src);
|
||||
token.attrSet('id', `image-hash-${imgHash}`);
|
||||
}
|
||||
@@ -231,6 +250,13 @@ export class MarkdownEngine {
|
||||
return normalizeLink(vscode.Uri.parse(link).with({ scheme: vscode.env.uriScheme }).toString());
|
||||
}
|
||||
|
||||
// Support file:// links
|
||||
if (isOfScheme(Schemes.file, link)) {
|
||||
// Ensure link is relative by prepending `/` so that it uses the <base> element URI
|
||||
// when resolving the absolute URL
|
||||
return normalizeLink('/' + link.replace(/^file:/, 'file'));
|
||||
}
|
||||
|
||||
// If original link doesn't look like a url with a scheme, assume it must be a link to a file in workspace
|
||||
if (!/^[a-z\-]+:/i.test(link)) {
|
||||
// Use a fake scheme for parsing
|
||||
@@ -241,12 +267,14 @@ export class MarkdownEngine {
|
||||
if (uri.path[0] === '/') {
|
||||
const root = vscode.workspace.getWorkspaceFolder(this.currentDocument!);
|
||||
if (root) {
|
||||
const fileUri = vscode.Uri.joinPath(root.uri, uri.fsPath);
|
||||
uri = fileUri.with({
|
||||
scheme: uri.scheme,
|
||||
const fileUri = vscode.Uri.joinPath(root.uri, uri.fsPath).with({
|
||||
fragment: uri.fragment,
|
||||
query: uri.query,
|
||||
});
|
||||
|
||||
// Ensure fileUri is relative by prepending `/` so that it uses the <base> element URI
|
||||
// when resolving the absolute URL
|
||||
uri = vscode.Uri.parse('markdown-link:' + '/' + fileUri.toString(true).replace(/^\S+?:/, fileUri.scheme));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -269,9 +297,7 @@ export class MarkdownEngine {
|
||||
private addLinkValidator(md: any): void {
|
||||
const validateLink = md.validateLink;
|
||||
md.validateLink = (link: string) => {
|
||||
// support file:// links
|
||||
return validateLink(link)
|
||||
|| isOfScheme(Schemes.file, link)
|
||||
|| isOfScheme(Schemes.vscode, link)
|
||||
|| isOfScheme(Schemes['vscode-insiders'], link)
|
||||
|| /^data:image\/.*?;/.test(link);
|
||||
|
||||
Reference in New Issue
Block a user