Skip to content

Commit

Permalink
Add custom font size and fixed not auto found setup path of chrome.
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhui committed Jan 16, 2020
1 parent 0b20324 commit 09fad28
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 11 deletions.
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ MDPS converte markdown content to html that using the [@jhuix/showdowns](https:/

![features-gif](https://jhuix.github.io/vscode-markdown-preview-showdown/screenshot/mdps.gif)

[@jhuix/Showdowns](https://github.com/jhuix/showdowns) is a lib that make markdown to html with some extensions of [showdown.js](https://github.com/showdownjs/showdown). And [showdown.js](https://github.com/showdownjs/showdown) is a Javascript Markdown to HTML converter, based on the original works by John Gruber. For more information, refer to the following document:
[@jhuix/showdowns](https://github.com/jhuix/showdowns) is a lib that make markdown to html with some extensions of [showdown.js](https://github.com/showdownjs/showdown). And showdown.js is a Javascript Markdown to HTML converter, based on the original works by John Gruber. For more information, refer to the following document:

- [Showdowns Features Syntax](https://github.com/jhuix/showdowns/blob/master/public/showdowns-features.md)
- [Showdowns Readme](https://github.com/jhuix/showdowns/blob/master/README.md)
Expand All @@ -24,15 +24,19 @@ MDPS converte markdown content to html that using the [@jhuix/showdowns](https:/

## Requirements

For export PDF or PNG or JPEG:
- For local rendering plantuml

When local rendering plantuml requires `Java` support, so [Java environment (JDK or JRE)](https://www.oracle.com/technetwork/java/javase/downloads/index.html) needs to be installed and the Java executor directory needs to be set to the global path environment variable.

When `markdown-preview-showdown.usePuppeteerCore` setting is true, this extension require puppeteer-core package (It has been integrated into the MDPS extension) and google chrome browser or chrome-location package, and `chrome.exe` program path is set to `markdown-preview-showdown.chromePath`. The chrome-location globally installed by npm:
- For export PDF or PNG or JPEG:

npm install -g chrome-location
When `markdown-preview-showdown.usePuppeteerCore` setting is true, this extension require puppeteer-core package (It has been integrated into the MDPS extension) and google chrome browser or chrome-location package, and `chrome.exe` program path is set to `markdown-preview-showdown.chromePath`. The chrome-location globally installed by npm:

When `markdown-preview-showdown.usePuppeteerCore` setting is false, this extension require puppeteer package. The puppeteer globally installed by npm:
npm install -g chrome-location

npm install -g puppeteer
When `markdown-preview-showdown.usePuppeteerCore` setting is false, this extension require puppeteer package. The puppeteer globally installed by npm:

npm install -g puppeteer


## Install from VS Code (Recommended)
Expand All @@ -51,6 +55,10 @@ This extension contributes the following settings:

Flavor of preview html page, you can choose one from ["github", "ghost", "vanilla"], default is "github" flavor.

* `markdown-preview-showdown.fontSize`:

Custom font size of preview page, default "14" px.

* `markdown-preview-showdown.scrollSync`:

Automatic scroll sync, default true.
Expand Down
9 changes: 7 additions & 2 deletions docs/release-notes.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
# Release Notes

## v1.2.1
1. Add custom font size setting of preview page, default "14" px.

2. Fixed not auto found setup path of chrome in windows platform.

## v1.2.0
1. Update [@jhuix/showdowns](https://github.com/jhuix/showdowns) v0.4.0:

- Add render diagram mode is asynchronous using promise-resolve, but exclude showdown-sequence.

2. When rendering a diagram (exclude js-sequence diagram), the page diagram does not flicker.

3. Add render mode setting of plantuml diagram, can choose from 'local' or 'remote';
3. Add render mode setting of plantuml diagram, can choose from 'local' or 'remote'.

4. Add remote render website setting of plantuml diagram;
4. Add remote render website setting of plantuml diagram.

## v1.1.8

Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
"default": false,
"type": "boolean"
},
"markdown-preview-showdown.fontSize": {
"description": "%mdps.fontSize%",
"default": 14,
"type": "number"
},
"markdown-preview-showdown.scrollSync": {
"description": "%mdps.scrollSync%",
"default": true,
Expand Down
1 change: 1 addition & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"mdps.title": "MDPS - MarkDown Preview Showdown",
"mdps.openPreview": "Preview MD File",
"mdps.autoPreview": "Automatic preview markdown file.",
"mdps.fontSize": "Custom font size of preview page.",
"mdps.scrollSync": "Automatic scroll sync.",
"mdps.maxContentSize": "When markdown content or html content size exceeds 'maxContentSize' value, compress the content with brotli during message transmission.",
"mdps.mermaidTheme": "Mermaid theme, you can choose one from [\"default\", \"dark\", \"forest\", \"neutral\"]",
Expand Down
1 change: 1 addition & 0 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"mdps.title": "MDPS - MarkDown文件预览",
"mdps.openPreview": "预览MD文件",
"mdps.autoPreview": "自动预览markdown文件.",
"mdps.fontSize": "预览页面的自定义字体大小.",
"mdps.scrollSync": "自动同步滚屏.",
"mdps.maxContentSize": "当预览markdown内容以及导出文件情况下, 并且插件与预览页面之间的传递内容大小超过该值定义的最大阈值时,传递内容会使用brotli进行压缩后传输, 默认值为32768(32K)字节.",
"mdps.mermaidTheme": "渲染Mermaid图表的主题式样, 可选择项为[\"default\", \"dark\", \"forest\", \"neutral\"], 默认主题为\"default\"",
Expand Down
5 changes: 5 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class PreviewConfig {

public locale: string;
public autoPreview: boolean;
public fontSize: number;
public scrollSync: boolean;
public maxContentSize: number;
public mermaidTheme: string;
Expand Down Expand Up @@ -48,6 +49,9 @@ export class PreviewConfig {
let tempNumber: number | undefined = config.get('maxContentSize');
this.maxContentSize = typeof tempNumber === 'undefined' ? Math.pow(8, 5) : tempNumber;

tempNumber = config.get('fontSize');
this.fontSize = typeof tempNumber === 'undefined' ? Math.pow(8, 5) : tempNumber;

let tmpStr: string | undefined = config.get('mermaidTheme');
this.mermaidTheme = typeof tmpStr === 'undefined' ? '' : tmpStr;

Expand All @@ -70,6 +74,7 @@ export class PreviewConfig {
this.puppeteerWaitForTimeout = typeof tmpNum === 'undefined' ? 0 : tmpNum;
} else {
this.autoPreview = false;
this.fontSize = 14;
this.scrollSync = true;
this.maxContentSize = Math.pow(8, 5);
this.mermaidTheme = 'default';
Expand Down
17 changes: 14 additions & 3 deletions src/previewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ export class ShowdownPreviewer {
border: none;
}
html {
font-size: 16px;
font-size: ${this.config.fontSize}px;
line-height: 1.6;
overflow: initial;
box-sizing: border-box;
Expand All @@ -381,7 +381,6 @@ export class ShowdownPreviewer {
body {
color: #333;
background: #f9f9f9;
font-size: 16px;
min-height: 100%;
position: relative;
font-family: Helvetica Neue, NotoSansHans-Regular, AvenirNext-Regular, arial, Hiragino Sans GB, Microsoft Yahei, WenQuanYi Micro Hei, Arial, Helvetica, sans-serif;
Expand Down Expand Up @@ -518,6 +517,7 @@ export class ShowdownPreviewer {
if (this.config.usePuppeteerCore) {
puppeteer = require('puppeteer-core');
if (!this.config.chromePath && process.platform === 'win32') {
// First find setup path of chrome from HKLM
await utils
.regQuery('HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe')
.then((out: string) => {
Expand All @@ -526,6 +526,17 @@ export class ShowdownPreviewer {
.catch((err: string) => {
console.log(err);
});
if (!this.config.chromePath) {
// Seconde find setup path of chrome from HKCU
await utils
.regQuery('HKCU\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\chrome.exe')
.then((out: string) => {
this.config.chromePath = out;
})
.catch((err: string) => {
console.log(err);
});
}
}
browser = await puppeteer.launch({
executablePath: this.config.chromePath || require('chrome-location'),
Expand Down Expand Up @@ -731,7 +742,7 @@ export class ShowdownPreviewer {
<title>${title}</title>
<style type="text/css">
body {
font-size: 16px;
font-size: ${this.config.fontSize}px;
line-height: 1.6;
}
a {
Expand Down

0 comments on commit 09fad28

Please sign in to comment.