Skip to content

Commit add7c63

Browse files
authored
Merge pull request #9 from denco/0.1.3
render headless tables (fix #5), render nested lists (fix #7)
2 parents 350552e + ea34cc3 commit add7c63

File tree

9 files changed

+231
-41
lines changed

9 files changed

+231
-41
lines changed

CHANGELOG.md

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

3+
## 0.1.3
4+
5+
* fix [nested lists](https://github.com/denco/vscode-confluence-markup/issues/7)
6+
* fix [headless table](https://github.com/denco/vscode-confluence-markup/issues/5)
7+
* rendering tables with row headers
8+
39
## 0.1.2
410

511
* fix rendering of tag inside of code macro

package.json

Lines changed: 5 additions & 5 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.2",
4+
"version": "0.1.3",
55
"publisher": "denco",
66
"description": "Confluence markup language support for Visual Studio Code",
77
"keywords": [
@@ -30,14 +30,14 @@
3030
"license": "MIT",
3131
"homepage": "https://github.com/denco/vscode-confluence-markup/blob/master/README.md",
3232
"engines": {
33-
"vscode": "^1.10.0"
33+
"vscode": "^1.20.0"
3434
},
3535
"activationEvents": [
3636
"onCommand:confluence.showPreview",
3737
"onCommand:confluence.showPreviewToSide",
3838
"onLanguage:confluence"
3939
],
40-
"main": "./out/extension",
40+
"main": "./out/src/extension",
4141
"contributes": {
4242
"languages": [
4343
{
@@ -117,11 +117,11 @@
117117
},
118118
"devDependencies": {
119119
"@types/mocha": "^2.2.42",
120-
"@types/node": "^7.0.43",
120+
"@types/node": "^7.0.59",
121121
"eslint": "^4.15.0",
122122
"tslint": "^5.9.1",
123123
"typescript": "^2.6.1",
124-
"vsce": "^1.37.6",
124+
"vsce": "^1.40.0",
125125
"vscode": "^1.1.6"
126126
},
127127
"__metadata": {

resources/css/confluence.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,21 @@ pre > code {
6565
box-shadow: 1px 1px 1px rgba(0,0,0,.25);
6666
line-height: 1.5em;
6767
}
68+
69+
ul {
70+
list-style-type: disc;
71+
}
72+
73+
ul.alternate {
74+
list-style-type: square;
75+
}
76+
77+
ol.initial {
78+
list-style: decimal;
79+
}
80+
ol.initial > ol {
81+
list-style-type: lower-alpha;
82+
}
83+
ol.initial > ol > ol {
84+
list-style-type: lower-roman;
85+
}

src/markupParser.ts

Lines changed: 62 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,18 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
3636

3737
var result = '';
3838
let listTag = '';
39+
let listStyle = '';
3940
let codeTagFlag = 0;
40-
let tableFlag = true;
41+
let tableFlag = false;
42+
let listFlag = false;
43+
let listArr = [];
44+
4145
for (let entry of sourceText.split(/\n/gi)) {
4246
let tag = entry;
4347
let html_tag = false;
4448

4549
if (codeTagFlag == 0) {
4650
tag = tag.replace(/h(\d+)\.\s([^\n]+)/g, "<h$1>$2</h$1>");
47-
tag = tag.replace(/-{4,}/gi, '<hr />');
48-
tag = tag.replace(/-{3}/gi, '&mdash;');
49-
tag = tag.replace(/-{2}/gi, '&ndash;');
5051

5152
// tag = tag.replace(/_([^_]*)_/g, "<em>$1</em>");
5253
tag = tag.replace(/\+([^\+]*)\+/g, "<u>$1</u>");
@@ -92,19 +93,20 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
9293
tag = '<img src="' + imageUri(sourceUri, match[1]) + '"/>';
9394
}
9495

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)) {
96+
//Table
97+
let tab_th_re = /\s*\|{2}.*$/gi;
98+
let tab_td_re = /\s*\|.*$/gi;
99+
if (tag.match(tab_th_re) || tag.match(tab_td_re)) {
100+
tag = tag.replace(/^\|{2,}/, '\|\|');
101+
tag = tag.replace(/^\|{2}/, '<th>');
102+
tag = tag.replace(/\|{2}$/, '</th>');
103+
tag = tag.replace(/\|{2}/gi, '</th><th>');
105104
tag = tag.replace(/^\|/, '<td>');
106105
tag = tag.replace(/\|$/, '</td>');
107106
tag = tag.replace(/\|/gi, '</td><td>');
107+
if (tableFlag == false){
108+
tag = '<table>' + tag;
109+
}
108110
tag = '<tr>' + tag + '</tr>';
109111
tableFlag = true;
110112
}
@@ -133,29 +135,57 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
133135
re = /^([-|\*|#]+)\s(.*)/;
134136
match = tag.match(re);
135137
if (match) {
136-
if (listTag.length === 0) {
137-
if (match[1] == '#') {
138-
listTag = 'ol';
139-
} else {
140-
listTag = 'ul';
141-
if (match[1] == '-') {
142-
listTag += ' style="list-style-type: square;"'
143-
}
138+
listFlag = true;
139+
listStyle = '';
140+
tag = '';
141+
if (match[1].match(/#$/)) {
142+
listTag = 'ol';
143+
// reset ol after 3rd level
144+
// add count of non-ol elements for mixed lists
145+
if ( (match[1].length + (match[1].match(/[-|\*]/g) || []).length) % 3 === 1) {
146+
listStyle = ' class="initial"';
144147
}
145-
tag = '<' + listTag + '>';
146-
} else {
147-
tag = '';
148+
}
149+
if (match[1].match(/[-|\*]$/)) {
150+
listTag = 'ul';
151+
}
152+
if (match[1].match(/-$/)) {
153+
listStyle = ' class="alternate"';
154+
}
155+
if (match[1].length > listArr.length) {
156+
tag = '<'+ listTag + listStyle + '>';
157+
listArr.push(listTag);
158+
}
159+
if (match[1].length < listArr.length) {
160+
// while (listArr.length > match[1].length) {
161+
// tag += '</' + listArr.pop() + '>'
162+
// }
163+
tag = '</' + listArr.slice(match[1].length, listArr.length).reverse().join('></') +'>';
164+
listArr = listArr.slice(0, match[1].length);
148165
}
149166
tag += "<li>" + match[2] + "</li>";
150167
}
151168

152-
if ((tag.length === 0) && (listTag.length !== 0)) {
153-
tag += '</' + listTag + '>';
154-
listTag = '';
169+
170+
if ((tag.length === 0) && (listArr.length > 0)) {
171+
// if ((!listFlag) && (listArr.length > 0)) {
172+
tag = '';
173+
// do {
174+
// tag += '</' + listArr.pop() + '>'
175+
// } while (listArr.length > 0);
176+
tag = '</' + listArr.reverse().join('></') + '>'
177+
listArr = [];
178+
listFlag = false;
155179
}
156180

181+
// hr and dash lines
182+
tag = tag.replace(/-{4,}/gi, '<hr />');
183+
tag = tag.replace(/-{3}/gi, '&mdash;');
184+
tag = tag.replace(/-{2}/gi, '&ndash;');
185+
// strong
157186
tag = tag.replace(/\*([^\*]*)\*/g, "<strong>$1</strong>");
158-
if ((! html_tag) && (! tag.match('<img'))) {
187+
// line-through
188+
if ((!html_tag) && (!tag.match('<img')) && (!listFlag)) {
159189
tag = tag.replace(/-([\w ]*)-/g, "<span style='text-decoration: line-through;'>$1</span>");
160190
tag = tag.replace(/_([\w ]*)_/g, "<i>$1</i>");
161191
}
@@ -168,11 +198,13 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
168198
if (tag.match(/^s*$/)){
169199
tag = '<br />';
170200
}
201+
171202
//close table
172-
if (!tag.match(/<\/tr>$/)){
203+
if (!tag.match(/<\/tr>$/) && tableFlag) {
173204
tag = '</table>' + tag;
174205
tableFlag = false;
175206
}
207+
176208
result += tag;
177209

178210
// console.log("PARSED:" + tag);

test/test.confluence

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,3 @@ h2. *noformat:*
113113
{noformat}
114114

115115
{noformat}noformat <tag></tag> oneline{noformat}
116-
117-
h1. Ende
118-
119-
_emphasis_

test/testfiles/issues.confluence

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
h1. *Issues*
2+
3+
[#3|https://github.com/denco/vscode-confluence-markup/issues/3]
4+
5+
{noformat}
6+
$ date -R -v+1d
7+
Sat, 10 Feb 2018 10:37:39 +0100
8+
{noformat}
9+
10+
[#5|https://github.com/denco/vscode-confluence-markup/issues/5]
11+
12+
h4. Table without heading
13+
14+
|test|test|
15+
|simple table|two|
16+
17+
[#6|https://github.com/denco/vscode-confluence-markup/issues/6]
18+
19+
h4. Header Four
20+
- list one
21+
- list two
22+
- list three
23+
24+
h4. next header (should not be indented)
25+
* list
26+
* list two
27+
28+
h3. third header
29+
- one
30+
- two
31+
32+
[#7|https://github.com/denco/vscode-confluence-markup/issues/7]
33+
34+
* el. 1
35+
** el. 1.1
36+
** el. 1.2

test/testfiles/lists.confluence

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
h1. Lists
2+
3+
# one
4+
# two
5+
## nested one
6+
## nested two
7+
# three
8+
9+
----
10+
# one
11+
# two
12+
## nested one
13+
## nested two
14+
## nested three
15+
### sub sub
16+
### sub sub
17+
#### sub s4
18+
##### sub s5
19+
###### sub s6
20+
####### sub s7
21+
# three
22+
23+
----
24+
* one
25+
* two
26+
** nested one
27+
** nested two
28+
** nested three
29+
*** sub sub
30+
*** sub sub
31+
**** sub s4
32+
***** sub s5
33+
****** sub s6
34+
******* sub s7
35+
* three
36+
37+
----
38+
39+
- one
40+
- two
41+
-- nested one
42+
-- nested two
43+
- three
44+
45+
----
46+
h1. Nested Lists
47+
* one
48+
* two
49+
** nested one
50+
** nested two
51+
* three
52+
53+
----
54+
- one
55+
- two
56+
-- nested one
57+
-- nested two
58+
- three
59+
60+
----
61+
# one
62+
# two
63+
## nested one
64+
## nested two
65+
# three
66+
67+
----
68+
h4. Header Four
69+
- list one
70+
- list two
71+
- list three
72+
h4. Next header (indented)
73+
74+
----
75+
h4. Other Header Four
76+
- list one
77+
- list two
78+
- list three

test/testfiles/tables.confluence

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
h1. Tables
2+
3+
* multiline table
4+
||Heading 1||Heading 2||
5+
|* Item 1\\* Item 2\\* Item 3|# Item 1 \\# Item 2\\# Item 3|
6+
7+
* column heading
8+
||header c1||header c2||
9+
|data 1.1|data 1.2|
10+
|data 2.1|data 2.2|
11+
12+
* row heading
13+
||header r1|data 1.1|data 1.2
14+
||header r2|data 2.1|data 2.2
15+
||header r3|data 3.1|data 3.2
16+
17+
* with column and row heading
18+
|| ||header c1||header c2
19+
||header r1|data 1.1|data 1.2|
20+
||header r2|data 2.1|data 2.2|
21+
22+
* headless
23+
|data 1.1|data 1.2|
24+
|data 2.1|data 2.2|

tsconfig.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
"es6"
99
],
1010
"sourceMap": true,
11-
"rootDir": "./src",
11+
"rootDir": "./",
1212
// "strict": true,
1313
},
1414
"exclude": [
1515
"node_modules",
1616
".vscode-test",
17-
"test"
17+
// "test"
1818
]
1919
}

0 commit comments

Comments
 (0)