Skip to content

export-html template.html 被格式化工具错误处理导致导出失败 #43616

@yunlzhang

Description

@yunlzhang

Bug 描述

导出的 session HTML 文件无法正常打开,浏览器控制台报错:

Uncaught ReferenceError: MARKED_JS is not defined
Uncaught ReferenceError: HIGHLIGHT_JS is not defined
Uncaught ReferenceError: JS is not defined

原因分析

dist/export-html/template.html 模板文件中的占位符被格式化工具(如 prettier)错误地拆分成多行格式:

期望格式

<script>{{MARKED_JS}}</script>

实际格式

<script>
 {
 {
 MARKED_JS;
 }
 }
</script>

代码中使用 .replace("{{MARKED_JS}}", markedJs) 进行替换,但由于模板中的占位符被拆分,导致无法匹配,最终生成的 HTML 文件中 JavaScript 变量未定义。

影响范围

  • {{MARKED_JS}}
  • {{HIGHLIGHT_JS}}
  • {{JS}}

建议修复

  • 在模板文件中使用 HTML 注释保护占位符,防止被格式化
  • 或者在构建流程中添加 .html 文件的格式化忽略规则
  • 或者在代码中使用正则替换,容忍空白字符

临时解决方案

手动修改 dist/export-html/template.html,将多行占位符改回单行格式。

环境

  • OpenClaw 版本:最新 (2026-03-11)
  • Node: v22.12.0
  • 系统: macOS (arm64)

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked as stale due to inactivity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions