Skip to content

Commit ffe9905

Browse files
committed
support image rendering
1 parent b20eafe commit ffe9905

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/markupParser.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ import { open } from 'fs';
88
const EXTENTION_ID = 'denco.confluence-markup';
99
const EMOTICON_PATH = '/resources/emoticons/';
1010

11+
function imageUri(searchUri: vscode.Uri, imageLink: string) {
12+
let imageUri
13+
if (imageLink.match(/^(ht)|(f)tps?:\/\//)) {
14+
imageUri = vscode.Uri.parse(imageLink);
15+
} else {
16+
let extPath = path.dirname(searchUri.fsPath);
17+
imageUri = vscode.Uri.file(path.join(extPath, imageLink));
18+
}
19+
return imageUri;
20+
}
21+
1122
function emoticonUri(emoticonFile: string) {
1223
let extPath = vscode.extensions.getExtension(EXTENTION_ID).extensionPath;
1324
let emoticonUri = vscode.Uri.file(path.join(extPath, EMOTICON_PATH, emoticonFile));
@@ -30,7 +41,7 @@ export async function parseMarkup(sourceText: string, sourceUri: vscode.Uri) {
3041
tag = tag.replace(/-{3}/gi, '—');
3142
tag = tag.replace(/-{2}/gi, '–');
3243

33-
tag = tag.replace(/_([^_]*)_/g, "<em>$1</em>");
44+
// tag = tag.replace(/_([^_]*)_/g, "<em>$1</em>");
3445
tag = tag.replace(/\+([^\+]*)\+/g, "<u>$1</u>");
3546
tag = tag.replace(/\^([^\^]*)\^/g, "<sup>$1</sup>");
3647
tag = tag.replace(/~([^~]*)~/g, "<sub>$1</sub>");
@@ -55,6 +66,14 @@ export async function parseMarkup(sourceText: string, sourceUri: vscode.Uri) {
5566
tag = tag.replace(/\(!\)/g, '<img alt="(warning)" src="' + emoticonUri('warning.png') + '"/>');
5667

5768
tag = tag.replace(/\[([^|]*)?\|?([^|]*)\]/g, "<a href='$2'>$1</a>");
69+
70+
//img
71+
let img = /!(.*)!/;
72+
let match = tag.match(img);
73+
if (match) {
74+
tag = '<img src="' + imageUri(sourceUri, match[1]) + '"/>';
75+
}
76+
5877
}
5978

6079
// code

0 commit comments

Comments
 (0)