我按照这个帖子设置了 org-emphasis-regexp-components
这个变量,并且在 Emacs 中能够成功渲染出行内中文加粗的效果,但是奇怪的时候在导出之后仍然没有加粗,而是保留了 **
已经在 Emacs -q 中复现了这个问题,Emacs 版本号是 29.1,使用内置的 Org 9.6.6
我按照这个帖子设置了 org-emphasis-regexp-components
这个变量,并且在 Emacs 中能够成功渲染出行内中文加粗的效果,但是奇怪的时候在导出之后仍然没有加粗,而是保留了 **
已经在 Emacs -q 中复现了这个问题,Emacs 版本号是 29.1,使用内置的 Org 9.6.6
因为 org-mode 渲染用的是 org-do-emphasis-faces
,而 parse 用的是 org-element--parse-generic-emphasis
(后者比较新), 所以旧的方法有点不适用,需要在原来的基础上对 org-element--parse-generic-emphasis
做点修改:
(defun eli/org-element--parse-generic-emphasis (mark type)
"Parse emphasis object at point, if any.
MARK is the delimiter string used. TYPE is a symbol among
`bold', `code', `italic', `strike-through', `underline', and
`verbatim'.
Assume point is at first MARK."
(save-excursion
(let ((origin (point)))
(unless (bolp) (forward-char -1))
(let ((opening-re
(rx-to-string
`(seq (or line-start (any space ?- ?\( ?' ?\" ?\{ nonascii))
,mark
(not space)))))
(when (looking-at opening-re)
(goto-char (1+ origin))
(let ((closing-re
(rx-to-string
`(seq
(not space)
(group ,mark)
(or (any space ?- ?. ?, ?\; ?: ?! ?? ?' ?\" ?\) ?\} ?\\ ?\[
nonascii)
line-end)))))
(when (re-search-forward closing-re nil t)
(let ((closing (match-end 1)))
(goto-char closing)
(let* ((post-blank (skip-chars-forward " \t"))
(contents-begin (1+ origin))
(contents-end (1- closing)))
(list type
(append
(list :begin origin
:end (point)
:post-blank post-blank)
(if (memq type '(code verbatim))
(list :value
(and (memq type '(code verbatim))
(buffer-substring
contents-begin contents-end)))
(list :contents-begin contents-begin
:contents-end contents-end)))))))))))))
(advice-add #'org-element--parse-generic-emphasis :override #'eli/org-element--parse-generic-emphasis)
这样就可以了
当然为了稳定可以使用零宽空格,虽然在 org 开发者内部对是否全面接受零宽空格还没有统一意见,不过零宽空格是在 [:space:]
范围内的,所以肯定没有兼容性问题。
渲染和输出不一致太奇怪了,不知道这是bug还是feature
That’s a bug in fontification code originated from inconsistency between parser and fontification. But tricky to fix. See [DISCUSSION] Refactoring fontification system
这是字体化代码中的一个错误,源于解析器和字体化之间的不一致。 但修复起来很棘手。 请参阅[DISCUSSION] Refactoring fontification system
We do accept it, because it is documented in the manual. But we admit that it is awkward, with its own problems when zero-width space renders differently on export. Still looking to settle on some better solution - several have been proposed.
我们确实接受它,因为它记录在手册中。 但我们承认这很尴尬,当零宽度空间在导出时呈现不同的效果时,它也有自己的问题。 仍在寻求一些更好的解决方案 - 已经提出了一些解决方案。