Skip to content

Commit

Permalink
Fix tag A click issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
shd101wyy committed Jul 4, 2017
1 parent 382c956 commit ecc1ffe
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 4 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Below is a demo of the Atom version.
* `Markdown Preview Enhanced: Create TOC`
* `Markdown Preview Enhanced: Open Mermaid Config`
* `Markdown Preview Enhanced: Open MathJax Config`
* `Markdown Preview Enhanced: Open PhantomJS Config`
* `Markdown Preview Enhanced: Insert New Slide`
* `Markdown Preview Enhanced: Insert Table`
* `Markdown Preview Enhanced: Insert Page Break`
Expand All @@ -30,9 +31,14 @@ Below is a demo of the Atom version.

For more features that will be supported in the future, check [Markdown Preview Enhanced for atom](https://shd101wyy.github.io/markdown-preview-enhanced/#/).

### Progress so far
### Progress so far
#### July 4, 2017
*Basically finished porting.*
* Done [PhantomJS export](./docs/phantomjs.md).
* Done [pandoc parser](https://shd101wyy.github.io/markdown-preview-enhanced/#/pandoc?id=pandoc-parser) support.
* Added `Gothic`, `Newsprint`, and `Night` preview themes.

#### June 20, 2017
Basically finished.
* Done [Pandoc export](https://shd101wyy.github.io/markdown-preview-enhanced/#/pandoc-pdf). (Not tested).
* Done Markdown(GFM) export. (Not tested)
* Done [TOC](https://shd101wyy.github.io/markdown-preview-enhanced/#/toc) implementation.
Expand Down
54 changes: 54 additions & 0 deletions docs/phantomjs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# PhantomJS Export

**PhantomJS** supports `pdf`, `jpeg`, and `png` file export.
You need to download and install [phantomjs](http://phantomjs.org/download.html) first.

## Usage
Right click at the preview, then click `PhantomJS`. Choose the file type you want to export.

## Configuration
You can edit phantomjs configuration by running `Markdown Preview Enhanced: Open PhantomJS Config` command.

The `phantomjs_header_footer_config.js` file should look like this:


```javascript
'use strict'
/*
configure header and footer (and other options)
more information can be found here:
https://github.com/marcbachmann/node-html-pdf
Attention: this config will override your config in exporter panel.
eg:
let config = {
"header": {
"height": "45mm",
"contents": '<div style="text-align: center;">Author: Marc Bachmann</div>'
},
"footer": {
"height": "28mm",
"contents": '<span style="color: #444;">{{page}}</span>/<span>{{pages}}</span>'
}
}
*/
// you can edit the 'config' variable below
let config = {
}

module.exports = config || {}
```

---

You can also write configuration for individual markdown file by front-matter.
For example:

```markdown
---
phantomjs:
orientation: "landscape"
---

```
3 changes: 2 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,11 +245,12 @@ export function activate(context: vscode.ExtensionContext) {

function clickTagA(uri, href) {
const sourceUri = vscode.Uri.parse(decodeURIComponent(uri));
href = decodeURIComponent(href)
if (['.pdf', '.xls', '.xlsx', '.doc', '.ppt', '.docx', '.pptx'].indexOf(path.extname(href)) >= 0) {
utility.openFile(href)
} else if (href.match(/^file\:\/\/\//)) {
// openFilePath = href.slice(8) # remove protocal
let openFilePath = href.replace(/(\s*)[\#\?](.+)$/, '') // remove #anchor and ?params...
let openFilePath = utility.addFileProtocol(href.replace(/(\s*)[\#\?](.+)$/, '')) // remove #anchor and ?params...
openFilePath = decodeURI(openFilePath)
vscode.commands.executeCommand('vscode.open', vscode.Uri.parse(openFilePath), vscode.ViewColumn.One)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/markdown-preview-enhanced-webview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ function bindTagAClickEvent() {

window.parent.postMessage({
command: 'did-click-link', // <= this has to be `did-click-link` to post message
data: `command:_markdown-preview-enhanced.clickTagA?${JSON.stringify([sourceUri, href])}`
data: `command:_markdown-preview-enhanced.clickTagA?${JSON.stringify([sourceUri, encodeURIComponent(href)])}`
}, 'file://')
}
}
Expand Down

0 comments on commit ecc1ffe

Please sign in to comment.