diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index 8c0cf12..8fef8c7 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -20,9 +20,9 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: 14.x - name: Install Dependencies diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 58272b7..2a24c07 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,9 +17,9 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@v3 with: node-version: 14.x - name: Install Dependencies diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d639f6..a9c85fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Confluence Wiki Markup +## [1.0.1] + +- modified code/noformat blocks so they can be used in lists to match confluence behaviour +- added support for code block macro titles and themes (only standard themes are supported, and there's no syntax highlighting) +- changed `white-space: normal` to `white-space: pre-wrap` for `pre > code` CSS to match confluence behaviour and commonmark spec (white space is preserved) +- changed test files to accomodate above changes +- updated github workflow actions to v3 + ## [1.0.0](https://github.com/denco/vscode-confluence-markup/releases/tag/1.0.0) - non preview release [1.0.0](https://github.com/denco/vscode-confluence-markup/issues/37) diff --git a/media/css/confluence.css b/media/css/confluence.css index 2d1b90d..88a490f 100644 --- a/media/css/confluence.css +++ b/media/css/confluence.css @@ -48,14 +48,37 @@ table, th, td { padding: 7px; } +.code-block { + display: block; + width: 90%; + border-width: 1px; +} + +.code-title { + display: block; + background:#c6c3c3; + color: black; + font-weight: bold; + border-bottom-color: #ccc; + padding: 5px 10px; + overflow: hidden; + position: relative; +} + +pre { + margin: 0px; +} + pre > code { display: block; background:rgba(0, 0, 0, 0.15); word-wrap: break-word; overflow-wrap: break-word; word-break: break-space; - white-space: normal; - margin: 0px 5px; + /* Confluence allows for indentations and whitespace preservation in code blocks */ + /* white-space: normal; */ + white-space: pre-wrap; + margin: 0px; padding: 5px 1em; line-height: 1.5em; } @@ -84,7 +107,7 @@ pre > code { pre > code > p { - margin: 0px; + margin: .5em 0; } ul { diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index f371e2f..ec2c010 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -1,11 +1,12 @@ { "name": "confluence-markup", - "version": "1.0.0", + "version": "1.0.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "1.0.0", + "name": "confluence-markup", + "version": "1.0.1", "license": "MIT", "devDependencies": { "@types/glob": "^7.1.4", diff --git a/package.json b/package.json index d09db80..f7dacb7 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "confluence-markup", "displayName": "Confluence markup", - "version": "1.0.0", + "version": "1.0.1", "publisher": "denco", "description": "Confluence markup language support for Visual Studio Code", "keywords": [ diff --git a/src/markupParser.ts b/src/markupParser.ts index f919bda..fcc0dcf 100644 --- a/src/markupParser.ts +++ b/src/markupParser.ts @@ -157,22 +157,73 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) { } // code - // online code tag + // oneline code and noformat tag tag = tag.replace(/\{(noformat|code)[^}]*\}(.*)\{(noformat|code)\}/, function (m0, m1, m2) { return `
${m2.replace(/
`; }); - const code_re = /\{(noformat|code)[^}]*\}/; + + // code and noformat tag + const code_re = /\{(noformat|code)([^}]*)\}/; const code_match = tag.match(code_re); if (code_match) { if (! codeTagFlag) { - tag = `
`;
+				let codeBlockStyle = "";
+				// Title style is unecessary for now. It can't be easily customized in Confluence.
+				// let titleStyle = "";
+				tag = tag.replace(code_re, function (m0, m1, m2) {
+					// let res = '
'
+					let res = `
`;
+					const splits = m2.split(/[|:]/);
+					splits.forEach( (el:string) => {
+						const elems = el.split('=');
+						if (elems[0] === "title"){
+							res = `${elems[1]}${res}`;
+							// res = `${elems[1]}${res}`;
+						}
+						// Basic theme matching.
+						if (elems[0] === "theme"){
+							// Predefined confluence themes.
+							switch (elems[1].toLowerCase()) {
+								case "django":
+									codeBlockStyle = `;color:#f8f8f8;background-color:#0a2b1d;`;
+									break;
+								case "emacs":
+									codeBlockStyle = `;color:#d3d3d3;background-color:black;`;
+									break;
+								case "fadetogrey":
+									codeBlockStyle = `;color:white;background-color:#121212;`;
+									break;
+								case "midnight":
+									codeBlockStyle = `;color:#d1edff;background-color:#0f192a;`;
+									break;
+								case "rdark":
+									codeBlockStyle = `;color:#b9bdb6;background-color:#1b2426;`;
+									break;
+								case "eclipse":
+								case "confluence":
+									codeBlockStyle = `;color:white;background-color:black;`;
+								}
+						}
+					});
+					res = `
${res}`; + res = res.replace('$codeBlockStyle', codeBlockStyle); + // res = res.replace('$titleStyle', titleStyle); + return res; + }); codeTagFlag = true; } else { - tag = '
'; + tag = '
'; + //This pays attention to the list flag and adds the closing tag if needed. + if (listFlag) { + tag = `${tag}`; + } codeTagFlag = false; } } + if (codeTagFlag && ! code_match) { + tag = tag.replace(/'; + } const panel_re = /\{panel(.*)}/; if (! codeTagFlag && tag.match(panel_re)) { @@ -251,11 +302,14 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) { panelTagFlag = true; } else { tag = ''; + if (listFlag) { + tag = `${tag}`; + } panelTagFlag = false; } } - if (! codeTagFlag) { + // if (! codeTagFlag) { // lists const li_re = /^([-*#]+)\s(.*)/; const li_match = tag.match(li_re); @@ -285,7 +339,12 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) { tag = ''; listArr = listArr.slice(0, li_match[1].length); } - tag += "
  • " + li_match[2] + "
  • "; + // This prevents the closing tag from being added too prematurely. + if (codeTagFlag || panelTagFlag) { + tag += "
  • " + li_match[2]; + } else { + tag += "
  • " + li_match[2] + "
  • "; + } } @@ -296,10 +355,13 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) { listFlag = false; } + if (! codeTagFlag) { // hr and dash lines tag = tag.replace(/-{4,}/gi, '
    '); tag = tag.replace(/-{3}/gi, '—'); tag = tag.replace(/-{2}/gi, '–'); + } + // strong tag = tag.replace(/\*([^*]*)\*/g, "$1"); // line-through @@ -309,11 +371,12 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) { tag = tag.replace(/\B-((\([^)]*\)|{[^}]*}|\[[^]]+\]){0,3})(\S.*?\S|\S)-\B/g," $3 "); tag = tag.replace(/(?:\b)_((\([^)]*\)|{[^}]*}|\[[^]]+\]){0,3})(\S.*?\S|\S)_(?:\b)/g, "$3"); } - } else { - if (tag !== `
    `) {
    -				tag = tag.replace(/';
    -			}
    -		}
    +		// This only really applied to the inner part of code blocks and noformat blocks, so I moved it there and used a flag to trigger it.
    +		// } else {
    +		// 	if (tag !== `
    `) {
    +		// 		tag = tag.replace(/';
    +		// 	}
    +		// }
     
     		//close table
     		if (!tag.match(/<\/tr>$/) && tableFlag) {
    diff --git a/src/test/suite/fixtures/expected/issues.html b/src/test/suite/fixtures/expected/issues.html
    index 9490d75..24299cd 100644
    --- a/src/test/suite/fixtures/expected/issues.html
    +++ b/src/test/suite/fixtures/expected/issues.html
    @@ -6,16 +6,18 @@ 

    #3: Noformat macro

    -

    -		

    -

    $ date -R -v+1d -
    -

    -

    Sat, 10 Feb 2018 10:37:39 +0100 -
    -

    -

    - +
    +
    +			

    +

    $ date -R -v+1d +
    +

    +

    Sat, 10 Feb 2018 10:37:39 +0100 +
    +

    +

    + +

    #5: Table without heading

    diff --git a/src/test/suite/fixtures/expected/test.html b/src/test/suite/fixtures/expected/test.html index cbab41d..aa75efc 100644 --- a/src/test/suite/fixtures/expected/test.html +++ b/src/test/suite/fixtures/expected/test.html @@ -258,31 +258,37 @@

    -

    -		

    -

    <test> -
    -

    -

    <test1 /> -
    -

    -

    </test> -
    -

    -

    - +
    + test +
    +			

    +

    <test> +
    +

    +

    <test1 /> +
    +

    +

    </test> +
    +

    +

    + +

    -

    -		

    -

    bash -
    -

    -

    echo very long command line with a lot of sings to check word wrap and how it looks like && echo much more elements to print -
    -

    -

    - +
    + title +
    +			

    +

    bash +
    +

    +

    echo very long command line with a lot of sings to check word wrap and how it looks like && echo much more elements to print +
    +

    +

    + +

    @@ -297,16 +303,18 @@ 

    -

    -		

    -

    <xml> -
    -

    -

    </xml> -
    -

    -

    - +
    +
    +			

    +

    <xml> +
    +

    +

    </xml> +
    +

    +

    + +