在Emacs中,当htmlize emacs缓冲区时,如何将链接导出到可点击链接?

whu*_*nmr 5 html lisp emacs elisp org-mode

背景

  1. 我使用伟大的htmlize.el导出我的组织模式缓冲区内容与字体hi-lock.
  2. Emacs组织模式具有链接格式.

问题

例如,这是一个包含内容的组织模式文件:

[[http://hunmr.blogspot.com][blog]]
Run Code Online (Sandbox Code Playgroud)

当我使用Htmlize.el将缓冲区html化为HTML内容时,链接丢失了.生成HTML像:

<span style="hyperlinkFOOBAR">blog</span>
Run Code Online (Sandbox Code Playgroud)

预期

我希望它产生可点击的链接,如:

<a style="hyperlinkFOOBAR" href="http://hunmr.blogspot.com">blog</a>
Run Code Online (Sandbox Code Playgroud)

EDIT1 org-export-as-html可以导出链接,但不能为Hi-locks创建CSS.

  • 您是否知道将组织模式链接导出到HTML的其他方法?
  • 要使用elisp读取org-mode缓冲区中的真实链接,该怎么做?读文字属性?

感谢您的帮助,您的帮助将得到高度赞赏.

whu*_*nmr 1

感谢 @Andreas 的提示,我将以下代码添加到 htmlize.el 中。目前,org-link 可以被 html 化为可点击的链接。

代码已分享到github上:

https://github.com/whunmr/dotemacs/blob/master/site-lisp/htmlize.el

http://hunmr.blogspot.com/2012/08/enhance-htmlizeel-now-can-export-org.html

主要代码如下:

(defun expand-org-link (&optional buffer)
  "Change [[url][shortname]] to [[url] [shortname]] by adding a space between url and shortname"
  (goto-char (point-min))
  (while (re-search-forward "\\[\\[\\([^][]+\\)\\]\\(\\[\\([^][]+\\)\\]\\)?\\]"
                nil t)
    (let ((url (match-string 1))
      (link-text (match-string 3)))
      (delete-region (match-beginning 0) (match-end 0))
      (insert "[[" url "] [" link-text "]]"))))

(defun shrink-org-link (&optional buffer)
  "Change [[url] [shortname]] to [[url][shortname]], remove the space between url and shortname"
  (goto-char (point-min))
  (while (re-search-forward "\\[\\[\\([^][]+\\)\\] \\(\\[\\([^][]+\\)\\]\\)?\\]"
                nil t)
    (let ((url (match-string 1))
      (link-text (match-string 3)))
      (delete-region (match-beginning 0) (match-end 0))
      (insert "[[" url "][" link-text "]]"))))

(defun transform-org-link ()
  "transform htmlized <span> to <a>"
  (goto-char (point-min))
  (while (re-search-forward "\\[\\[<span \\([^>]+\\)>\\([^][]+\\)</span>\\] \\[\\([^][]+\\)\\]\\]"
                nil t)
    (let ((style (match-string 1))
          (url (match-string 2))
      (link-text (match-string 3)))
      (delete-region (match-beginning 0) (match-end 0))
      (insert "<a " style " href=\"" url "\">" link-text "</a>"))))
Run Code Online (Sandbox Code Playgroud)