>背景
- 我使用很棒的htmlize.el来导出带有字体hi-lock的组织模式缓冲区内容。
- Emacs org-mode 有一个链接格式。
问题
例如,下面是一个包含以下内容的组织模式文件:
[[http://hunmr.blogspot.com][blog]]
当我使用 Htmlize.el 将缓冲区 htmlize 为 HTML 内容时,链接丢失了。生成如下 HTML:
<span style="hyperlinkFOOBAR">blog</span>
预期
我希望它会产生可点击的链接,例如:
<a style="hyperlinkFOOBAR" href="http://hunmr.blogspot.com">blog</a>
问题
EDIT1 org-export-as-html 可以导出链接,但不能为 Hi-locks 创建 CSS。
- 您知道将组织模式链接导出为 HTML 的其他方法吗?
- 要使用 elisp 在组织模式缓冲区中读取真实链接,该怎么做? 阅读文本财产?
提前感谢您的帮助。
org-export-as-html 应该 DTRT
感谢您@Andreas的提示,我将以下代码添加到 htmlize.el。目前,组织链接可以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>"))))