Skip to content

Commit

Permalink
Merge pull request #4 from denco/fix-0.1.2
Browse files Browse the repository at this point in the history
Fix 0.1.2
  • Loading branch information
denco authored Mar 29, 2018
2 parents 4ee0f71 + ecf1cd3 commit 350552e
Show file tree
Hide file tree
Showing 8 changed files with 176 additions and 72 deletions.
8 changes: 8 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
"type": "npm",
"script": "compile",
"problemMatcher": []
},
{
"type": "typescript",
"tsconfig": "tsconfig.json",
"option": "watch",
"problemMatcher": [
"$tsc-watch"
]
}
]
}
13 changes: 13 additions & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
**/*.ts
**/tsconfig.json
**/*.map
**/*.bak
*.vsix
.gitignore
.vscode/**
.vscode-test/**
tsconfig.json
package-lock.json
test/**
node_modules/**
typings/**
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Confluence Wiki Markup

## 0.1.2

* fix rendering of tag inside of code macro
* fix [noformat issue](https://github.com/denco/vscode-confluence-markup/issues/3)
* fix strikethrough and italic text
* add table rendering

## 0.1.1

* fix simple link
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "confluence-markup",
"displayName": "Confluence markup",
"version": "0.1.1",
"version": "0.1.2",
"publisher": "denco",
"description": "Confluence markup language support for Visual Studio Code",
"keywords": [
Expand Down Expand Up @@ -37,7 +37,7 @@
"onCommand:confluence.showPreviewToSide",
"onLanguage:confluence"
],
"main": "./out/src/extension",
"main": "./out/extension",
"contributes": {
"languages": [
{
Expand Down Expand Up @@ -116,13 +116,13 @@
"test": "npm run compile && node ./node_modules/vscode/bin/test"
},
"devDependencies": {
"@types/mocha": "^2.2.42",
"@types/node": "^7.0.43",
"eslint": "^4.15.0",
"tslint": "^5.9.1",
"typescript": "^2.6.1",
"vsce": "^1.35.0",
"vscode": "^1.1.6",
"@types/node": "^7.0.43",
"@types/mocha": "^2.2.42"
"vsce": "^1.37.6",
"vscode": "^1.1.6"
},
"__metadata": {
"publisherDisplayName": "denco"
Expand Down
5 changes: 5 additions & 0 deletions resources/css/confluence.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ blockquote {
border-left: 5px solid;
}

table, th, td {
border: 1px solid;
border-collapse: collapse;
}

pre > code {
display: inline-block;
width: 90%;
Expand Down
68 changes: 53 additions & 15 deletions src/markupParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
//TODO: use Tokenazer instead of line loop

var result = '';

let listTag = '';
let codeTagFlag = 0;
let tableFlag = true;
for (let entry of sourceText.split(/\n/gi)) {
let tag = entry;
let html_tag = false;

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

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

let re = /\[([^|]*)?\|?([^|]*)\]/g
if (tag.match(re)) {
tag = tag.replace(re, function (m0, m1, m2) {
if ((m1.length !== 0) && (m2.length !== 0)) {
return "<a href='" + m2 + "'>" + m1 + "</a>";
} else {
return "<a href='" + m1 + "'>" + m1 + "</a>";
}
});
html_tag = true;
}
//img
let img = /!(.*)!/;
let match = tag.match(img);
if (match) {
tag = '<img src="' + imageUri(sourceUri, match[1]) + '"/>';
}

//table
let tab_th_re = /\s*\|\|.*\|\|$/gi;
let tab_td_re = /\s*\|.*\|$/gi;
if (tag.match(tab_th_re)) {
tag = tag.replace(/^\|\|/, '<th>');
tag = tag.replace(/\|\|$/, '</th>');
tag = tag.replace(/\|\|/gi, '</th><th>');
tag = '<table><tr>' + tag + '</tr>';
tableFlag = true;
} else if (tag.match(tab_td_re)) {
tag = tag.replace(/^\|/, '<td>');
tag = tag.replace(/\|$/, '</td>');
tag = tag.replace(/\|/gi, '</td><td>');
tag = '<tr>' + tag + '</tr>';
tableFlag = true;
}
}

// code
// online code tag
tag = tag.replace(/\{code[^\}]*\}(.*)\{code\}/, "<pre><code>$1</code></pre>");
let re = /\{code.*\}/;
tag = tag.replace(/\{(noformat|code)[^\}]*\}(.*)\{(noformat|code)\}/, function (m0, m1, m2) {
return "<pre><code>" + m2.replace(/</gi, '&lt;') + "</code></pre>";
});

let re = /\{[(code)|(noformat)].*\}/;
let match = tag.match(re);
if (match) {
if (codeTagFlag === 0) {
Expand Down Expand Up @@ -130,13 +155,26 @@ export async function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
}

tag = tag.replace(/\*([^\*]*)\*/g, "<strong>$1</strong>");
tag = tag.replace(/\B-(\w*)-\B/g, "<span style='text-decoration: line-through;'>striket-hrough</span>");
}
if (tag === '<pre><code>') {
result += tag;
if ((! html_tag) && (! tag.match('<img'))) {
tag = tag.replace(/-([\w ]*)-/g, "<span style='text-decoration: line-through;'>$1</span>");
tag = tag.replace(/_([\w ]*)_/g, "<i>$1</i>");
}
} else {
result += tag + '<br />';
if (tag !== '<pre><code>'){
tag = tag.replace(/</gi, '&lt;') + '<br />';
}
}

