Skip to content

Commit

Permalink
🐛 Unable to render when image link is absolute path. TobiasTao#11
Browse files Browse the repository at this point in the history
  • Loading branch information
TobiasTao committed Oct 28, 2020
1 parent 859dabe commit fa2cc68
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@
"type": "string",
"default": "KaTeX",
"description": "Mathematical formula rendering engine",
"enum": ["KaTeX", "MathJax"]
"enum": [
"KaTeX",
"MathJax"
]
},
"vscode-md.options.preview.math.macros": {
"type": "object",
Expand Down Expand Up @@ -229,7 +232,7 @@
"webpack-cli": "^3.3.12"
},
"dependencies": {
"vditor": "^3.5.5"
"vditor": "^3.6.0"
},
"keywords": [
"markdown",
Expand Down
5 changes: 4 additions & 1 deletion src/mdEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ export class MarkdownEditorProvider implements vscode.CustomTextEditorProvider {
.toString(true)
.replace(/\/[^\/]+?\.\w+$/, '/');

let linkPrefix = '';

const extConfig = vscode.workspace.getConfiguration('vscode-md');

// image dir(fsPath)
Expand All @@ -67,7 +69,7 @@ export class MarkdownEditorProvider implements vscode.CustomTextEditorProvider {
}
}
} else if (extConfig.image.pathType === 'absolute') {
linkBase = linkBase.split('///')[0] + '///';
linkPrefix = linkBase.split('///')[0] + '///';
if (path.isAbsolute(extConfig.image.dirPath)) {
imgPathPrefix = extConfig.image.dirPath;
imgStoreDir = imgPathPrefix;
Expand All @@ -93,6 +95,7 @@ export class MarkdownEditorProvider implements vscode.CustomTextEditorProvider {
preview: {
markdown: {
linkBase: linkBase,
linkPrefix,
mark: extConfig.options.preview.markdown.mark
},
math: extConfig.options.preview.math,
Expand Down
58 changes: 29 additions & 29 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import { window } from 'vscode';
import { IImgInfo } from 'picgo/dist/src/utils/interfaces';

export function formatString(tplString: string, data: IUploadName | IOutputUrl) {
const keys = Object.keys(data);
const values = keys.map((k) => data[k]);
return new Function(keys.join(','), 'return `' + tplString + '`').apply(null, values);
const keys = Object.keys(data);
const values = keys.map((k) => data[k]);
return new Function(keys.join(','), 'return `' + tplString + '`').apply(null, values);
}

const nls = require('../package.nls.json');

function addPeriod(message: string) {
if (!message.endsWith('.') && !message.endsWith('!')) {
message = message + '.';
}
return message;
if (!message.endsWith('.') && !message.endsWith('!')) {
message = message + '.';
}
return message;
}

// export function showWarning(message: string) {
Expand All @@ -24,36 +24,36 @@ function addPeriod(message: string) {
// }

export function showError(message: string) {
message = addPeriod(message);
window.showErrorMessage(`${nls['ext.displayName']}: ${message}`);
message = addPeriod(message);
window.showErrorMessage(`${nls['ext.displayName']}: ${message}`);
}

// export function showInfo(message: string) {
// message = addPeriod(message);
// window.showInformationMessage(`${nls['ext.displayName']}: ${message}`);
// }
export function showInfo(message: string) {
message = addPeriod(message);
window.showInformationMessage(`${nls['ext.displayName']}: ${message}`);
}

export function getUploadedName(imgInfo: IImgInfo): string {
let fullName;
if (!imgInfo.fileName) {
fullName = '';
} else {
fullName = imgInfo.fileName as string;
}
let basename = path.basename(fullName, path.extname(fullName));
return basename;
let fullName;
if (!imgInfo.fileName) {
fullName = '';
} else {
fullName = imgInfo.fileName as string;
}
let basename = path.basename(fullName, path.extname(fullName));
return basename;
}

export function getNonce() {
let text = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < 32; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
let text = '';
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
for (let i = 0; i < 32; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
}
return text;
}

export function genImgName(): number {
var date = new Date(Date.now());
return date.getTime();
var date = new Date(Date.now());
return date.getTime();
}

0 comments on commit fa2cc68

Please sign in to comment.