Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
yzane committed Oct 26, 2019
2 parents a2abbc0 + 8a3278a commit 14cfe06
Show file tree
Hide file tree
Showing 23 changed files with 1,597 additions and 247 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.history
.vscode-test
node_modules
work/**
*.vsix
Expand Down
19 changes: 12 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
// A launch configuration that launches the extension inside a new window
{
"version": "0.1.0",
"version": "0.2.0",
"configurations": [
{
"name": "Launch Extension",
"name": "Run Extension",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
"stopOnEntry": false
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}"
]
},
{
"name": "Launch Tests",
"name": "Extension Tests",
"type": "extensionHost",
"request": "launch",
"runtimeExecutable": "${execPath}",
"args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/test" ],
"stopOnEntry": false
"args": [
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/test/suite/index"
]
}
]
}
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{
"markdown-pdf.outputDirectory": "sample"
"markdown-pdf.outputDirectory": "sample",
"markdown-pdf.markdown-it-include.enable": false,
"debug.node.autoAttach": "on"
}
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 1.4.0 (2019/10/27)
* Add: Support [mermaid](https://github.com/knsv/mermaid)
* Added mermaid support. [#144](https://github.com/yzane/vscode-markdown-pdf/pull/144)

## 1.3.1 (2019/09/30)
* Update: README
* Update: CHANGELOG
Expand Down
33 changes: 24 additions & 9 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
* [markdown-it-include](https://github.com/camelaissani/markdown-it-include)
* [PlantUML](http://plantuml.com/)
* [markdown-it-plantuml](https://github.com/gmunguia/markdown-it-plantuml)
* [mermaid](http://knsv.github.io/mermaid/)
* [knsv/mermaid](https://github.com/knsv/mermaid)

サンプルファイル
* [pdf](sample/README.pdf)
Expand Down Expand Up @@ -96,6 +98,24 @@ Content of plugins/README.md
Content of CHANGELOG.md
```

### mermaid

INPUT
<pre>
```mermaid
stateDiagram
[*] --> First
state First {
[*] --> second
second --> [*]
}
```
</pre>

OUTPUT

![mermaid](images/mermaid.png)

## インストール

Markdown PDF をインストールして、Visutal Studio Code で Markdownファイルを最初に開いた時、Chromium のダウンロードが自動で始まります。
Expand Down Expand Up @@ -540,15 +560,9 @@ Visual Studio Code の `files.autoGuessEncoding` オプションを使うと、

## [Release Notes](CHANGELOG.md)

### 1.3.1 (2019/09/30)
* Update: README
* Update: CHANGELOG

### 1.3.0 (2019/09/30)
* Add: Support [markdown-it-include](https://github.com/camelaissani/markdown-it-include)
* Integrate markdown-it-include plugin [#138](https://github.com/yzane/vscode-markdown-pdf/pull/138)
* Add: `markdown-pdf.markdown-it-include.enable` option
* Update: README
### 1.4.0 (2019/10/27)
* Add: Support [mermaid](https://github.com/knsv/mermaid)
* Added mermaid support. [#144](https://github.com/yzane/vscode-markdown-pdf/pull/144)


## License
Expand All @@ -569,6 +583,7 @@ MIT
* [markdown-it/markdown-it-container](https://github.com/markdown-it/markdown-it-container)
* [gmunguia/markdown-it-plantuml](https://github.com/gmunguia/markdown-it-plantuml)
* [camelaissani/markdown-it-include](https://github.com/camelaissani/markdown-it-include)
* [knsv/mermaid](https://github.com/knsv/mermaid)

and

Expand Down
33 changes: 24 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ Supports the following features
* [markdown-it-include](https://github.com/camelaissani/markdown-it-include)
* [PlantUML](http://plantuml.com/)
* [markdown-it-plantuml](https://github.com/gmunguia/markdown-it-plantuml)
* [mermaid](http://knsv.github.io/mermaid/)
* [knsv/mermaid](https://github.com/knsv/mermaid)

Sample files
* [pdf](sample/README.pdf)
Expand Down Expand Up @@ -98,6 +100,24 @@ Content of plugins/README.md
Content of CHANGELOG.md
```

### mermaid

INPUT
<pre>
```mermaid
stateDiagram
[*] --> First
state First {
[*] --> second
second --> [*]
}
```
</pre>

OUTPUT

![mermaid](images/mermaid.png)

## Install

Chromium download starts automatically when Markdown PDF is installed and Markdown file is first opened with Visutal Studio Code.
Expand Down Expand Up @@ -546,15 +566,9 @@ Please use the following to insert a page break.

## [Release Notes](CHANGELOG.md)

### 1.3.1 (2019/09/30)
* Update: README
* Update: CHANGELOG

### 1.3.0 (2019/09/30)
* Add: Support [markdown-it-include](https://github.com/camelaissani/markdown-it-include)
* Integrate markdown-it-include plugin [#138](https://github.com/yzane/vscode-markdown-pdf/pull/138)
* Add: `markdown-pdf.markdown-it-include.enable` option
* Update: README
### 1.4.0 (2019/10/27)
* Add: Support [mermaid](https://github.com/knsv/mermaid)
* Added mermaid support. [#144](https://github.com/yzane/vscode-markdown-pdf/pull/144)


## License
Expand All @@ -575,6 +589,7 @@ MIT
* [markdown-it/markdown-it-container](https://github.com/markdown-it/markdown-it-container)
* [gmunguia/markdown-it-plantuml](https://github.com/gmunguia/markdown-it-plantuml)
* [camelaissani/markdown-it-include](https://github.com/camelaissani/markdown-it-include)
* [knsv/mermaid](https://github.com/knsv/mermaid)

and

Expand Down
66 changes: 31 additions & 35 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@ function activate(context) {
init();

var commands = [
vscode.commands.registerCommand('extension.markdown-pdf.settings', function () { MarkdownPdf('settings'); }),
vscode.commands.registerCommand('extension.markdown-pdf.pdf', function () { MarkdownPdf('pdf'); }),
vscode.commands.registerCommand('extension.markdown-pdf.html', function () { MarkdownPdf('html'); }),
vscode.commands.registerCommand('extension.markdown-pdf.png', function () { MarkdownPdf('png'); }),
vscode.commands.registerCommand('extension.markdown-pdf.jpeg', function () { MarkdownPdf('jpeg'); }),
vscode.commands.registerCommand('extension.markdown-pdf.all', function () { MarkdownPdf('all'); })
vscode.commands.registerCommand('extension.markdown-pdf.settings', async function () { await markdownPdf('settings'); }),
vscode.commands.registerCommand('extension.markdown-pdf.pdf', async function () { await markdownPdf('pdf'); }),
vscode.commands.registerCommand('extension.markdown-pdf.html', async function () { await markdownPdf('html'); }),
vscode.commands.registerCommand('extension.markdown-pdf.png', async function () { await markdownPdf('png'); }),
vscode.commands.registerCommand('extension.markdown-pdf.jpeg', async function () { await markdownPdf('jpeg'); }),
vscode.commands.registerCommand('extension.markdown-pdf.all', async function () { await markdownPdf('all'); })
];
commands.forEach(function (command) {
context.subscriptions.push(command);
});

var isConvertOnSave = vscode.workspace.getConfiguration('markdown-pdf')['convertOnSave'];
if (isConvertOnSave) {
var disposable_onsave = vscode.workspace.onDidSaveTextDocument(function () { MarkdownPdfOnSave(); });
var disposable_onsave = vscode.workspace.onDidSaveTextDocument(function () { markdownPdfOnSave(); });
context.subscriptions.push(disposable_onsave);
}
}
Expand All @@ -34,8 +34,8 @@ function deactivate() {
}
exports.deactivate = deactivate;

function MarkdownPdf(option_type) {
async function markdownPdf(option_type) {

try {

// check active window
Expand Down Expand Up @@ -92,7 +92,7 @@ function MarkdownPdf(option_type) {
var text = editor.document.getText();
var content = convertMarkdownToHtml(mdfilename, type, text);
var html = makeHtml(content, uri);
exportPdf(html, filename, type, uri);
await exportPdf(html, filename, type, uri);
} else {
showErrorMessage('MarkdownPdf().2 Supported formats: html, pdf, png, jpeg.');
return;
Expand All @@ -107,7 +107,7 @@ function MarkdownPdf(option_type) {
}
}

function MarkdownPdfOnSave() {
function markdownPdfOnSave() {
try {
var editor = vscode.window.activeTextEditor;
var mode = editor.document.languageId;
Expand Down Expand Up @@ -157,6 +157,11 @@ function convertMarkdownToHtml(filename, type, text) {
html: true,
breaks: breaks,
highlight: function (str, lang) {

if (lang && lang.match(/\bmermaid\b/i)) {
return `<div class="mermaid">${str}</div>`;
}

if (lang && hljs.getLanguage(lang)) {
try {
str = hljs.highlight(lang, str, true).value;
Expand Down Expand Up @@ -320,13 +325,17 @@ function makeHtml(data, uri) {
var filename = path.join(__dirname, 'template', 'template.html');
var template = readFile(filename);

// read mermaid javascripts
var mermaid = readFile(path.join(__dirname, 'node_modules', 'mermaid', 'dist', 'mermaid.min.js'));

// compile template
var mustache = require('mustache');

var view = {
title: title,
style: style,
content: data
content: data,
mermaid: mermaid
};
return mustache.render(template, view);
} catch (error) {
Expand Down Expand Up @@ -359,12 +368,12 @@ function exportPdf(data, filename, type, uri) {
See https://github.com/yzane/vscode-markdown-pdf#install');
return;
}

var StatusbarMessageTimeout = vscode.workspace.getConfiguration('markdown-pdf')['StatusbarMessageTimeout'];
vscode.window.setStatusBarMessage('');
var exportFilename = getOutputDir(filename, uri);

vscode.window.withProgress({
return vscode.window.withProgress({
location: vscode.ProgressLocation.Notification,
title: '[Markdown PDF]: Exporting (' + type + ') ...'
}, async () => {
Expand All @@ -382,18 +391,11 @@ function exportPdf(data, filename, type, uri) {
var tmpfilename = path.join(f.dir, f.name + '_tmp.html');
exportHtml(data, tmpfilename);
var options = {
executablePath: vscode.workspace.getConfiguration('markdown-pdf')['executablePath'] || undefined
}
const browser = await puppeteer.launch(options).catch(error => {
showErrorMessage('puppeteer.launch()', error);
});
const page = await browser.newPage().catch(error => {
showErrorMessage('browser.newPage()', error);
});;
await page.goto(vscode.Uri.file(tmpfilename).toString(), { waitUntil: 'networkidle0' }).catch(error => {
showErrorMessage('page.goto()', error);
});;

executablePath: vscode.workspace.getConfiguration('markdown-pdf')['executablePath'] || puppeteer.executablePath()
};
const browser = await puppeteer.launch(options);
const page = await browser.newPage();
await page.goto(vscode.Uri.file(tmpfilename).toString(), { waitUntil: 'networkidle0' });
// generate pdf
// https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagepdfoptions
if (type == 'pdf') {
Expand Down Expand Up @@ -430,9 +432,7 @@ function exportPdf(data, filename, type, uri) {
left: vscode.workspace.getConfiguration('markdown-pdf')['margin']['left'] || ''
}
}
await page.pdf(options).catch(error => {
showErrorMessage('page.pdf', error);
});
await page.pdf(options);
}

// generate png and jpeg
Expand Down Expand Up @@ -474,9 +474,7 @@ function exportPdf(data, filename, type, uri) {
omitBackground: vscode.workspace.getConfiguration('markdown-pdf')['omitBackground'],
}
}
await page.screenshot(options).catch(error => {
showErrorMessage('page.screenshot()', error);
});
await page.screenshot(options);
}

await browser.close();
Expand Down Expand Up @@ -529,9 +527,7 @@ function isExistsDir(dirname) {

function deleteFile (path) {
var rimraf = require('rimraf')
rimraf(path, function(error) {
if (error) throw error;
});
rimraf.sync(path);
}

function getOutputDir(filename, resource) {
Expand Down
Binary file added images/mermaid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 14cfe06

Please sign in to comment.