In Emacs, How to export Links to a clickable link, when htmlize emacs buffer?
BACKGROUND
PROBLEM
For Example, here is a org-mode file with contents:
[[http://hunmr.blogspot.com][blog]]
When I Using Htmlize.el to htmlize buffer to HTML contents, The link was missing. produces HTML like:
<span style="hyperlinkFOOBAR">blog</span>
EXPECTED
I expected it produces clickable link like:
<a style="hyperlinkFOOBAR" href="http://hunmr.blogspot.com">blog</a>
QUESTION
EDIT1 The org-export-as-html can export link, but can not create CSS for the Hi-locks.
THANKS IN ADVANCE, YOUR HELP WILL BE HIGHLY APPRECIATED.
org-export-as-html应该是DTRT
Thanks for @Andreas 's hints, I add following code to htmlize.el. Currently the org-link can be htmlized to clickable link.
The code was shared on github:
https://github.com/whunmr/dotemacs/blob/master/site-lisp/htmlize.el
and
http://hunmr.blogspot.com/2012/08/enhance-htmlizeel-now-can-export-org.html
FOLLOWING IS THE MAIN CODE:
(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>"))))
链接地址: http://www.djcxy.com/p/30638.html