Skip to content

Commit

Permalink
0.3.9 (#159)
Browse files Browse the repository at this point in the history
* Add enableLinkify option

* Update to use latest vscode workspace API

* Upgrade mume to version 0.3.6
  • Loading branch information
shd101wyy authored Oct 28, 2018
1 parent 805290a commit 6bce64c
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,6 +48,7 @@ export class MarkdownPreviewEnhancedConfig implements MarkdownEngineConfig {
this.breakOnSingleNewLine = config.get<boolean>("breakOnSingleNewLine");
this.enableTypographer = config.get<boolean>("enableTypographer");
this.enableWikiLinkSyntax = config.get<boolean>("enableWikiLinkSyntax");
this.enableLinkify = config.get<boolean>("enableLinkify");
this.wikiLinkFileExtension = config.get<string>("wikiLinkFileExtension");
this.enableEmojiSyntax = config.get<boolean>("enableEmojiSyntax");
this.enableExtendedTableSyntax = config.get<boolean>(
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ export function activate(context: vscode.ExtensionContext) {
{
command: "changeTextEditorSelection",
line: event.selections[0].active.line,
topRatio
topRatio,
},
);
}
Expand Down
52 changes: 50 additions & 2 deletions src/preview-content-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,63 @@ 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
*/
public initMarkdownEngine(sourceUri: Uri): MarkdownEngine {
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;
Expand Down

0 comments on commit 6bce64c

Please sign in to comment.