if (tag.match(/^s*$/)){
tag = '<br />';
}
//close table
if (!tag.match(/<\/tr>$/)){
tag = '</table>' + tag;
tableFlag = false;
}
result += tag;

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

Expand Down
99 changes: 65 additions & 34 deletions test/test.confluence
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@

h1. *Examples*

----
h2. *headers:*

h1. Header 1
h2. Header 2
h3. Header 3
h4. Header 4
h5. Header 5
h6. Header 6

----
h2. *smiles:*

* :) smile :)
* :( sad :(
* :P tongue
Expand All @@ -10,41 +26,34 @@
* (x)
* (!)

examples:
----
h2. *Links:*

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


(!)

// Confluence

h1. Header 1

h2. Header 2

h3. Header 3

h4. Header 4

h5. Header 5


h2. Text Effects
----
h2. *text effects:*

*strong*

*bold text*

_emphasis_
_italics_ : Thing{_}x_

_italics_ : Thing_x_

_italics with spaces_

??citation?? \\
-del eted- \\
+inserted+ \\

-deleted- \\
-deleted with spaces- \\
+inserted+ \\
Text with ^superscript^ : kg/m^3^

Text with ~subscript~

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

----
h2. *lists:*

:)


- Simple list
Squared list
- one
- two

* Simple list
Dotted list
* one
* tree
* third

Numbered list
# one
#* borderStyle
#* dasddasd
# two
# :)

----
h2. *table:*

||heading 1||heading 2||heading 3||
|cell A1|cell A2|cell A3|
|cell B1|cell B2|cell B3|


----
h2. *code:*

{code:language=xml|title=test}
<test>
<test1 />
</test>
{code}

{code:language|title=title|borderStyle=solid}
{code:language=sh|title=title|borderStyle=solid}
bash
{code}

{code}code oneline{code}

# one
#* borderStyle
#* dasddasd
# two
# :)
----
h2. *noformat:*

{noformat}
<xml>
</xml>
{noformat}

{noformat}noformat <tag></tag> oneline{noformat}

h1. Ende

h1. Ende
_emphasis_
36 changes: 19 additions & 17 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{
"compilerOptions": {
"moduleResolution": "node",
"module": "commonjs",
"target": "es5",
"outDir": "out",
"lib": [
"es6"
],
"sourceMap": true,
"rootDir": "."
},
"exclude": [
"node_modules",
".vscode-test"
]
}
{
"compilerOptions": {
"moduleResolution": "node",
"module": "commonjs",
"target": "es5",
"outDir": "out",
"lib": [
"es6"
],
"sourceMap": true,
"rootDir": "./src",
// "strict": true,
},
"exclude": [
"node_modules",
".vscode-test",
"test"
]
}

0 comments on commit 350552e

Please sign in to comment.