Skip to content

Commit

Permalink
fixed: failed to open an external link (#15)
Browse files Browse the repository at this point in the history
* start

* implement

* edit readme

* new issue

* edit readme
  • Loading branch information
dzylikecode authored Oct 24, 2022
1 parent 4617ee3 commit d371602
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 5 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,8 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## [Unreleased]

- Initial release
- 1.6.0

[fixed: failed to open an external link](https://github.com/dzylikecode/VSCodeExt-docsify-Preview/pull/15)

- Initial release
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,18 @@ If you want to paste images in markdown, welcome to use my other plugin:[md-past

## Known Issues

You should open the preview in the browser if click the external link in the preview. The reason why it can't open it inside the preview is the limitation of Webview.

> may be I can try open it in the browser.
You may open the duplicate tab in the browser if clicking the external link.

If you find any issues, please report them to [issue](https://github.com/dzylikecode/VSCodeExt-docsify-Preview/issues)

## Release Notes

### 1.6.0

fixed: failed to open an external link

> Now you can open the external link in the preview, and then it will be opened in the browser. But the problem is that you may open the duplicate tab in the browser. I will try to fix it in the future.
### 1.5.0

- feature:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "docsify-preview",
"displayName": "docsify-Preview",
"description": "write docs easily with docsify",
"version": "1.5.0",
"version": "1.6.0",
"engines": {
"vscode": "^1.71.0"
},
Expand Down
2 changes: 2 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ async function main(context, disposable) {
);
} else if (message.command == "closePreview") {
server.close();
} else if (message.command == "openLink") {
vscode.env.openExternal(message.url);
}
return;
function goHere(url, linePercent) {
Expand Down
3 changes: 3 additions & 0 deletions src/server/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ window.addEventListener("message", (event) => {
case "hideContextMenu":
hideContextMenu();
break;
case "openLink":
vscode.postMessage(message);
break;
}
});

Expand Down
17 changes: 17 additions & 0 deletions src/server/listener/injected.html
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,23 @@
}
}
});
hook.doneEach(() => {
openBlankLink();
return;
function openBlankLink() {
document.querySelectorAll("a[target='_blank']").forEach((link) => {
link.addEventListener("click", (e) => {
window.parent.window.postMessage(
{
command: "openLink",
url: link.href,
},
"*"
);
});
});
}
});
hook.ready(() => {
// this why I can't scroll window directly
restoreScrollState();
Expand Down

0 comments on commit d371602

Please sign in to comment.