mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-12 18:24:21 +01:00
Improve export preview mode CSS variable value filling (#15110)
* 改进 CSS 变量替换为实际值 * Chrome、Edge、SiYuan 桌面端不需要替换 CSS 变量 * 外观模式或主题改变之后,重新加载所有将 CSS 变量替换为实际值的导出预览 * 代码块之间没有间距 * 去掉一个空格 * 使用 ua.Mobile() 判断移动设备 * 重构
This commit is contained in:
parent
449b537104
commit
2994969286
6 changed files with 235 additions and 43 deletions
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/mssola/useragent"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/model"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -627,9 +628,22 @@ func exportPreview(c *gin.Context) {
|
|||
}
|
||||
|
||||
id := arg["id"].(string)
|
||||
stdHTML := model.Preview(id)
|
||||
|
||||
userAgentStr := c.GetHeader("User-Agent")
|
||||
fillCSSVar := true
|
||||
if userAgentStr != "" {
|
||||
ua := useragent.New(userAgentStr)
|
||||
name, _ := ua.Browser()
|
||||
// Chrome、Edge、SiYuan 桌面端不需要替换 CSS 变量
|
||||
if !ua.Mobile() && (name == "Chrome" || name == "Edge" || strings.Contains(userAgentStr, "Electron") || strings.Contains(userAgentStr, "SiYuan/")) {
|
||||
fillCSSVar = false
|
||||
}
|
||||
}
|
||||
|
||||
stdHTML := model.Preview(id, fillCSSVar)
|
||||
ret.Data = map[string]interface{}{
|
||||
"html": stdHTML,
|
||||
"html": stdHTML,
|
||||
"fillCSSVar": fillCSSVar,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue