Skip to content

Commit 11ccd8e

Browse files
authored
Merge pull request #26 from denco/feature/issue_22
Feature/issue 22
2 parents cdfc58c + 1d8f18c commit 11ccd8e

File tree

4 files changed

+137
-4
lines changed

4 files changed

+137
-4
lines changed

media/css/confluence.css

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,29 @@ pre>code {
7979
line-height: 1.5em;
8080
}
8181

82+
83+
.panel {
84+
display: inline-block;
85+
width: 90%;
86+
color: black;
87+
margin: 0px;
88+
background-color: lightslategrey;
89+
border-width: 1px;
90+
91+
}
92+
93+
.panel-title {
94+
font-weight: bold;
95+
padding: 5px;
96+
border-bottom: none;
97+
}
98+
99+
.panel-body {
100+
background-color: lightgrey;
101+
padding: 3px;
102+
}
103+
104+
82105
pre > code > p {
83106
margin: 0px
84107
}

src/markupParser.ts

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
4949
let listTag = '';
5050
let listStyle = '';
5151
let codeTagFlag = false;
52+
let panelTagFlag = false;
5253
let tableFlag = false;
5354
let listFlag = false;
5455
let listArr: string[] = [];
@@ -98,7 +99,6 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
9899
let esc_href = /\[\s*([^|]*)?\|?([^|].*)[\s+|\\]\]/g
99100
if (tag.match(re_href)) {
100101
tag = tag.replace(re_href, function (m0, m1, m2) {
101-
console.log(`aaa: >${m1}<, >${m2}<`);
102102
if ((m1.length !== 0) && (m2.length !== 0)) {
103103
return "<a href='" + m2 + "'>" + m1 + "</a>";
104104
} else {
@@ -117,8 +117,8 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
117117
}
118118

119119
//Table
120-
let tab_th_re = /\s*\|{2}.*$/gi;
121-
let tab_td_re = /\s*\|.*$/gi;
120+
let tab_th_re = /\s*[^{]*\|{2}[^}]*$/gi;
121+
let tab_td_re = /\s*[^{]*\|[^}]*$/gi;
122122
if (!html_tag && (tag.match(tab_th_re) || tag.match(tab_td_re))) {
123123
tag = tag.replace(/^\|{2,}/, '\|\|');
124124
tag = tag.replace(/^\|{2}/, '<th>');
@@ -153,6 +153,87 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
153153
}
154154
}
155155

156+
let panel_re = /\{panel(.*)}/;
157+
if (tag.match(panel_re)) {
158+
if (! panelTagFlag) {
159+
let panelStyle = "";
160+
let titleStyle = "";
161+
tag = tag.replace(panel_re, function (m0, m1, m2) {
162+
let res = '<div class="panel panel-body" $panelStyle>'
163+
let splits=m1.split(/[\|:]/);
164+
splits.forEach( (el:String) => {
165+
let elems = el.split('=');
166+
if (elems[0] === "title"){
167+
res = `<div class="panel panel-title" $titleStyle>${elems[1]}</div>${res}`;
168+
}
169+
if (elems[0] === "titleBGColor"){
170+
if (titleStyle.length === 0) {
171+
titleStyle = `style='background-color: ${elems[1]};`;
172+
} else {
173+
titleStyle += ` background-color: ${elems[1]};`;
174+
}
175+
}
176+
if (elems[0] === "bgColor"){
177+
if (panelStyle.length === 0) {
178+
panelStyle = `style='background-color: ${elems[1]};`;
179+
} else {
180+
panelStyle += ` background-color: ${elems[1]};`;
181+
}
182+
}
183+
if (elems[0] === "borderStyle"){
184+
if (panelStyle.length === 0) {
185+
panelStyle = `style='border-style: ${elems[1]}; `;
186+
} else {
187+
panelStyle += ` border-style: ${elems[1]}; `;
188+
}
189+
if (titleStyle.length === 0) {
190+
titleStyle = `style='border-style: ${elems[1]}; border-bottom:none; `;
191+
} else {
192+
titleStyle += ` border-style: ${elems[1]}; border-bottom:none; `;
193+
}
194+
}
195+
if (elems[0] === "borderColor"){
196+
if (panelStyle.length === 0) {
197+
panelStyle = `style='border-color: ${elems[1]}; `;
198+
} else {
199+
panelStyle += ` border-color: ${elems[1]}; `;
200+
}
201+
if (titleStyle.length === 0) {
202+
titleStyle = `style='border-color: ${elems[1]}; `;
203+
} else {
204+
titleStyle += ` border-color: ${elems[1]}; `;
205+
}
206+
}
207+
if (elems[0] === "borderWidth"){
208+
if (panelStyle.length === 0) {
209+
panelStyle = `style='border-width: ${elems[1]}; `;
210+
} else {
211+
panelStyle += ` border-width: ${elems[1]}; `;
212+
}
213+
if (titleStyle.length === 0) {
214+
titleStyle = `style='border-width: ${elems[1]}; `;
215+
} else {
216+
titleStyle += ` border-width: ${elems[1]}; `;
217+
}
218+
}
219+
});
220+
if (titleStyle.length >= 0) {
221+
titleStyle += `'`;
222+
}
223+
if (panelStyle.length >= 0) {
224+
panelStyle += `'`;
225+
}
226+
res = res.replace('$panelStyle', panelStyle);
227+
res = res.replace('$titleStyle', titleStyle);
228+
return res;
229+
});
230+
panelTagFlag = true;
231+
} else {
232+
tag = '</div>';
233+
panelTagFlag = false;
234+
}
235+
}
236+
156237
if (! codeTagFlag) {
157238
// lists
158239
re = /^([-|\*|#]+)\s(.*)/;
@@ -216,7 +297,6 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
216297
tag = '</table>' + tag;
217298
tableFlag = false;
218299
}
219-
console.log(tag);
220300
result += "<p>" + tag + "</p>";
221301
}
222302

src/test/testfiles/nix/issues.confluence

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ This is a {{test}} of how things work with {{confluence}} markup.
6060

6161
_Blah blah blah._
6262

63+
[#22|https://github.com/denco/vscode-confluence-markup/issues/22] panel support
64+
65+
{panel}
66+
Some text
67+
{panel}
68+
69+
{panel:title=My Title}
70+
Some text with a title
71+
{panel}
72+
73+
{panel:title=My Title|borderStyle=dashed|borderColor=#ccc|titleBGColor=#F7D6C1|bgColor=#FFFFCE}
74+
a block of text surrounded with a *panel*
75+
yet _another_ line
76+
{panel}
77+
6378
[#24|https://github.com/denco/vscode-confluence-markup/issues/24]: Can't use [ and ] in string
6479

6580
[lalala]

src/test/testfiles/win/issues.confluence

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,21 @@ This is a {{test}} of how things work with {{confluence}} markup.
6060

6161
_Blah blah blah._
6262

63+
[#22|https://github.com/denco/vscode-confluence-markup/issues/22] panel support
64+
65+
{panel}
66+
Some text
67+
{panel}
68+
69+
{panel:title=My Title}
70+
Some text with a title
71+
{panel}
72+
73+
{panel:title=My Title|borderStyle=dashed|borderColor=#ccc|titleBGColor=#F7D6C1|bgColor=#FFFFCE}
74+
a block of text surrounded with a *panel*
75+
yet _another_ line
76+
{panel}
77+
6378
[#24|https://github.com/denco/vscode-confluence-markup/issues/24]: Can't use [ and ] in string
6479

6580
[lalala]

0 commit comments

Comments
 (0)