组织模式导出到html:链接在新标签中打开?

时间:2013-01-08 15:05:52

标签: org-mode

在从org-mode创建的html中,如果指定为

,则可以在新选项卡中打开链接
#+ATTR_HTML: target="_blank" 
[[http://cnn.com][CNN]]

我找到了here

但是,如果[[http://cnn.com][CNN]]是项目符号项,则无效。例如,

#+ATTR_HTML: target="_blank" 
- [[http://cnn.com][CNN]]

或者

- #+ATTR_HTML: target="_blank" 
  [[http://cnn.com][CNN]]

1)如何使这项工作,以及2)我可以通过在顶部指定某个形式的此选项(可能是#+OPTIONS:的某个参数)来为特定页面上的所有链接设置此html属性吗?

3 个答案:

答案 0 :(得分:2)

简答:替换函数org-export-attach-captions-and-attributes中的字符串:

diff -u -L /home/eab/.emacs.d/el-get/org-mode/lisp/org-exp.el -L \#\<buffer\ el-get/org-exp.el\> /home/eab/.emacs.d/el-get/org-mode/lisp/org-exp.el /tmp/buffer-content-8644Ge2
--- /home/eab/.emacs.d/el-get/org-mode/lisp/org-exp.el
+++ #<buffer el-get/org-exp.el>
@@ -1935,7 +1935,7 @@
            "\\|"
            "^[ \t]*\\(|[^-]\\)"
            "\\|"
-           "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
+           "^.*\\[\\[.*\\]\\][ \t]*$"))
    cap shortn attr label end)
     (while (re-search-forward re nil t)
       (cond

关于麻烦的长篇评论。 让我们看一下函数的源代码,它将#+ATTR_BACKEND解析为文本属性。

(defun org-export-attach-captions-and-attributes (target-alist)
  "Move #+CAPTION, #+ATTR_BACKEND, and #+LABEL text into text properties.
If the next thing following is a table, add the text properties to the first
table line.  If it is a link, add it to the line containing the link."
  (goto-char (point-min))
  (remove-text-properties (point-min) (point-max)
              '(org-caption nil org-attributes nil))
  (let ((case-fold-search t)
    (re (concat "^[ \t]*#\\+caption:[ \t]+\\(.*\\)"
            "\\|"
            "^[ \t]*#\\+attr_" (symbol-name org-export-current-backend) ":[ \t]+\\(.*\\)"
            "\\|"
            "^[ \t]*#\\+label:[ \t]+\\(.*\\)"
            "\\|"
            "^[ \t]*\\(|[^-]\\)"
            "\\|"
            "^[ \t]*\\[\\[.*\\]\\][ \t]*$"))
...)))
在这种情况下,

org-export-current-backendHTML。 它适用于此类文本

#+ATTR_HTML: target="_blank" 
[[http://cnn.com][CNN]]
像这样:

1)通过regexp #+ATTR_HTML: target="_blank"

解析整行"^[ \t]*#\\+attr_"...

2)通过regexp [[http://cnn.com][CNN]]

解析整行"^[ \t]*\\[\\[.*\\]\\][ \t]*$"

3)在导出到html

之前删除字符串#+ATTR_HTML: target="_blank"

4)为行target="_blank"设置属性[[http://cnn.com][CNN]]

然后org-mode使用此属性准备要导出的html链接。

如果我用"^[ \t]*\\[\\[.*\\]\\][ \t]*$"替换字符串"^.*\\[\\[.*\\]\\][ \t]*$",则此修补函数适用于

#+ATTR_HTML: target="_blank" 
  - [[http://cnn.com][CNN]]

太。但是列表存在问题

  - [[http://cnn.com][CNN]] 
  - [[http://cnn.com][CNN]]
  - some text

如果我在每个链接之前添加ATTR_HTML

#+ATTR_HTML: target="_blank" 
  - [[http://cnn.com][CNN]] 
#+ATTR_HTML: target="_blank" 
  - [[http://cnn.com][CNN]]
  - some text

然后我得到这样的输出html

* CNN

* CNN
* some text

列表中有一个额外的差距。所以,我不能得到这样的输出

* CNN
* CNN
* some text

* CNN

* CNN

* some text

此示例演示了org-mode在某些情况下不灵活。我可以编写lisp函数,为导出文本中的所有链接设置此html属性,并将此功能添加到#+OPTIONS:或其他内容。但是我不能以这种方式使越来越多的组织模式导出系统复杂化,因为存在一些组织模式语法限制 - 它很简单。

如果我遇到像这样的org-publish问题,我想:除了org-mode之外,我可能需要其他化妆品吗? )

答案 1 :(得分:1)

我发现添加了以下作品:

getContentType()

答案 2 :(得分:0)

如果你有几个链接,你可以将 html 包含到你的模板中,就像这样

My projects
- @@html:<a href="https://example.com" target="_blank">Example</a>@@
相关问题