Skip to content

Commit 350552e

Browse files
authored
Merge pull request #4 from denco/fix-0.1.2
Fix 0.1.2
2 parents 4ee0f71 + ecf1cd3 commit 350552e

File tree

8 files changed

+176
-72
lines changed

8 files changed

+176
-72
lines changed

.vscode/tasks.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@
2525
"type": "npm",
2626
"script": "compile",
2727
"problemMatcher": []
28+
},
29+
{
30+
"type": "typescript",
31+
"tsconfig": "tsconfig.json",
32+
"option": "watch",
33+
"problemMatcher": [
34+
"$tsc-watch"
35+
]
2836
}
2937
]
3038
}

.vscodeignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
**/*.ts
2+
**/tsconfig.json
3+
**/*.map
4+
**/*.bak
5+
*.vsix
6+
.gitignore
7+
.vscode/**
8+
.vscode-test/**
9+
tsconfig.json
10+
package-lock.json
11+
test/**
12+
node_modules/**
13+
typings/**

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Confluence Wiki Markup
22

3+
## 0.1.2
4+
5+
* fix rendering of tag inside of code macro
6+
* fix [noformat issue](https://github.com/denco/vscode-confluence-markup/issues/3)
7+
* fix strikethrough and italic text
8+
* add table rendering
9+
310
## 0.1.1
411

512
* fix simple link

package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "confluence-markup",
33
"displayName": "Confluence markup",
4-
"version": "0.1.1",
4+
"version": "0.1.2",
55
"publisher": "denco",
66
"description": "Confluence markup language support for Visual Studio Code",
77
"keywords": [
@@ -37,7 +37,7 @@
3737
"onCommand:confluence.showPreviewToSide",
3838
"onLanguage:confluence"
3939
],
40-
"main": "./out/src/extension",
40+
"main": "./out/extension",
4141
"contributes": {
4242
"languages": [
4343
{
@@ -116,13 +116,13 @@
116116
"test": "npm run compile && node ./node_modules/vscode/bin/test"
117117
},
118118
"devDependencies": {
119+
"@types/mocha": "^2.2.42",
120+
"@types/node": "^7.0.43",
119121
"eslint": "^4.15.0",
120122
"tslint": "^5.9.1",
121123
"typescript": "^2.6.1",
122-
"vsce": "^1.35.0",
123-
"vscode": "^1.1.6",
124-
"@types/node": "^7.0.43",
125-
"@types/mocha": "^2.2.42"
124+
"vsce": "^1.37.6",
125+
"vscode": "^1.1.6"
126126
},
127127
"__metadata": {
128128
"publisherDisplayName": "denco"

resources/css/confluence.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ blockquote {
4747
border-left: 5px solid;
4848
}
4949

50+
table, th, td {
51+
border: 1px solid;
52+
border-collapse: collapse;
53+
}
54+
5055
pre > code {
5156
display: inline-block;
5257
width: 90%;

src/markupParser.ts

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
3535
//TODO: use Tokenazer instead of line loop
3636

3737
var result = '';
38-
3938
let listTag = '';
4039
let codeTagFlag = 0;
40+
let tableFlag = true;
4141
for (let entry of sourceText.split(/\n/gi)) {
4242
let tag = entry;
43+
let html_tag = false;
4344

4445
if (codeTagFlag == 0) {
4546
tag = tag.replace(/h(\d+)\.\s([^\n]+)/g, "<h$1>$2</h$1>");
@@ -71,27 +72,51 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
7172
tag = tag.replace(/\(x\)/g, '<img alt="(cross)" src="' + emoticonUri('error.png') + '"/>');
7273
tag = tag.replace(/\(!\)/g, '<img alt="(warning)" src="' + emoticonUri('warning.png') + '"/>');
7374

74-
tag = tag.replace(/\[([^|]*)?\|?([^|]*)\]/g, function (m0, m1, m2) {
75-
if ((m1.length !== 0) && (m2.length !== 0)) {
76-
return "<a href='" + m2 + "'>" + m1 + "</a>";
77-
} else {
78-
return "<a href='" + m1 + "'>" + m1 + "</a>";
79-
}
80-
});
75+
tag = tag.replace(/\\\\/gi, '<br/>');
8176

77+
let re = /\[([^|]*)?\|?([^|]*)\]/g
78+
if (tag.match(re)) {
79+
tag = tag.replace(re, function (m0, m1, m2) {
80+
if ((m1.length !== 0) && (m2.length !== 0)) {
81+
return "<a href='" + m2 + "'>" + m1 + "</a>";
82+
} else {
83+
return "<a href='" + m1 + "'>" + m1 + "</a>";
84+
}
85+
});
86+
html_tag = true;
87+
}
8288
//img
8389
let img = /!(.*)!/;
8490
let match = tag.match(img);
8591
if (match) {
8692
tag = '<img src="' + imageUri(sourceUri, match[1]) + '"/>';
8793
}
8894

95+
//table
96+
let tab_th_re = /\s*\|\|.*\|\|$/gi;
97+
let tab_td_re = /\s*\|.*\|$/gi;
98+
if (tag.match(tab_th_re)) {
99+
tag = tag.replace(/^\|\|/, '<th>');
100+
tag = tag.replace(/\|\|$/, '</th>');
101+
tag = tag.replace(/\|\|/gi, '</th><th>');
102+
tag = '<table><tr>' + tag + '</tr>';
103+
tableFlag = true;
104+
} else if (tag.match(tab_td_re)) {
105+
tag = tag.replace(/^\|/, '<td>');
106+
tag = tag.replace(/\|$/, '</td>');
107+
tag = tag.replace(/\|/gi, '</td><td>');
108+
tag = '<tr>' + tag + '</tr>';
109+
tableFlag = true;
110+
}
89111
}
90112

91113
// code
92114
// online code tag
93-
tag = tag.replace(/\{code[^\}]*\}(.*)\{code\}/, "<pre><code>$1</code></pre>");
94-
let re = /\{code.*\}/;
115+
tag = tag.replace(/\{(noformat|code)[^\}]*\}(.*)\{(noformat|code)\}/, function (m0, m1, m2) {
116+
return "<pre><code>" + m2.replace(/</gi, '&lt;') + "</code></pre>";
117+
});
118+
119+
let re = /\{[(code)|(noformat)].*\}/;
95120
let match = tag.match(re);
96121
if (match) {
97122
if (codeTagFlag === 0) {
@@ -130,13 +155,26 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
130155
}
131156

132157
tag = tag.replace(/\*([^\*]*)\*/g, "<strong>$1</strong>");
133-
tag = tag.replace(/\B-(\w*)-\B/g, "<span style='text-decoration: line-through;'>striket-hrough</span>");
134-
}
135-
if (tag === '<pre><code>') {
136-
result += tag;
158+
if ((! html_tag) && (! tag.match('<img'))) {
159+
tag = tag.replace(/-([\w ]*)-/g, "<span style='text-decoration: line-through;'>$1</span>");
160+
tag = tag.replace(/_([\w ]*)_/g, "<i>$1</i>");
161+
}
137162
} else {
138-
result += tag + '<br />';
163+
if (tag !== '<pre><code>'){
164+
tag = tag.replace(/</gi, '&lt;') + '<br />';
165+
}
139166
}
167+
168+
if (tag.match(/^s*$/)){
169+
tag = '<br />';
170+
}
171+
//close table
172+
if (!tag.match(/<\/tr>$/)){
173+
tag = '</table>' + tag;
174+
tableFlag = false;
175+
}
176+
result += tag;
177+
140178
// console.log("PARSED:" + tag);
141179
}
142180

