mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-08 09:08:48 +01:00
lookup of custom style sheets, fixes #8287
This commit is contained in:
@@ -117,7 +117,7 @@
|
||||
"markdown.styles": {
|
||||
"type": ["array"],
|
||||
"default": [],
|
||||
"description": "A list of URLs or local paths to CSS style sheets to use from the markdown preview."
|
||||
"description": "A list of URLs or local paths to CSS style sheets to use from the markdown preview. Relative paths are interpreted relative to the folder open in the explorer. If there is no open folder, they are interpreted relative to the location of the markdown file."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,17 +183,33 @@ class MDDocumentContentProvider implements TextDocumentContentProvider {
|
||||
return md;
|
||||
}
|
||||
|
||||
private getMediaPath(mediaFile) {
|
||||
private getMediaPath(mediaFile) : string {
|
||||
return this._context.asAbsolutePath(path.join('media', mediaFile));
|
||||
}
|
||||
|
||||
private fixHref(resource: Uri, href: string) {
|
||||
private isAbsolute(p) : boolean {
|
||||
return path.normalize(p + '/') === path.normalize(path.resolve(p) + '/');
|
||||
}
|
||||
|
||||
private fixHref(resource: Uri, href: string) : string {
|
||||
if (href) {
|
||||
// Return early if href is already a URL
|
||||
// Use href if it is already an URL
|
||||
if (Uri.parse(href).scheme) {
|
||||
return href;
|
||||
}
|
||||
// Otherwise convert to a file URI by joining the href with the resource location
|
||||
|
||||
// Use href as file URI if it is absolute
|
||||
if (this.isAbsolute(href)) {
|
||||
return Uri.file(href).toString();
|
||||
}
|
||||
|
||||
// use a workspace relative path if there is a workspace
|
||||
let rootPath = vscode.workspace.rootPath;
|
||||
if (rootPath) {
|
||||
return Uri.file(path.join(rootPath, href)).toString();
|
||||
}
|
||||
|
||||
// otherwise look relative to the markdown file
|
||||
return Uri.file(path.join(path.dirname(resource.fsPath), href)).toString();
|
||||
}
|
||||
return href;
|
||||
|
||||
Reference in New Issue
Block a user