org.babel源代码块内的超链接



我想在org.babel源代码块的注释上有一些超链接。我的目标是将文件导出为html,并能够跟踪一些引用,如下面的最小示例所示:

#+BEGIN_SRC lisp
(princ "Hello World!") ;; [[stackoverflow.com/blabla1234][Got this from SO.]]
#+END_SRC

"问题"是链接没有嵌入到源代码块中(这实际上很有意义)。

有没有一种方法可以覆盖这种行为,或者在src块中插入超链接的替代语法?

现在可能不可能(从组织模式8.3.4开始)。HTML导出引擎目前似乎没有转义受保护字符的机制。您应该提交实现它或提交功能请求!(详细信息)

一些解决方法:

使用原始HTML模拟输出

您可以输出原始HTML,否则它看起来像源块,并且它将在链接完整的情况下呈现:

#+BEGIN_HTML
<pre class="src src-sh">
(princ "Hello World!") ;; <a href="stackoverflow.com/blabla1234">Got this from SO.</a>
</pre>
#+END_HTML

防止替换如果你的代码没有大于和小于符号,你可以防止它们被取代

(setq org-html-protect-char-alist '(("&" . "&amp;"))

或者如果不起作用:

(setq htmlize-basic-character-table
  ;; Map characters in the 0-127 range to either one-character strings
  ;; or to numeric entities.
  (let ((table (make-vector 128 ?)))
    ;; Map characters in the 32-126 range to themselves, others to
    ;; &#CODE entities;
    (dotimes (i 128)
      (setf (aref table i) (if (and (>= i 32) (<= i 126))
                   (char-to-string i)
                 (format "&#%d;" i))))
    ;; Set exceptions manually.
    (setf
     ;; Don't escape newline, carriage return, and TAB.
     (aref table ?n) "n"
     (aref table ?r) "r"
     (aref table ?t) "t"
     ;; Escape &, <, and >.
     (aref table ?&) "&amp;"
     ;;(aref table ?<) "&lt;"
     ;;(aref table ?>) "&gt;"
     ;; Not escaping '"' buys us a measurable speedup.  It's only
     ;; necessary to quote it for strings used in attribute values,
     ;; which htmlize doesn't typically do.
     ;(aref table ?") "&quot;"
     )
    table))

请注意,这两种方法都是简单地不转义HTML标记分隔符本身的技巧。如果语法高亮显示应用于任何字符,它将通过插入<span>的来中断生成的HTML链接。

最新更新