When non-nil use user-defined names and ID over internal ones.
By default, Org generates its own internal ID values during HTML
export. This process ensures that these values are unique and
valid, but the keys are not available in advance of the export
process, and not so readable.
When this variable is non-nil, Org will use NAME keyword, or the
real name of the target to create the ID attribute.
Independently of this variable, however, CUSTOM_ID are always
used as a reference.
我读下来的理解是,如果有 CUSTOM_ID 会优先使用(heading 我就是都设置了 CUSTOM_ID 避免变化),如果用户自己定义了 NAME,或者对应的元素有名字(“ or the real name of the target”) 就会用这个作为 ID。
这就意味着,我启用了这个配置,应该还需要给 figure、details 等设置一个 name?如果没有设置,还是会用默认的 org id 生成逻辑。
但是这些 figure 的 ID 我本来就不在意,我还需要额外想一个唯一的 name 设置上去,感觉有些麻烦(我也尝试过,但不知道是不是设置的语法不对,也没生效)
看了一下 ox-html-stable-ids.el,如果 heading 是中文的话,转换的 id 应该也是中文?所以你需要用 Quail 解析中文,获取拼音用作 id?
em…我目前不太在意 heading 这个 id 的可读性,只要是一个不会发生变化的唯一的 id 就好了。
我的做法是每次保存 org 文件,都给 heading 生成 ID 和 CUSTOM_ID 的 properties,这样在我导出的时候,就会用 CUSTOM_ID 作为 id 了。
我是通过 org-mode-hook 中的 before-save-hook 实现的:
相关代码
(defun spike-leung/org-add-custom-id-to-headings-in-files ()
"Add a CUSTOM_ID property to all headings in the current buffer, if it does not already exist."
(interactive)
(org-map-entries
(lambda ()
(unless (org-entry-get nil "CUSTOM_ID")
(let ((custom-id (org-id-new)))
(org-set-property "CUSTOM_ID" custom-id))))))
(add-hook 'org-mode-hook
(lambda ()
(add-hook 'before-save-hook 'spike-leung/org-add-custom-id-to-headings-in-files nil 'local)))
AI 很可能直接给我一个 <\\(\\(?:details\\|\\(?:figu\\|p\\)re\\)\\)\\([^>]*\\)\\([[:space:]]id=\\s\"org[[:xdigit:]]*\\s\"\\)\\([^>]*\\)>,也许能用,但实在不直观,后面我就不知道怎么维护了。
当然我知道 rx 的话,也可以让 AI 帮我用 rx 写,我最开始也让它写了一个,但或许是我用法不对,没有给它足够的文档,也可能是模型没选对,我只给了一段 prompt,它给到我的结果并不好。