From 6bce64c08cfcece2796b213a9370316b9b904d31 Mon Sep 17 00:00:00 2001 From: Yiyi Wang Date: Sat, 27 Oct 2018 21:20:29 -0500 Subject: [PATCH] 0.3.9 (#159) * Add enableLinkify option * Update to use latest vscode workspace API * Upgrade mume to version 0.3.6 --- package.json | 7 ++++- src/config.ts | 2 ++ src/extension.ts | 2 +- src/preview-content-provider.ts | 52 +++++++++++++++++++++++++++++++-- 4 files changed, 59 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index cb49e4d..1f4ef1e 100644 --- a/package.json +++ b/package.json @@ -219,6 +219,11 @@ "default": true, "type": "boolean" }, + "markdown-preview-enhanced.enableLinkify": { + "description": "Enable or disable conversion of URL-like text to links in the markdown preview.", + "default": true, + "type": "boolean" + }, "markdown-preview-enhanced.wikiLinkFileExtension": { "description": "By default, the extension for wikilink is `.md`. For example: [[test]] will direct to file path `test.md`.", "default": ".md", @@ -419,7 +424,7 @@ "test": "npm run compile && node ./node_modules/vscode/bin/test" }, "dependencies": { - "@shd101wyy/mume": "^0.3.5", + "@shd101wyy/mume": "^0.3.6", "@types/vfile": "^2.2.2" }, "devDependencies": { diff --git a/src/config.ts b/src/config.ts index 2fa2852..20410b4 100644 --- a/src/config.ts +++ b/src/config.ts @@ -11,6 +11,7 @@ export class MarkdownPreviewEnhancedConfig implements MarkdownEngineConfig { public readonly breakOnSingleNewLine: boolean; public readonly enableTypographer: boolean; public readonly enableWikiLinkSyntax: boolean; + public readonly enableLinkify: boolean; public readonly wikiLinkFileExtension: string; public readonly enableEmojiSyntax: boolean; public readonly enableExtendedTableSyntax: boolean; @@ -47,6 +48,7 @@ export class MarkdownPreviewEnhancedConfig implements MarkdownEngineConfig { this.breakOnSingleNewLine = config.get("breakOnSingleNewLine"); this.enableTypographer = config.get("enableTypographer"); this.enableWikiLinkSyntax = config.get("enableWikiLinkSyntax"); + this.enableLinkify = config.get("enableLinkify"); this.wikiLinkFileExtension = config.get("wikiLinkFileExtension"); this.enableEmojiSyntax = config.get("enableEmojiSyntax"); this.enableExtendedTableSyntax = config.get( diff --git a/src/extension.ts b/src/extension.ts index b948ce8..da62d18 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -496,7 +496,7 @@ export function activate(context: vscode.ExtensionContext) { { command: "changeTextEditorSelection", line: event.selections[0].active.line, - topRatio + topRatio, }, ); } diff --git a/src/preview-content-provider.ts b/src/preview-content-provider.ts index d53e796..e39be10 100644 --- a/src/preview-content-provider.ts +++ b/src/preview-content-provider.ts @@ -217,6 +217,51 @@ export class MarkdownPreviewEnhancedView } } + private getProjectDirectoryPath( + sourceUri: Uri, + workspaceFolders: vscode.WorkspaceFolder[], + ) { + const possibleWorkspaceFolders = workspaceFolders.filter( + (workspaceFolder) => { + return ( + path + .dirname(sourceUri.path.toUpperCase()) + .indexOf(workspaceFolder.uri.path.toUpperCase()) >= 0 + ); + }, + ); + + if (!possibleWorkspaceFolders.length) { + vscode.window.showErrorMessage( + "Bug in getProjectDirectoryPath function. Please report on GitHub. Thanks!", + ); + } + + // We pick the workspaceUri that has the longest path + const workspaceFolder = possibleWorkspaceFolders.sort( + (x, y) => y.uri.fsPath.length - x.uri.fsPath.length, + )[0]; + let projectDirectoryPath = workspaceFolder.uri.fsPath; + if (process.platform === "win32") { + projectDirectoryPath = projectDirectoryPath.replace( + /^([a-zA-Z])\:\\/, + (_, $1) => `${$1.toUpperCase()}:\\`, + ); + } + return projectDirectoryPath; + } + + private getFilePath(sourceUri: Uri) { + if (process.platform === "win32") { + return sourceUri.fsPath.replace( + /^([a-zA-Z])\:\\/, + (_, $1) => `${$1.toUpperCase()}:\\`, + ); + } else { + return sourceUri.fsPath; + } + } + /** * Initialize MarkdownEngine for this markdown file */ @@ -224,8 +269,11 @@ export class MarkdownPreviewEnhancedView let engine = this.getEngine(sourceUri); if (!engine) { engine = new MarkdownEngine({ - filePath: sourceUri.fsPath, - projectDirectoryPath: vscode.workspace.rootPath, + filePath: this.getFilePath(sourceUri), + projectDirectoryPath: this.getProjectDirectoryPath( + sourceUri, + vscode.workspace.workspaceFolders, + ), config: this.config, }); this.engineMaps[sourceUri.fsPath] = engine;