lookup of custom style sheets, fixes #8287

This commit is contained in:
kieferrm
2016-06-30 14:50:22 -07:00
parent 51520d26ca
commit 6b01b4c0d8
2 changed files with 21 additions and 5 deletions
+1 -1
View File
@@ -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."
}
}
}
+20 -4
View 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;