【问题标题】:In Emacs, How to export Links to a clickable link, when htmlize emacs buffer?在 Emacs 中,当 htmlize emacs 缓冲区时,如何将链接导出到可点击的链接?
【发布时间】:2012-08-09 21:06:58
【问题描述】:

背景

  1. 我使用了很棒的htmlize.el 来导出我的组织模式缓冲区内容,字体为hi-lock.
  2. Emacs 组织模式有一个Link format.

问题

例如,这是一个包含内容的 org-mode 文件:

[[http://hunmr.blogspot.com][blog]]

当我使用 Htmlize.el 将缓冲区 html 化为 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-mode缓冲区中的真实链接,该怎么做?阅读文本 财产?

在此先感谢您的帮助,我们将不胜感激。

【问题讨论】:

  • CLUE1 我找到了代码,org-mode 如何在 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) 待续

标签: html emacs lisp elisp org-mode


【解决方案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>"))))

【讨论】:

    【解决方案2】:

    org-export-as-html 应该 DTRT

    【讨论】:

    • 嗨@Andreas,感谢您的帮助。我使用 htmlize.el 的主要原因是在导出后保持 Hi-lock 模式突出显示。但是 org-export-as-html 目前不能保留高亮字体。所以我想也许我们需要在 htmlize.el 中添加链接导出功能。
    • 非常感谢,也许我可以从 org-export-as-html 的代码中找到一些重要的线索。
    猜你喜欢
    • 1970-01-01
    • 2011-06-19
    • 1970-01-01
    • 2021-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-05
    相关资源
    最近更新 更多