Skip to content

Commit

Permalink
Merge pull request #21 from denco/0.1.8
Browse files Browse the repository at this point in the history
0.1.8
  • Loading branch information
denco authored Nov 14, 2019
2 parents 56ab07d + 966a646 commit 201a0d8
Show file tree
Hide file tree
Showing 18 changed files with 1,037 additions and 43 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"version": "0.1.0",
"configurations": [
{
"name": "Debug extension Extension",
"name": "Debug extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Confluence Wiki Markup

## [0.1.8](https://github.com/denco/vscode-confluence-markup/releases/tag/0.1.8)

- fix [Multiply inline monospace macro](https://github.com/denco/vscode-confluence-markup/issues/17)
- fix [Italic with dot at the end](https://github.com/denco/vscode-confluence-markup/issues/18)
- fix rendering striked-throu markup
- adjust content security policy
- add downloads badge in [README.MD](https://github.com/denco/vscode-confluence-markup/blob/master/README.md)

## [0.1.7](https://github.com/denco/vscode-confluence-markup/releases/tag/0.1.7)

- fix skip empty lines
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![The MIT License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://github.com/denco/vscode-confluence-markup/blob/master/LICENSE)
[![Version](https://vsmarketplacebadge.apphb.com/version-short/denco.confluence-markup.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=denco.confluence-markup)
[![Installs](https://vsmarketplacebadge.apphb.com/installs-short/denco.confluence-markup.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=denco.confluence-markup)
[![Downloads](https://vsmarketplacebadge.apphb.com/downloads-short/denco.confluence-markup.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=denco.confluence-markup)
[![Rating](https://vsmarketplacebadge.apphb.com/rating-short/denco.confluence-markup.svg?style=flat-square)](https://marketplace.visualstudio.com/items?itemName=denco.confluence-markup)

## Description
Expand Down
10 changes: 5 additions & 5 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.7",
"version": "0.1.8",
"publisher": "denco",
"description": "Confluence markup language support for Visual Studio Code",
"keywords": [
Expand Down Expand Up @@ -30,7 +30,7 @@
"license": "MIT",
"homepage": "https://github.com/denco/vscode-confluence-markup/blob/master/README.md",
"engines": {
"vscode": "^1.25.0"
"vscode": "^1.40.0"
},
"activationEvents": [
"onCommand:confluence.showPreview",
Expand Down Expand Up @@ -132,12 +132,12 @@
},
"devDependencies": {
"@types/mocha": "^5.2.7",
"@types/node": "^11.13.9",
"eslint": "^5.16.0",
"@types/node": "^12.12.7",
"tslint": "^5.18.0",
"typescript": "^3.5.3",
"vsce": "^1.66.0",
"vscode": "^1.1.36"
"vscode": "^1.1.36",
"html-formatter": "^0.1.9"
},
"__metadata": {
"publisherDisplayName": "denco"
Expand Down
22 changes: 4 additions & 18 deletions src/ConfluenceContentProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';

import { parseMarkup, cssUri } from './markupParser';
import {parseMarkup} from './markupParser';

export function packConfluenceUri(uri: vscode.Uri) {
// Temporarily change the URI scheme
Expand Down Expand Up @@ -40,24 +40,10 @@ export class ConfluenceContentProvider implements vscode.TextDocumentContentProv
}

public async provideTextDocumentContent(uri: vscode.Uri): Promise<string> {
let document = await vscode.workspace.openTextDocument(unpackConfluenceUri(uri));
let body = await parseMarkup(unpackConfluenceUri(uri), document.getText());
let cssLink = cssUri("confluence.css");
const document = await vscode.workspace.openTextDocument(unpackConfluenceUri(uri));
const body = await parseMarkup(unpackConfluenceUri(uri), document.getText());


// Security
// https://code.visualstudio.com/api/extension-guides/webview#security
return `<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<meta http-equiv="Content-Security-Policy" content="default-src 'none'; style-src 'self' 'unsafe-inline'; img-src vscode-resource: https:; script-src vscode-resource:; style-src vscode-resource:;"/>
<link rel="stylesheet" href="${cssLink}">
</head>
<body>
${body}
</body>
</html>`;
return body
}

get onDidChange(): vscode.Event<vscode.Uri> {
Expand Down
30 changes: 29 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,37 @@ import { packConfluenceUri, unpackConfluenceUri, ConfluenceContentProvider } fro

const path = require('path');

import {cssUri} from './markupParser';


function getRenderedContent(contentProvider: ConfluenceContentProvider, uri: vscode.Uri, panel: vscode.WebviewPanel) {
contentProvider.provideTextDocumentContent(packConfluenceUri(uri)).then((renderedContent) => {
panel.webview.html = renderedContent;
// Security
// https://code.visualstudio.com/api/extension-guides/webview#security

const cssFile = cssUri('confluence.css')
let cssLink = ""
if (cssFile) {
const cssUrl = panel.webview.asWebviewUri(cssFile)
cssLink = `<link rel="stylesheet" href="${cssUrl}">`
}

panel.webview.html = `<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Security-Policy"
content="default-src 'none';
img-src self vscode-resource: https:;
script-src self vscode-resource:;
style-src 'unsafe-inline' self vscode-resource:;"/>
${cssLink}
</head>
<body>
${renderedContent}
</body>
</html>`;
}, (reason) => {
vscode.window.showErrorMessage(reason);
});
Expand Down
19 changes: 11 additions & 8 deletions src/markupParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,22 @@ function imageUri(searchUri: vscode.Uri, imageLink: string) {
}

function getUri(filepath: string, filename: string) {
let extension = vscode.extensions.getExtension(EXTENTION_ID);
const extension = vscode.extensions.getExtension(EXTENTION_ID);
if (extension) {
let extPath = extension.extensionPath;
const extPath = extension.extensionPath;

// set special chema for resource:
// https://code.visualstudio.com/api/extension-guides/webview#loading-local-content
let uri = vscode.Uri.file(path.join(extPath, filepath, filename)).with({ scheme: 'vscode-resource' });
return uri;
const uri = vscode.Uri.file(path.join(extPath, filepath, filename))
return uri
}
}

function emoticonUri(emoticonFile: string) {
return getUri(EMOTICON_PATH, emoticonFile);
const emoticonUrl = getUri(EMOTICON_PATH, emoticonFile)
if (emoticonUrl) {
return emoticonUrl.with({scheme: 'vscode-resource'});
}
}

export function cssUri(cssFile: string) {
Expand Down Expand Up @@ -69,7 +72,7 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
tag = tag.replace(/\+([^\+]*)\+/g, "<u>$1</u>");
tag = tag.replace(/\^([^\^]*)\^/g, "<sup>$1</sup>");
tag = tag.replace(/~([^~]*)~/g, "<sub>$1</sub>");
tag = tag.replace(/\{{2}(.*)\}{2}/g, `<code style='font-family: ${MONOSPACE_FONT_FAMILY}'>$1</code>`);
tag = tag.replace(/\{{2}([^\{{2}]*)\}{2}/g, `<code style='font-family: ${MONOSPACE_FONT_FAMILY}'>$1</code>`);
tag = tag.replace(/\?{2}(.*)\?{2}/g, "<cite>$1</cite>");
tag = tag.replace(/\{color:(\w+)\}(.*)\{color\}/g, "<span style='color:$1;'>$2</span>");

Expand Down Expand Up @@ -195,8 +198,8 @@ export function parseMarkup(sourceUri: vscode.Uri, sourceText: string) {
tag = tag.replace(/\*([^\*]*)\*/g, "<strong>$1</strong>");
// line-through
if ((!html_tag) && (!tag.match('<img')) && (!listFlag)) {
tag = tag.replace(/-([\w ]*)-/g, "<span style='text-decoration: line-through;'>$1</span>");
tag = tag.replace(/_([\w ]*)_/g, "<i>$1</i>");
tag = tag.replace(/\B-([^-]*)-\B/g, " <span style='text-decoration: line-through;'>$1</span> ");
tag = tag.replace(/_([^_]*)_/g, "<i>$1</i>");
}
} else {
if (tag !== `<pre><code style='font-family: ${MONOSPACE_FONT_FAMILY}'>`) {
Expand Down
7 changes: 5 additions & 2 deletions src/test/markupParser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import * as path from 'path';
import { parseMarkup, cssUri } from '../markupParser';
import * as fs from 'fs';

const HTML_FORMATTER = require('html-formatter');

const TEST_FILES_ROOT = path.join(__dirname, "../../src/test/testfiles");
const FIXTURES_ROOT = path.join(__dirname, "../../src/test/resources/fixtures");

Expand All @@ -26,7 +28,7 @@ suite("markupParser Tests", function () {

// Defines a Mocha unit test
test("Test CSS Uri", function () {
const expected = vscode.Uri.file(path.join(__dirname, "../../media/css/dummy.css")).with({ "scheme": 'vscode-resource' });
const expected = vscode.Uri.file(path.join(__dirname, "../../media/css/dummy.css"));
const css = cssUri("dummy.css");
assert.notEqual(css, undefined);
if (css) {
Expand Down Expand Up @@ -54,7 +56,8 @@ suite("markupParser Tests", function () {
const testFileUri = vscode.Uri.file(fullFilePath);
const confluenceContent = fs.readFileSync(testFileUri.fsPath, 'utf8');

assert.equal(parseMarkup(testFileUri, confluenceContent), fixtureContent);
const parsedMarkup = HTML_FORMATTER.render(parseMarkup(testFileUri, confluenceContent))
assert.equal(parsedMarkup, fixtureContent);
});
});
});
29 changes: 28 additions & 1 deletion src/test/resources/fixtures/issue_6.html
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
<p><h1>TITLE</h1></p><p><h2>Section One</h2></p><p>Section one.</p><p><h2>Section Two</h2></p><p>Section two.</p><p><ol class="initial"><li>Numbered List 1</li></p><p><li>Numbered List 2</li></p><p></ol></p><p><h2>Section Three</h2></p><p>Section three.</p><p><h2>Section Four</h2></p><p>Section four.</p>
<p>
<h1>TITLE</h1>
</p>
<p>
<h2>Section One</h2>
</p>
<p>Section one.</p>
<p>
<h2>Section Two</h2>
</p>
<p>Section two.</p>
<p>
<ol class="initial">
<li>Numbered List 1</li>
</p>
<p>
<li>Numbered List 2</li>
</p>
<p></ol>
</p>
<p>
<h2>Section Three</h2>
</p>
<p>Section three.</p>
<p>
<h2>Section Four</h2>
</p>
<p>Section four.</p>
Loading

0 comments on commit 201a0d8

Please sign in to comment.