whu*_*nmr 5 html lisp emacs elisp org-mode
背景
问题
例如,这是一个包含内容的组织模式文件:
[[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.
感谢您的帮助,您的帮助将得到高度赞赏.
感谢 @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)