test/test.confluence

Lines changed: 65 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
2+
h1. *Examples*
3+
4+
----
5+
h2. *headers:*
6+
7+
h1. Header 1
8+
h2. Header 2
9+
h3. Header 3
10+
h4. Header 4
11+
h5. Header 5
12+
h6. Header 6
13+
14+
----
15+
h2. *smiles:*
16+
117
* :) smile :)
218
* :( sad :(
319
* :P tongue
@@ -10,41 +26,34 @@
1026
* (x)
1127
* (!)
1228

13-
examples:
29+
----
30+
h2. *Links:*
1431

15-
Confluence:
1632
* [Mark Up|https://confluence.atlassian.com/doc/confluence-wiki-markup-251003035.html#ConfluenceWikiMarkup-Headings]
1733
* [Storage Format|https://confluence.atlassian.com/doc/confluence-storage-format-790796544.html]
34+
* [html format|https://www.w3schools.com/html/html_formatting.asp]
35+
* [test|https://ifl2014.github.io/submissions/ifl2014_submission_18.pdf]
1836

19-
20-
(!)
21-
22-
// Confluence
23-
24-
h1. Header 1
25-
26-
h2. Header 2
27-
28-
h3. Header 3
29-
30-
h4. Header 4
31-
32-
h5. Header 5
33-
34-
35-
h2. Text Effects
37+
----
38+
h2. *text effects:*
3639

3740
*strong*
41+
3842
*bold text*
3943

4044
_emphasis_
41-
_italics_ : Thing{_}x_
45+
46+
_italics_ : Thing_x_
47+
48+
_italics with spaces_
4249

4350
??citation?? \\
44-
-del eted- \\
45-
+inserted+ \\
4651

52+
-deleted- \\
53+
-deleted with spaces- \\
54+
+inserted+ \\
4755
Text with ^superscript^ : kg/m^3^
56+
4857
Text with ~subscript~
4958

5059
{{monospaced}}
@@ -54,35 +63,57 @@ bq. Here's how you make a paragraph appear as a block quotation.
5463
{color:red}look ma, red text!{color}
5564

5665
----
66+
h2. *lists:*
5767

58-
:)
59-
60-
61-
- Simple list
68+
Squared list
6269
- one
6370
- two
6471

65-
* Simple list
72+
Dotted list
6673
* one
6774
* tree
6875
* third
6976

77+
Numbered list
78+
# one
79+
#* borderStyle
80+
#* dasddasd
81+
# two
82+
# :)
83+
84+
----
85+
h2. *table:*
7086

7187
||heading 1||heading 2||heading 3||
7288
|cell A1|cell A2|cell A3|
7389
|cell B1|cell B2|cell B3|
7490

7591

92+
----
93+
h2. *code:*
94+
95+
{code:language=xml|title=test}
96+
<test>
97+
<test1 />
98+
</test>
99+
{code}
76100

77-
{code:language|title=title|borderStyle=solid}
101+
{code:language=sh|title=title|borderStyle=solid}
78102
bash
79103
{code}
80104

105+
{code}code oneline{code}
81106

82-
# one
83-
#* borderStyle
84-
#* dasddasd
85-
# two
86-
# :)
107+
----
108+
h2. *noformat:*
109+
110+
{noformat}
111+
<xml>
112+
</xml>
113+
{noformat}
114+
115+
{noformat}noformat <tag></tag> oneline{noformat}
116+
117+
h1. Ende
87118

88-
h1. Ende
119+
_emphasis_

tsconfig.json

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
{
2-
"compilerOptions": {
3-
"moduleResolution": "node",
4-
"module": "commonjs",
5-
"target": "es5",
6-
"outDir": "out",
7-
"lib": [
8-
"es6"
9-
],
10-
"sourceMap": true,
11-
"rootDir": "."
12-
},
13-
"exclude": [
14-
"node_modules",
15-
".vscode-test"
16-
]
17-
}
1+
{
2+
"compilerOptions": {
3+
"moduleResolution": "node",
4+
"module": "commonjs",
5+
"target": "es5",
6+
"outDir": "out",
7+
"lib": [
8+
"es6"
9+
],
10+
"sourceMap": true,
11+
"rootDir": "./src",
12+
// "strict": true,
13+
},
14+
"exclude": [
15+
"node_modules",
16+
".vscode-test",
17+
"test"
18+
]
19+
}

0 commit comments

Comments
 (0)