【发布时间】:2023-12-27 19:19:01
【问题描述】:
我在 Windows 7 Ultimate 上的 Emacs 24.3.1 中运行 Org-mode 8.2.6,并且遇到了从 Org-mode 导出的 HTML 中链接如何工作的特殊性。我已经广泛使用org-id 为组织模式文件中的标题分配唯一ID(存储在标题的:PROPERTIES: 抽屉中)。
在 Org-mode 8.0 中引入新的导出器框架之前,所有这些链接都可以正常工作。无论标题层次结构的级别如何,导出的基于 HTML ID 的链接都可以正常工作。但是,使用新的导出器框架会产生不同的结果。现在,当目标标题位于导出设置中定义的标题级别以下时,基于 ID 的链接总是会失败,默认为级别 3 (H:3)。注意:这仅适用于导出的 HTML;基于 ID 的链接在 Emacs 中完美运行。
这是一个最小的示例,演示了我将其导出为 HTML 时的这种行为(有关详细信息,请参阅注释):
* Headline Level 1
** Headline Level 2
*** Headline Level 3
:PROPERTIES:
:ID: 307db49e-e001-4a7b-9541-96eee2ae6f06
:END:
**** <<heading-level-4>>Non-headline level
:PROPERTIES:
:ID: 3be9179d-f838-4052-93ca-6c76c9aff12d
:END:
** Headline Level 2
*** Headline Level 3
Now I want to link to information that appears elsewhere in the file. Links work as
expected within Emacs. When exported to HTML, however, links do not work as they
did before the new exporter framework was introduced in Org-mode 8.0.
**** ID-based link: [[id:307db49e-e001-4a7b-9541-96eee2ae6f06][Headline Level 3]]
This link /does/ work. Using IDs always works for links to any headline level. By
"headline level" I mean any Org-mode heading that is defined as a headline
(default H:3).
**** ID-based link: [[id:3be9179d-f838-4052-93ca-6c76c9aff12d][Non-headline level]]
This link using the ID /doesn't/ work when exported to HTML using the new exporter
framework. Now, using IDs as the target for links /always/ fails for links to any
headline lower than the headline level defined in the export settings.
**** Non-ID-based link: [[heading-level-4][Non-headline level]]
Using an internal link works, but I have /many/ existing files that depend on IDs
for links at heading levels lower than the levels I want treated as (numbered)
headlines, and I also sometimes link to targets in other files, in which case,
using ID's creates a much simpler workflow.
如果上面的文件名为demo-links.org,则默认输出文件为demo-links.html。第一个工作链接的目标 HTML 如下所示:
<h4 id="sec-1-1-1"><a id="ID-307db49e-e001-4a7b-9541-96eee2ae6f06" name="ID-307db49e-e001-4a7b-9541-96eee2ae6f06"></a><span class="section-number-4">1.1.1</span> Headline Level 3</h4>
链接的 HTML 如下所示:
<a href="#sec-1-1-1">Headline Level 3</a>
链接 ID 是目标代码的一部分,但不用于链接代码。
无效链接目标的 HTML 如下所示:
<ul class="org-ul"><li><a id="heading-level-4" name="heading-level-4"></a>Non-headline level<br /><div class="outline-text-5" id="text-1-1-1-1"></div></li></ul>
请注意,生成的代码不包含 ID (3be9179d-f838-4052-93ca-6c76c9aff12d)。它也不像上一个链接那样包含部分 ID。
指向它的链接的 HTML 如下所示:
<a href="#sec-1-1-1-1">Non-headline level</a>
我相信ox-html.el 中的相关代码出现在评论“指向标题的链接”之后,但我是 elisp 的新手(充其量)。
我的问题是:这种行为是设计使然,还是我可以更改某些设置以使导出工作的方式与引入新导出框架之前的方式一样?
【问题讨论】:
-
我向 Org-mode 邮件列表报告了这个问题,问题已得到解决。