org-babel源代码块中的超链接?

时间:2016-05-18 14:35:56

标签: emacs org-mode org-babel

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

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

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

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

1 个答案:

答案 0 :(得分:1)

现在可能不可能(从org-mode 8.3.4开始)。 HTML导出引擎当前似乎没有转义受保护字符的机制。您应该提交实现它或提交功能请求! (https://azure.microsoft.com/en-us/documentation/samples/active-directory-dotnet-daemon/

一些解决方法:

使用原始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 ?\0)))
    ;; 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链接。

相关问题