5

BACKGROUND

  1. I using great htmlize.el to export my org-mode buffer contents with font hi-lock.
  2. Emacs org-mode has a Link format.

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.

  • Do you know other ways to to export org-mode links to HTML?
  • To read the real link in org-mode buffer using elisp, how to do that? read text property?

THANKS IN ADVANCE, YOUR HELP WILL BE HIGHLY APPRECIATED.

Community
  • 1
  • 1
whunmr
  • 2,435
  • 2
  • 22
  • 35
  • **CLUE1** I find the code, how org-mode show the link in OVERVIEW. `(defun org-columns-compact-links (s) "Replace [[link][desc]] with [desc] or [link]." (while (string-match org-bracket-link-regexp s) (setq s (replace-match (concat "[" (match-string (if (match-end 3) 3 1) s) "]") t t s))) s)` **TO BE CONTINUE** – whunmr Aug 14 '12 at 15:44

2 Answers2

1

org-export-as-html should DTRT

Andreas Röhler
  • 4,804
  • 14
  • 18
  • Hi @Andreas, thanks for your help. The main reason I use the htmlize.el is to Keep the Hi-lock patterns highlighted, after exporting. But org-export-as-html currently can not keep the highlight fonts. So I think maybe we need add the link exporting function to the htmlize.el. – whunmr Aug 14 '12 at 11:44
  • Great thanks, maybe I can find some important clues from code of org-export-as-html . – whunmr Aug 14 '12 at 11:52
1

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>"))))
whunmr
  • 2,435
  • 2
  • 22
  • 35