Private
Public Access
1
0

重构:Wails升级/mermaid主题切换/代码高亮修复/文件系统UI重构

- Wails v2.12.0升级(App绑定新增API、runtime类型扩展)
- 修复mermaid暗色主题切换渲染失败(SVG textContent污染→data-mermaid-src保存源码)
- 修复代码高亮全语言失效(languageMap静态白名单替代运行时hljs检查)
- 文件系统:FileListPanel重写、FileItemRow合并删除、Toolbar简化
- 新增剪贴板图片粘贴(Ctrl+V粘贴图片到当前目录)
- 死代码清理:DeviceTest/errorHandler/useLocalStorage移除
- MarkdownEditor优化、theme store增强、CodeMirror加载器精简
This commit is contained in:
2026-04-11 16:46:43 +08:00
parent efc042fcd3
commit 7dbd57a8b6
40 changed files with 1274 additions and 1404 deletions

View File

@@ -41,8 +41,14 @@ var (
es6ImportFromRegex = regexp.MustCompile(`import\s+([\s\S]*?)\s+from\s+["']([^"']+)["']`)
es6DynamicImport = regexp.MustCompile(`import\s*\(\s*["']([^"']+)["']\s*\)`)
es6BareImport = regexp.MustCompile(`(?m)^\s*import\s+["']([^"']+)["']`)
// HTML 预览路径修复
locationPathRegex = regexp.MustCompile(`\blocation\.pathname\b`)
)
// HTML 属性正则缓存(避免 replaceHtmlTagAttribute 中重复编译)
var attrRegexCache sync.Map // map[string]*regexp.Regexp
// LocalFileServer 本地文件服务器(独立的 HTTP 服务器)
type LocalFileServer struct {
server *http.Server
@@ -501,6 +507,11 @@ func handleHtmlPreviewRequest(w http.ResponseWriter, r *http.Request) {
// 解析参数
filePath := r.URL.Query().Get("path")
var err error
if filePath, err = url.QueryUnescape(filePath); err != nil {
http.Error(w, "Invalid path encoding", http.StatusBadRequest)
return
}
theme := r.URL.Query().Get("theme")
if theme == "" {
theme = "light"
@@ -536,6 +547,12 @@ func handleHtmlPreviewRequest(w http.ResponseWriter, r *http.Request) {
// 转换资源路径(将相对路径和绝对路径都转换为完整的本地文件服务器 URL
processedContent := transformHtmlResourcePaths(string(content), baseDir)
// 修复 JS 中基于 location.pathname 的相对路径计算
// 预览模式下 location.pathname = "/localfs/html-preview",与实际文件路径不一致
// ⚠️ 会替换所有出现位置含JS字符串内HTML预览场景下可接受
correctPathname := `"/localfs/` + strings.ReplaceAll(baseDir, "\\", "/") + `/`
processedContent = locationPathRegex.ReplaceAllString(processedContent, correctPathname)
// 注入链接点击拦截脚本
finalContent := injectLinkInterceptor(processedContent)
@@ -616,8 +633,14 @@ func transformHtmlResourcePaths(htmlContent string, baseDir string) string {
// replaceHtmlTagAttribute 替换 HTML 标签中的属性路径
func replaceHtmlTagAttribute(html string, pattern *regexp.Regexp, attrName string, baseDir string) string {
return pattern.ReplaceAllStringFunc(html, func(match string) string {
// 提取属性值
attrRegex := regexp.MustCompile(fmt.Sprintf(`%s=["']([^"']+)["']`, attrName))
// 提取属性值(使用缓存的正则)
var attrRegex *regexp.Regexp
if v, ok := attrRegexCache.Load(attrName); ok {
attrRegex = v.(*regexp.Regexp)
} else {
attrRegex = regexp.MustCompile(fmt.Sprintf(`%s=["']([^"']+)["']`, attrName))
attrRegexCache.Store(attrName, attrRegex)
}
attrMatch := attrRegex.FindStringSubmatch(match)
if attrMatch == nil {
return match