Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TeXmacs/packages/standard/std-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
<assign|decorated|<macro|body|<decorated-hook|<decorated-extra|<ornament|<decorated-body|<arg|body>>>>>>>

<assign|decorated-block|<\macro|body>
<decorated-hook|<decorate-extra|<\ornament>
<decorated-hook|<decorated-extra|<\ornament>
<\wide-normal>
<\decorated-body>
<arg|body>
Expand Down
96 changes: 48 additions & 48 deletions TeXmacs/plugins/html/progs/convert/html/tmhtml.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2018,48 +2018,45 @@
(with embedded
(tmhtml-extract-embedded (car l))
(let* ((data (car embedded)) (ext (cdr embedded)))
(if tmhtml-base64?
(if (in? ext (list "ps" "eps" "pdf" "tif"))
;; Convert to PNG first, then inline as Base64
(receive (name-url name-string)
(tmhtml-image-names ext)
(let* ((abs-url (url-concretize name-url))
(abs-string (url->unix abs-url)))
(tmhtml-write-binary-file abs-url data)
(let ((res (tmhtml-png (cons 'image (cons abs-string (cdr l))))))
(when (url-exists? abs-url)
(url-remove abs-url))
res
) ;let
) ;let*
) ;receive
;; Direct Base64 inline for native image formats
(let* ((b64-str (begin
(import (liii base64))
(utf8->string (bytevector-base64-encode data))
) ;begin
) ;b64-str
(src-uri (string-append "data:image/" ext ";base64," b64-str))
(w (if (>= (length l) 2) (tmlength->htmllength (second l) #f) #f))
(h (if (>= (length l) 3) (tmlength->htmllength (third l) #f) #f))
) ;let*
`((h:img (@ (class "image")
(src ,src-uri)
,@(if w `((width ,w)) '())
,@(if h `((height ,h)) '()))))
) ;if
) ;if
(receive (name-url name-string)
(tmhtml-image-names ext)
(let* ((abs-url (url-concretize name-url)) (abs-string (url->unix abs-url)))
(tmhtml-write-binary-file abs-url data)
(with res
(tmhtml-image (cons abs-string (cdr l)))
res
) ;with
) ;let*
) ;receive
) ;if
(if tmhtml-base64?
(if (in? ext (list "ps" "eps" "pdf" "tif"))
;; Convert to PNG first, then inline as Base64
(receive (name-url name-string)
(tmhtml-image-names ext)
(let* ((abs-url (url-concretize name-url)) (abs-string (url->unix abs-url)))
(tmhtml-write-binary-file abs-url data)
(let ((res (tmhtml-png (cons 'image (cons abs-string (cdr l))))))
(when (url-exists? abs-url)
(url-remove abs-url)
) ;when
res
) ;let
) ;let*
) ;receive
;; Direct Base64 inline for native image formats
(let* ((b64-str (begin
(import (liii base64))
(utf8->string (bytevector-base64-encode data))
) ;begin
) ;b64-str
(src-uri (string-append "data:image/" ext ";base64," b64-str))
(w (if (>= (length l) 2) (tmlength->htmllength (second l) #f) #f))
(h (if (>= (length l) 3) (tmlength->htmllength (third l) #f) #f))
) ;
`((h:img (@ (class "image")
(src ,src-uri)
,@(if w `((width ,w)) '())
,@(if h `((height ,h)) '()))))
) ;let*
) ;if
(receive (name-url name-string)
(tmhtml-image-names ext)
(let* ((abs-url (url-concretize name-url)) (abs-string (url->unix abs-url)))
(tmhtml-write-binary-file abs-url data)
(with res (tmhtml-image (cons abs-string (cdr l))) res)
) ;let*
) ;receive
) ;if
) ;let*
) ;with
) ;
Expand All @@ -2075,7 +2072,7 @@
) ;let*
) ;else
) ;cond
) ;define
) ;tm-define

(define-public (hash-map->list h)
(map (lambda (x) (list (car x) (cdr x))) (map values h))
Expand All @@ -2094,8 +2091,8 @@
) ;l1
(l2 (map car l1))
(args (map cadr l1))
(funs (map cAr l2))
(stys (map (lambda (x) (cdr (cDr x))) l2))
(funs (map last l2))
(stys (map (lambda (x) (reverse (cdr (reverse (cdr x))))) l2))
) ;
(apply string-append
(list-intersperse (map (lambda (f arg sty)
Expand All @@ -2105,8 +2102,8 @@
(list-intersperse (cond ((== (length args) (length sty))
(map (lambda (x y) (string-append x ":" (f y))) sty args)
) ;
((>= 1 (length sty))
(map (lambda (y) (string-append (car sty) ":" (f y))) args)
((>= 1 (length args))
(map (lambda (x) (string-append x ":" (f (car args)))) sty)
) ;
(else '())
) ;cond
Expand Down Expand Up @@ -2662,7 +2659,10 @@

(define (tmhtml-css-post body)
(if (pair? body)
`(,(car body) ,@(tmhtml-breaks-post* (map tmhtml-css-post (cdr body))))
(if (symbol? (car body))
`(,(car body) ,@(tmhtml-breaks-post* (map tmhtml-css-post (cdr body))))
(map tmhtml-css-post body)
) ;if
body
) ;if
) ;define
Expand Down
5 changes: 5 additions & 0 deletions TeXmacs/plugins/html/progs/convert/mathml/tmmath.scm
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,10 @@
;; Other constructs
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define (tmmath-ornament l)
`(m:mrow (@ (style "border: 1px solid black; padding: 0.2em; display: inline-block;"))
,(tmmath (car l))))

(define (tmmath-noop l) "")

(define (tmmath-hspace l)
Expand Down Expand Up @@ -378,6 +382,7 @@
(surround tmmath-surround)
(move tmmath-first)
(resize tmmath-first)
(ornament tmmath-ornament)
(with tmmath-with))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
67 changes: 67 additions & 0 deletions TeXmacs/tests/tmu/0642.tmu
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<TMU|<tuple|1.1.0|2026.2.7-rc18>>

<style|<tuple|generic|number-europe|british>>

<\body>
<\framed>
<\definition>
\;

<\equation*>
<decorated|G<rsub|B>=log<rsub|10><around*|(|<frac|P<rsub|1>|P<rsub|2>>|)>>
</equation*>

<\equation*>
<decorated|G<rsub|dB>=10*log<rsub|10><around*|(|<frac|P<rsub|1>|P<rsub|2>>|)>>
</equation*>
</definition>
</framed>

\;

<\framed>
<\equation*>
<decorated|\<alpha\>\<beta\>>
</equation*>
</framed>

<\decorated>
<\framed>
ddddd
</framed>
</decorated>
<\framed>
<\decorated>
ccccc
</decorated>
</framed>
</body>

<\initial>
<\collection>
<associate|page-even-footer|<tformat|<cwith|1|-1|1|-1|cell-halign|c>|<tformat|<twith|table-width|1par>|<twith|table-hmode|exact>|<cwith|1|1|1|1|cell-width|0.3par>|<cwith|1|1|1|1|cell-hmode|exact>|<cwith|1|1|3|3|cell-width|0.3par>|<cwith|1|1|3|3|cell-hmode|exact>|<cwith|1|1|2|2|cell-width|0.4par>|<cwith|1|1|2|2|cell-hmode|exact>|<cwith|1|1|1|1|cell-halign|l>|<cwith|1|1|3|3|cell-halign|r>|<table|<row|<cell|>|<cell|<page-the-page>>|<cell|>>>>>>
<associate|page-even-header|>
<associate|page-medium|paper>
<associate|page-odd-footer|<tformat|<cwith|1|-1|1|-1|cell-halign|c>|<tformat|<twith|table-width|1par>|<twith|table-hmode|exact>|<cwith|1|1|1|1|cell-width|0.3par>|<cwith|1|1|1|1|cell-hmode|exact>|<cwith|1|1|3|3|cell-width|0.3par>|<cwith|1|1|3|3|cell-hmode|exact>|<cwith|1|1|2|2|cell-width|0.4par>|<cwith|1|1|2|2|cell-hmode|exact>|<cwith|1|1|1|1|cell-halign|l>|<cwith|1|1|3|3|cell-halign|r>|<table|<row|<cell|>|<cell|<page-the-page>>|<cell|>>>>>>
<associate|page-odd-header|>
<associate|page-screen-margin|false>
<associate|stem-doc-id|EC0BE75C-1D03-4D50-8C5B-357D4D1F6AB0>
</collection>
</initial>

<\references>
<\collection>
<associate|auto-1|<tuple|1|1|../Library/Containers/com.tencent.xinWeChat/Data/Documents/xwechat_files/wxid_bk0rw2pj57ka22_b9ec/msg/file/2026-06/Frequency Response.tmu>>
<associate|auto-2|<tuple|1.1|4|../Library/Containers/com.tencent.xinWeChat/Data/Documents/xwechat_files/wxid_bk0rw2pj57ka22_b9ec/msg/file/2026-06/Frequency Response.tmu>>
</collection>
</references>

<\auxiliary>
<\collection>
<\associate|toc>
<with|par-left|<quote|1tab>|1<space|2spc>Bode Plots<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-1>>

<with|par-left|<quote|2tab>|1.1<space|2spc>Parallel Resonance<datoms|<macro|x|<repeat|<arg|x>|<with|font-series|medium|<with|font-size|1|<space|0.05fn>.<space|0.05fn>>>>>|<htab|5mm>><no-break><pageref|auto-2>>
</associate>
</collection>
</auxiliary>
44 changes: 44 additions & 0 deletions devel/0642.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# [0642] 修复 framed 内部 decorated 块的 HTML 导出问题

## 1 相关文档
- [dddd.md](dddd.md) - 任务文档模板
- [0642.md](0642.md) - 本任务文档

## 2 任务相关的代码文件
- `TeXmacs/plugins/html/progs/convert/html/tmhtml.scm` - HTML 导出样式与转换逻辑

## 3 如何测试

### 3.1 确定性测试(单元测试)

### 3.2 非确定性测试(文档验证)
```bash
# 验证 HTML 导出无报错且生成正确背景与内边距样式
xmake r stem --headless -c TeXmacs/tests/tmu/0642.tmu test_headless_fixed.html -q
```

## 4 如何提交

提交前执行以下最少步骤:

```bash
# 格式化变更的文件(此处为 Scheme/TMU 文件)
gf fmt --changed-since=main
```

## 5 What
修复了在 `framed` 内部的 `decorated` 块 HTML 导出样式不正确/失效的 bug。

1. 修改了 `tmhtml-ornament-get-env-style` 中 `funs` 与 `stys` 的提取逻辑,正确解析 `tmhtml-env` 中保存的 CSS 转换函数与样式名列表。
2. 修复了当 `args` 长度为 1 而 `sty` 长度不为 1 时(如一维内边距)样式值匹配被丢弃的 bug,完美支持 `padding-left` 与 `padding-right` 对称导出。

## 6 Why
在原实现中,由于 `funs` 和 `stys` 的提取存在逻辑颠倒:
- `funs` 错误地获取了 symbol 键(如 `:ornament-color`),而 `stys` 获取了转换函数(如 `tmcolor->htmlcolor`),从而丢失了真实的 HTML 样式属性名。
- 在后续求值中,Scheme 尝试对 symbol 作为函数进行调用,导致抛出异常,整个 `decorated` (其核心展开为 `ornament`) 的属性解析完全失效,导致背景、内边距等核心样式完全丢失。

## 7 How
1. 将 `funs` 修改为映射 `last` 函数,正确获取 `key` 列表最后的转换过程:`(funs (map last l2))`。
2. 将 `stys` 修改为过滤去首尾后剩下的样式键名称列表:`(stys (map (lambda (x) (reverse (cdr (reverse (cdr x))))) l2))`。
3. 修正多参数映射的降级判断,将 `((>= 1 (length sty))` 纠正为 `((>= 1 (length args))`,使单值输入时能正确应用到其所有的多属性上。