将Org-mode文件导出为HTML后,链接行为出现意外情况

3
我正在Windows 7 Ultimate的Emacs 24.3.1中运行Org-mode 8.2.6,并在从Org-mode导出的HTML中遇到了一个问题。我已经广泛使用org-id为Org-mode文件中的标题分配唯一ID(存储在标题的:PROPERTIES:抽屉中)。
在Org-mode 8.0引入新的导出框架之前,所有这些链接都可以正常工作。无论标题层次的级别如何,导出的基于ID的链接都能很好地工作。但是,使用新的导出框架会产生不同的结果。现在,当目标标题位于导出设置中定义的标题级别以下时(默认为级别3:H:3),基于ID的链接总是失败。注意:这仅适用于导出的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邮件列表报告了这个问题,问题已经得到解决。 - brgil
2个回答

1
我也遇到了这个问题。此外,在org-7.9中,被"<<"和">>"包围的文本可以在导出的HTML中显示,而在org-8.2中则不能显示。
由于声望有限,我无法为该项投票,因此我在此回答而没有正确答案。(=_=)

很抱歉你也遇到了同样的问题,但我也很高兴知道不仅仅是我!感谢你的反馈。 - brgil

0

看一下org-html-headline函数的代码,似乎“标准标题”情况(导出到hN的任何内容)特别处理了自定义ID:

(let* (...
       (ids (remove nil
                    (list (org-element-property :CUSTOM_ID headline)
                          (concat "sec-" section-number)
                          (org-element-property :ID headline))))
       (preferred-id (car ids)) ;; <- here, id for the header is sec-XXX
       (extra-ids (cdr ids))
       ...)
  (format ...
          (format "outline-container-%s"
                  (or (org-element-property :CUSTOM_ID headline)
                      (concat "sec-" section-number)))
          ...
          (format "\n<h%d id=\"%s\">%s%s</h%d>\n"
                  level1
                  preferred-id
                  (mapconcat
                   (lambda (x)
                     (let ((id (org-export-solidify-link-text
                                (if (org-uuidgen-p x) (concat "ID-" x)
                                  x))))
                       (org-html--anchor id))) ;; <- generate a list of <a id=ID-XXX></a>
                   extra-ids "")
                  full-text
                  level1)
          ...))

这就是那些<a id="ID-XXX" name="ID-XXX"></a>片段的来源(占位符锚点,只是为了暴露一个额外的ID)

不幸的是,在翻译成列表项的标题的情况下,没有处理ID / CUSTOM_ID的方法,这对我来说看起来像是一个错误。 因此,虽然可以重写org-html-headline以对列表项进行相同的处理,但这并不像修改设置那样容易(代码修改可能会很脆弱)

我建议提交一个错误报告,毕竟这似乎是一个退步。


我的代码解读与你描述的基本一致,但我想可能有些地方我漏掉了。因此,在我看来,这似乎是一个 bug。我会将其报告为 bug。感谢你的意见。 - brgil

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接