🐛 The hyperlink in the changelog fails to jump to the browser to open https://github.com/siyuan-note/siyuan/issues/8458
This commit is contained in:
parent
8c9d947ff2
commit
b24c06fbce
4 changed files with 45 additions and 35 deletions
|
@ -119,8 +119,10 @@ const exitApp = (port, errorWindowId) => {
|
|||
}
|
||||
};
|
||||
|
||||
const localServer = "http://127.0.0.1"
|
||||
|
||||
const getServer = (port = kernelPort) => {
|
||||
return "http://127.0.0.1:" + port;
|
||||
return localServer + ":" + port;
|
||||
};
|
||||
|
||||
const sleep = (ms) => {
|
||||
|
@ -359,16 +361,13 @@ const boot = () => {
|
|||
const menu = Menu.buildFromTemplate(template);
|
||||
Menu.setApplicationMenu(menu);
|
||||
// 当前页面链接使用浏览器打开
|
||||
currentWindow.webContents.on("will-navigate", (event, url) => {
|
||||
if (event.sender) {
|
||||
const currentURL = new URL(event.sender.getURL());
|
||||
if (url.startsWith(getServer(currentURL.port))) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.preventDefault();
|
||||
shell.openExternal(url);
|
||||
currentWindow.webContents.on("will-navigate", (event) => {
|
||||
const url = event.url;
|
||||
event.preventDefault();
|
||||
if (url.startsWith(localServer)) {
|
||||
return;
|
||||
}
|
||||
shell.openExternal(url);
|
||||
});
|
||||
|
||||
currentWindow.on("close", (event) => {
|
||||
|
@ -664,10 +663,10 @@ app.whenReady().then(() => {
|
|||
BrowserWindow.fromId(id).webContents.send("siyuan-export-close", id);
|
||||
});
|
||||
ipcMain.on("siyuan-export-prevent", (event, id) => {
|
||||
BrowserWindow.fromId(id).webContents.on("will-navigate", (event, url) => {
|
||||
const currentURL = new URL(event.sender.getURL());
|
||||
BrowserWindow.fromId(id).webContents.on("will-navigate", (event) => {
|
||||
const url = event.url;
|
||||
event.preventDefault();
|
||||
if (url.startsWith(getServer(currentURL.port))) {
|
||||
if (url.startsWith(localServer)) {
|
||||
return;
|
||||
}
|
||||
shell.openExternal(url);
|
||||
|
|
|
@ -66,10 +66,11 @@ func getChangelog(c *gin.Context) {
|
|||
|
||||
model.Conf.ShowChangelog = false
|
||||
luteEngine := lute.New()
|
||||
htmlContent := luteEngine.Markdown("", contentData)
|
||||
htmlContent := luteEngine.MarkdownStr("", string(contentData))
|
||||
htmlContent = util.LinkTarget(htmlContent, "")
|
||||
|
||||
data["show"] = true
|
||||
data["html"] = gulu.Str.FromBytes(htmlContent)
|
||||
data["html"] = htmlContent
|
||||
ret.Data = data
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,6 @@ import (
|
|||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/imroc/req/v3"
|
||||
"github.com/siyuan-note/filelock"
|
||||
|
@ -517,24 +516,7 @@ func renderREADME(repoURL string, mdData []byte) (ret string, err error) {
|
|||
linkBase := "https://cdn.jsdelivr.net/gh/" + strings.TrimPrefix(repoURL, "https://github.com/")
|
||||
luteEngine.SetLinkBase(linkBase)
|
||||
ret = luteEngine.Md2HTML(string(mdData))
|
||||
doc, err := goquery.NewDocumentFromReader(strings.NewReader(ret))
|
||||
if nil != err {
|
||||
logging.LogErrorf("parse HTML failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
doc.Find("a").Each(func(i int, selection *goquery.Selection) {
|
||||
if href, ok := selection.Attr("href"); ok {
|
||||
if util.IsRelativePath(href) {
|
||||
selection.SetAttr("href", linkBase+href)
|
||||
}
|
||||
|
||||
// The hyperlink in the marketplace package README fails to jump to the browser to open https://github.com/siyuan-note/siyuan/issues/8452
|
||||
selection.SetAttr("target", "_blank")
|
||||
}
|
||||
})
|
||||
|
||||
ret, _ = doc.Find("body").Html()
|
||||
ret = util.LinkTarget(ret, linkBase)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,13 @@
|
|||
|
||||
package util
|
||||
|
||||
import "github.com/88250/lute"
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/88250/lute"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/siyuan-note/logging"
|
||||
)
|
||||
|
||||
func NewLute() (ret *lute.Lute) {
|
||||
ret = lute.New()
|
||||
|
@ -62,3 +68,25 @@ func NewStdLute() (ret *lute.Lute) {
|
|||
ret.SetInlineMathAllowDigitAfterOpenMarker(true) // Formula parsing supports $ followed by numbers when importing Markdown https://github.com/siyuan-note/siyuan/issues/8362
|
||||
return
|
||||
}
|
||||
|
||||
func LinkTarget(htmlStr, linkBase string) (ret string) {
|
||||
doc, err := goquery.NewDocumentFromReader(strings.NewReader(htmlStr))
|
||||
if nil != err {
|
||||
logging.LogErrorf("parse HTML failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
doc.Find("a").Each(func(i int, selection *goquery.Selection) {
|
||||
if href, ok := selection.Attr("href"); ok {
|
||||
if IsRelativePath(href) {
|
||||
selection.SetAttr("href", linkBase+href)
|
||||
}
|
||||
|
||||
// The hyperlink in the marketplace package README fails to jump to the browser to open https://github.com/siyuan-note/siyuan/issues/8452
|
||||
selection.SetAttr("target", "_blank")
|
||||
}
|
||||
})
|
||||
|
||||
ret, _ = doc.Find("body").Html()
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue