Skip to content

Commit

Permalink
Merge branch 'release/1.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
yzane committed Sep 8, 2023
2 parents 837ad2a + 85e59d6 commit 5b6dbb2
Show file tree
Hide file tree
Showing 10 changed files with 1,390 additions and 1,056 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Change Log

## 1.5.0 (2023/09/05)
* Improve: The default date format for headers and footers has been changed to the ISO-based format (YYYY-MM-DD).
* Support different date formats in templates [#197](https://github.com/yzane/vscode-markdown-pdf/pull/197)
* Improve: Avoid TimeoutError: Navigation timeout of 30000 ms exceeded and TimeoutError: waiting for Page.printToPDF failed: timeout 30000ms exceeded [#266](https://github.com/yzane/vscode-markdown-pdf/pull/266)
* Fix: Fix description of outputDirectoryRelativePathFile [#238](https://github.com/yzane/vscode-markdown-pdf/pull/238)
* README
* Add: Specification Changes
* Fix: Broken link

## 1.4.4 (2020/03/19)
* Change: mermaid javascript reads from URL instead of from local file
* Add: `markdown-pdf.mermaidServer` option
Expand Down
79 changes: 49 additions & 30 deletions README.ja.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
## 目次
<!-- TOC depthFrom:2 depthTo:2 updateOnSave:false -->

- [仕様変更](#仕様変更)
- [機能](#機能)
- [インストール](#インストール)
- [使い方](#使い方)
Expand All @@ -20,6 +21,13 @@

<div class="page"/>

## 仕様変更

- PDFのヘッダーとフッターのデフォルトの日付書式変更
- バージョン1.5.0から、ヘッダーとフッターのデフォルトの日付書式がISOベースの書式(YYYY-MM-DD)に変更されました。
- この変更は、以前の書式が環境によって異なる可能性があったため、日付表示の一貫性を向上させることを目的としています。
- 以前の書式を使用したい場合は、[markdown-pdf.headerTemplate](#markdown-pdfheadertemplate)を参照してください。

## 機能

以下の機能をサポートしています。
Expand Down Expand Up @@ -388,26 +396,48 @@ Markdown PDF をインストールして、Visual Studio Code で Markdownファ

### PDF options

- pdf only. [puppeteer page.pdf options](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagepdfoptions)
- pdf only. [puppeteer page.pdf options](https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.pdfoptions.md)

#### `markdown-pdf.displayHeaderFooter`
- ヘッダーとフッター表示を有効にします
- boolean. Default: true
- このオプションを有効にすると、ヘッダーとフッターが両方表示されます
- 片方を表示したくない場合は、もう片方の値を削除します
- ヘッダー非表示
```javascript
"markdown-pdf.headerTemplate": "",
```
- フッター非表示
```javascript
"markdown-pdf.footerTemplate": "",
```

#### `markdown-pdf.headerTemplate`, `markdown-pdf.footerTemplate`
- ヘッダーとフッターを出力する為のHTMLテンプレートを指定します
- `<span class='date'></span>` : 日付
#### `markdown-pdf.headerTemplate`
- ヘッダーを出力する為のHTMLテンプレートを指定します
- このオプションを使用するには、`markdown-pdf.displayHeaderFooter``true` に設定する必要があります。
- `<span class='date'></span>` : 日付。フォーマットは環境に依存します
- `<span class='title'></span>` : Markdown ファイル名
- `<span class='url'></span>` : Markdown フルパスファイル名
- `<span class='pageNumber'></span>` : 現在のページ番号
- `<span class='totalPages'></span>` : ドキュメントの総ページ数

```javascript
"markdown-pdf.headerTemplate": "<div style=\"font-size: 9px; margin-left: 1cm;\"> <span class='title'></span></div> <div style=\"font-size: 9px; margin-left: auto; margin-right: 1cm; \"> <span class='date'></span></div>",
```
```javascript
"markdown-pdf.footerTemplate": "<div style=\"font-size: 9px; margin: 0 auto;\"> <span class='pageNumber'></span> / <span class='totalPages'></span></div>",
```
- `%%ISO-DATETIME%%` : 現在の日付と時刻。ISOベース フォーマット (`YYYY-MM-DD hh:mm:ss`)
- `%%ISO-DATE%%` : 現在の日付。ISOベース フォーマット (`YYYY-MM-DD`)
- `%%ISO-TIME%%` : 現在の時刻。ISOベース フォーマット (`hh:mm:ss`)
- Default (version1.5.0以降): Markdown ファイル名 と 日付を `%%ISO-DATE%%` で表示します
```javascript
"markdown-pdf.headerTemplate": "<div style=\"font-size: 9px; margin-left: 1cm;\"> <span class='title'></span></div> <div style=\"font-size: 9px; margin-left: auto; margin-right: 1cm; \">%%ISO-DATE%%</div>",
```
- Default (version1.4.4以前): Markdown ファイル名 と 日付を `<span class='date'></span>` で表示します
```javascript
"markdown-pdf.headerTemplate": "<div style=\"font-size: 9px; margin-left: 1cm;\"> <span class='title'></span></div> <div style=\"font-size: 9px; margin-left: auto; margin-right: 1cm; \"> <span class='date'></span></div>",
```
#### `markdown-pdf.footerTemplate`
- フッターを出力する為のHTMLテンプレートを指定します
- 詳細は、[markdown-pdf.headerTemplate](#markdown-pdfheadertemplate) を参照してください
- Default: {現在のページ番号} / {ドキュメントの総ページ数} を表示します
```javascript
"markdown-pdf.footerTemplate": "<div style=\"font-size: 9px; margin: 0 auto;\"> <span class='pageNumber'></span> / <span class='totalPages'></span></div>",
```

#### `markdown-pdf.printBackground`
- 背景のグラフィックを出力
Expand Down Expand Up @@ -576,25 +606,14 @@ Visual Studio Code の `files.autoGuessEncoding` オプションを使うと、

## [Release Notes](CHANGELOG.md)

## 1.4.4 (2020/03/19)
* Change: mermaid javascript reads from URL instead of from local file
* Add: `markdown-pdf.mermaidServer` option
* add an option to disable mermaid [#175](https://github.com/yzane/vscode-markdown-pdf/issues/175)
* Add: `markdown-pdf.plantumlServer` option
* support configuration of plantUML server [#139](https://github.com/yzane/vscode-markdown-pdf/issues/139)
* Add: configuration scope
* extend setting 'headerTemplate' with scope\.\.\. [#184](https://github.com/yzane/vscode-markdown-pdf/pull/184)
* Update: [slug](https://github.com/yzane/vscode-markdown-pdf/commit/3f4aeaa724999c46fc37423d4b188fd7ce72ffce) for markdown-it-named-headers
* Update: markdown.css, markdown-pdf.css
* Update: dependent packages
* Fix: Fix for issue \#186 [#187](https://github.com/yzane/vscode-markdown-pdf/pull/187)
* Fix: move the Meiryo font to the end of the font-family setting
* Meiryo font causing \\ to show as ¥ [#83](https://github.com/yzane/vscode-markdown-pdf/issues/83)
* Backslash false encoded [#124](https://github.com/yzane/vscode-markdown-pdf/issues/124)
* Errors in which 한글\(korean word\) is not properly printed [#148](https://github.com/yzane/vscode-markdown-pdf/issues/148)
* Fix: Improve the configuration schema of package.json
* Some settings can now be set from the settings editor.

### 1.5.0 (2023/09/05)
* Improve: The default date format for headers and footers has been changed to the ISO-based format (YYYY-MM-DD).
* Support different date formats in templates [#197](https://github.com/yzane/vscode-markdown-pdf/pull/197)
* Improve: Avoid TimeoutError: Navigation timeout of 30000 ms exceeded and TimeoutError: waiting for Page.printToPDF failed: timeout 30000ms exceeded [#266](https://github.com/yzane/vscode-markdown-pdf/pull/266)
* Fix: Fix description of outputDirectoryRelativePathFile [#238](https://github.com/yzane/vscode-markdown-pdf/pull/238)
* README
* Add: Specification Changes
* Fix: Broken link

## License

Expand Down
81 changes: 50 additions & 31 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This extension converts Markdown files to pdf, html, png or jpeg files.
## Table of Contents
<!-- TOC depthFrom:2 depthTo:2 updateOnSave:false -->

- [Specification Changes](#specification-changes)
- [Features](#features)
- [Install](#install)
- [Usage](#usage)
Expand All @@ -22,6 +23,13 @@ This extension converts Markdown files to pdf, html, png or jpeg files.

<div class="page"/>

## Specification Changes

- Default Date Format for PDF Headers and Footers Modified
- Starting from version 1.5.0, the default date format for headers and footers has been changed to the ISO-based format (YYYY-MM-DD).
- This change aims to improve the consistency of date displays, as the previous format could vary depending on the environment.
- If you wish to use the previous format, please refer to [markdown-pdf.headerTemplate](#markdown-pdfheadertemplate).

## Features

Supports the following features
Expand Down Expand Up @@ -393,27 +401,49 @@ If the download is not successful or you want to avoid downloading every time yo

### PDF options

- pdf only. [puppeteer page.pdf options](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagepdfoptions)
- pdf only. [puppeteer page.pdf options](https://github.com/puppeteer/puppeteer/blob/main/docs/api/puppeteer.pdfoptions.md)

#### `markdown-pdf.displayHeaderFooter`
- Enable display header and footer
- Enables header and footer display
- boolean. Default: true
- Activating this option will display both the header and footer
- If you wish to display only one of them, remove the value for the other
- To hide the header
```javascript
"markdown-pdf.headerTemplate": "",
```
- To hide the footer
```javascript
"markdown-pdf.footerTemplate": "",
```

#### `markdown-pdf.headerTemplate`
#### `markdown-pdf.footerTemplate`
- HTML template for the print header and footer
- `<span class='date'></span>` : formatted print date
- Specifies the HTML template for outputting the header
- To use this option, you must set `markdown-pdf.displayHeaderFooter` to `true`
- `<span class='date'></span>` : formatted print date. The format depends on the environment
- `<span class='title'></span>` : markdown file name
- `<span class='url'></span>` : markdown full path name
- `<span class='pageNumber'></span>` : current page number
- `<span class='totalPages'></span>` : total pages in the document
- `%%ISO-DATETIME%%` : current date and time in ISO-based format (`YYYY-MM-DD hh:mm:ss`)
- `%%ISO-DATE%%` : current date in ISO-based format (`YYYY-MM-DD`)
- `%%ISO-TIME%%` : current time in ISO-based format (`hh:mm:ss`)
- Default (version 1.5.0 and later): Displays the Markdown file name and the date using `%%ISO-DATE%%`
```javascript
"markdown-pdf.headerTemplate": "<div style=\"font-size: 9px; margin-left: 1cm;\"> <span class='title'></span></div> <div style=\"font-size: 9px; margin-left: auto; margin-right: 1cm; \">%%ISO-DATE%%</div>",
```
- Default (version 1.4.4 and earlier): Displays the Markdown file name and the date using `<span class='date'></span>`
```javascript
"markdown-pdf.headerTemplate": "<div style=\"font-size: 9px; margin-left: 1cm;\"> <span class='title'></span></div> <div style=\"font-size: 9px; margin-left: auto; margin-right: 1cm; \"> <span class='date'></span></div>",
```

```javascript
"markdown-pdf.headerTemplate": "<div style=\"font-size: 9px; margin-left: 1cm;\"> <span class='title'></span></div> <div style=\"font-size: 9px; margin-left: auto; margin-right: 1cm; \"> <span class='date'></span></div>",
```
```javascript
"markdown-pdf.footerTemplate": "<div style=\"font-size: 9px; margin: 0 auto;\"> <span class='pageNumber'></span> / <span class='totalPages'></span></div>",
```
#### `markdown-pdf.footerTemplate`
- Specifies the HTML template for outputting the footer
- For more details, refer to [markdown-pdf.headerTemplate](#markdown-pdfheadertemplate)
- Default: Displays the {current page number} / {total pages in the document}
```javascript
"markdown-pdf.footerTemplate": "<div style=\"font-size: 9px; margin: 0 auto;\"> <span class='pageNumber'></span> / <span class='totalPages'></span></div>",
```

#### `markdown-pdf.printBackground`
- Print background graphics
Expand Down Expand Up @@ -464,7 +494,7 @@ If the download is not successful or you want to avoid downloading every time yo
"markdown-pdf.margin.left": "1cm",
```

### PNG JPEG options
### PNG, JPEG options

- png and jpeg only. [puppeteer page.screenshot options](https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagescreenshotoptions)

Expand Down Expand Up @@ -582,25 +612,14 @@ Please use the following to insert a page break.

## [Release Notes](CHANGELOG.md)

### 1.4.4 (2020/03/19)
* Change: mermaid javascript reads from URL instead of from local file
* Add: `markdown-pdf.mermaidServer` option
* add an option to disable mermaid [#175](https://github.com/yzane/vscode-markdown-pdf/issues/175)
* Add: `markdown-pdf.plantumlServer` option
* support configuration of plantUML server [#139](https://github.com/yzane/vscode-markdown-pdf/issues/139)
* Add: configuration scope
* extend setting 'headerTemplate' with scope\.\.\. [#184](https://github.com/yzane/vscode-markdown-pdf/pull/184)
* Update: [slug](https://github.com/yzane/vscode-markdown-pdf/commit/3f4aeaa724999c46fc37423d4b188fd7ce72ffce) for markdown-it-named-headers
* Update: markdown.css, markdown-pdf.css
* Update: dependent packages
* Fix: Fix for issue \#186 [#187](https://github.com/yzane/vscode-markdown-pdf/pull/187)
* Fix: move the Meiryo font to the end of the font-family setting
* Meiryo font causing \\ to show as ¥ [#83](https://github.com/yzane/vscode-markdown-pdf/issues/83)
* Backslash false encoded [#124](https://github.com/yzane/vscode-markdown-pdf/issues/124)
* Errors in which 한글\(korean word\) is not properly printed [#148](https://github.com/yzane/vscode-markdown-pdf/issues/148)
* Fix: Improve the configuration schema of package.json
* Some settings can now be set from the settings editor.

### 1.5.0 (2023/09/05)
* Improve: The default date format for headers and footers has been changed to the ISO-based format (YYYY-MM-DD).
* Support different date formats in templates [#197](https://github.com/yzane/vscode-markdown-pdf/pull/197)
* Improve: Avoid TimeoutError: Navigation timeout of 30000 ms exceeded and TimeoutError: waiting for Page.printToPDF failed: timeout 30000ms exceeded [#266](https://github.com/yzane/vscode-markdown-pdf/pull/266)
* Fix: Fix description of outputDirectoryRelativePathFile [#238](https://github.com/yzane/vscode-markdown-pdf/pull/238)
* README
* Add: Specification Changes
* Fix: Broken link

## License

Expand Down
31 changes: 27 additions & 4 deletions extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ function exportPdf(data, filename, type, uri) {
};
const browser = await puppeteer.launch(options);
const page = await browser.newPage();
await page.setDefaultTimeout(0);
await page.goto(vscode.Uri.file(tmpfilename).toString(), { waitUntil: 'networkidle0' });
// generate pdf
// https://github.com/GoogleChrome/puppeteer/blob/master/docs/api.md#pagepdfoptions
Expand All @@ -426,8 +427,8 @@ function exportPdf(data, filename, type, uri) {
path: exportFilename,
scale: vscode.workspace.getConfiguration('markdown-pdf', uri)['scale'],
displayHeaderFooter: vscode.workspace.getConfiguration('markdown-pdf', uri)['displayHeaderFooter'],
headerTemplate: vscode.workspace.getConfiguration('markdown-pdf', uri)['headerTemplate'] || '',
footerTemplate: vscode.workspace.getConfiguration('markdown-pdf', uri)['footerTemplate'] || '',
headerTemplate: transformTemplate(vscode.workspace.getConfiguration('markdown-pdf', uri)['headerTemplate'] || ''),
footerTemplate: transformTemplate(vscode.workspace.getConfiguration('markdown-pdf', uri)['footerTemplate'] || ''),
printBackground: vscode.workspace.getConfiguration('markdown-pdf', uri)['printBackground'],
landscape: landscape_option,
pageRanges: vscode.workspace.getConfiguration('markdown-pdf', uri)['pageRanges'] || '',
Expand All @@ -439,8 +440,9 @@ function exportPdf(data, filename, type, uri) {
right: vscode.workspace.getConfiguration('markdown-pdf', uri)['margin']['right'] || '',
bottom: vscode.workspace.getConfiguration('markdown-pdf', uri)['margin']['bottom'] || '',
left: vscode.workspace.getConfiguration('markdown-pdf', uri)['margin']['left'] || ''
}
}
},
timeout: 0
};
await page.pdf(options);
}

Expand Down Expand Up @@ -504,6 +506,27 @@ function exportPdf(data, filename, type, uri) {
); // vscode.window.withProgress
}

/**
* Transform the text of the header or footer template, replacing the following supported placeholders:
*
* - `%%ISO-DATETIME%%` – For an ISO-based date and time format: `YYYY-MM-DD hh:mm:ss`
* - `%%ISO-DATE%%` – For an ISO-based date format: `YYYY-MM-DD`
* - `%%ISO-TIME%%` – For an ISO-based time format: `hh:mm:ss`
*/
function transformTemplate(templateText) {
if (templateText.indexOf('%%ISO-DATETIME%%') !== -1) {
templateText = templateText.replace('%%ISO-DATETIME%%', new Date().toISOString().substr(0, 19).replace('T', ' '));
}
if (templateText.indexOf('%%ISO-DATE%%') !== -1) {
templateText = templateText.replace('%%ISO-DATE%%', new Date().toISOString().substr(0, 10));
}
if (templateText.indexOf('%%ISO-TIME%%') !== -1) {
templateText = templateText.replace('%%ISO-TIME%%', new Date().toISOString().substr(11, 8));
}

return templateText;
}

function isExistsPath(path) {
if (path.length === 0) {
return false;
Expand Down
Loading

0 comments on commit 5b6dbb2

Please sign in to comment.