``` **实际格式**: ```html ``` 代码中使用 `.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)","inLanguage":"en-US","datePublished":"2026-03-12T02:59:12Z","dateModified":"2026-03-12T02:59:12Z","mainEntityOfPage":{"@type":"WebPage","@id":"https://www.stepcodex.com/en/issue/export-html-template-html"},"author":{"@type":"Person","name":"yunlzhang","url":"https://github.com/yunlzhang","image":"https://github.com/yunlzhang"},"publisher":{"@type":"Organization","name":"StepCodex","url":"https://www.stepcodex.com"},"articleSection":"openclaw","about":[{"@type":"Thing","name":"openclaw","url":"https://www.stepcodex.com/en/category/openclaw"}],"contributor":[{"@type":"Person","name":"whylwhyl","url":"https://github.com/whylwhyl","image":"https://github.com/whylwhyl"}],"keywords":"export-html template.html 被格式化工具错误处理导致导出失败, openclaw, how to fix, fix, troubleshooting, root cause, solution, StepCodex","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/LikeAction","userInteractionCount":2}},{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://www.stepcodex.com/en/issue"},{"@type":"ListItem","position":2,"name":"openclaw","item":"https://www.stepcodex.com/en/category/openclaw"},{"@type":"ListItem","position":3,"name":"export-html template.html 被格式化工具错误处理导致导出失败","item":"https://www.stepcodex.com/en/issue/export-html-template-html"}]}]

openclaw - ✅(Solved) Fix export-html template.html 被格式化工具错误处理导致导出失败 [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#43616Fetched 2026-04-08 00:16:47
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Author
Participants
Timeline (top)
commented ×1cross-referenced ×1referenced ×1

Error Message

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

Fix Action

Fixed

PR fix notes

PR #43634: fix: restore export-html template placeholders and prevent reformatting

Description (problem / solution / changelog)

This PR fixes the export-html template that was broken by a formatter.

What was broken:

  • The template placeholders , , and were being split into multiple lines by the formatter
  • This caused the export-html functionality to fail because the placeholders couldn't be recognized

What this PR does:

  1. Restores the original template.html with correct placeholder formatting
  2. Adds to to prevent future reformatting
  3. Keeps the existing ignore in as an extra layer of protection

Closes #43616, #43620

Changed files

  • .gitattributes (modified, +1/-0)
  • src/auto-reply/reply/export-html/template.html (modified, +45/-79)

Code Example

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

---

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

---

<script>
 {
 {
 MARKED_JS;
 }
 }
</script>
RAW_BUFFERClick to expand / collapse

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)

extent analysis

Fix Plan

To fix the issue, we can modify the code to use regular expressions for replacement, allowing for whitespace characters. Here are the steps:

  • Update the replacement code to use a regular expression that matches the placeholder with optional whitespace characters:
const regex = new RegExp(`{{\\s*MARKED_JS\\s*}}`, 'g');
const replacedHtml = html.replace(regex, markedJs);
  • Repeat the same process for HIGHLIGHT_JS and JS placeholders:
const highlightRegex = new RegExp(`{{\\s*HIGHLIGHT_JS\\s*}}`, 'g');
const jsRegex = new RegExp(`{{\\s*JS\\s*}}`, 'g');
const replacedHtml = html
  .replace(regex, markedJs)
  .replace(highlightRegex, highlightJs)
  .replace(jsRegex, js);

Verification

To verify that the fix worked, check the generated HTML file for the correct replacement of the placeholders. The JavaScript variables should now be defined, and the browser console should no longer report the Uncaught ReferenceError.

Extra Tips

  • Consider adding a format ignore rule for the template.html file to prevent similar issues in the future.
  • If using a formatting tool like Prettier, configure it to ignore the template.html file or use a different formatting option that preserves the placeholders.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING