From 69e7a98a2f8044362597de31789b43b955e1fc7a Mon Sep 17 00:00:00 2001 From: Aaron Ecay Date: Fri, 8 Mar 2013 13:31:38 -0500 Subject: [PATCH 1/3] Add support for link properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * lisp/org-element.el (org-element-link-parser): include :properties in plist of parsed link * lisp/org.el (org-make-link-string): don’t escape properties * lisp/ox-html.el (org-html-link) lisp/ox-latex.el (org-latex-link): pass link properties to org-link-protocols functions The properties of a link are appended to the link path, separated by the string “&&”. Each property should have the form key=val. No escaping is applied to key or val, and they must not contain an “=” character. The properties of a link are passed as the optional fourth argument to export functions defined by org-add-link-type and org-link-protocols. (Currently only for the HTML and LaTeX backends). --- lisp/org-element.el | 18 ++++++++++++++---- lisp/org.el | 15 +++++++++------ lisp/ox-html.el | 3 ++- lisp/ox-latex.el | 3 ++- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/lisp/org-element.el b/lisp/org-element.el index 6810b98..b944ffd 100644 --- a/lisp/org-element.el +++ b/lisp/org-element.el @@ -2982,7 +2982,7 @@ Assume point is at the beginning of the link." (save-excursion (let ((begin (point)) end contents-begin contents-end link-end post-blank path type - raw-link link search-option application) + raw-link link search-option application properties) (cond ;; Type 1: Text targeted from a radio target. ((and org-target-link-regexp (looking-at org-target-link-regexp)) @@ -2998,9 +2998,18 @@ Assume point is at the beginning of the link." ;; abbreviation in it. raw-link (org-translate-link (org-link-expand-abbrev - (org-match-string-no-properties 1))) - link (org-link-unescape raw-link)) - ;; Determine TYPE of link and set PATH accordingly. + (org-match-string-no-properties 1)))) + (when (string-match "&&" raw-link) + (let ((components (split-string raw-link "&&")) + p) + (setq raw-link (nth 0 components)) + (dolist (prop (cdr components)) + (setq p (split-string prop "=")) + (setq properties (plist-put properties + (intern (concat ":" (nth 0 p))) + (nth 1 p)))))) + (setq link (org-link-unescape raw-link)) + ;; Determine TYPE of link and set PATH accordingly. (cond ;; File type. ((or (file-name-absolute-p link) (string-match "^\\.\\.?/" link)) @@ -3058,6 +3067,7 @@ Assume point is at the beginning of the link." :raw-link (or raw-link path) :application application :search-option search-option + :properties properties :begin begin :end end :contents-begin contents-begin diff --git a/lisp/org.el b/lisp/org.el index 811506a..5611adb 100644 --- a/lisp/org.el +++ b/lisp/org.el @@ -9449,12 +9449,15 @@ according to FMT (default from `org-email-link-description-format')." (not (string-match (org-image-file-name-regexp) link)) (not (equal link (org-link-escape link)))) (setq description (org-extract-attributes link))) - (setq link - (cond ((string-match (org-image-file-name-regexp) link) link) - ((string-match org-link-types-re link) - (concat (match-string 1 link) - (org-link-escape (substring link (match-end 1))))) - (t (org-link-escape link)))) + (let ((parts (split-string link "&&"))) + (setq link (nth 0 parts)) + (setq link + (cond ((string-match (org-image-file-name-regexp) link) link) + ((string-match org-link-types-re link) + (concat (match-string 1 link) + (org-link-escape (substring link (match-end 1))))) + (t (org-link-escape link)))) + (setq link (mapconcat #'identity (cons link (cdr parts)) "&&"))) (concat "[[" link "]" (if description (concat "[" description "]") "") "]")) diff --git a/lisp/ox-html.el b/lisp/ox-html.el index 829fe28..9d5fdc7 100644 --- a/lisp/ox-html.el +++ b/lisp/ox-html.el @@ -2630,7 +2630,8 @@ INFO is a plist holding contextual information. See (org-export-resolve-coderef path info))))) ;; Link type is handled by a special function. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols)))) - (funcall protocol (org-link-unescape path) desc 'html)) + (funcall protocol (org-link-unescape path) desc + 'html (org-element-property :properties link))) ;; External link with a description part. ((and path desc) (format "%s" path attributes desc)) ;; External link without a description part. diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el index d17dd60..a1cacf0 100644 --- a/lisp/ox-latex.el +++ b/lisp/ox-latex.el @@ -1948,7 +1948,8 @@ INFO is a plist holding contextual information. See (org-export-resolve-coderef path info))) ;; Link type is handled by a special function. ((functionp (setq protocol (nth 2 (assoc type org-link-protocols)))) - (funcall protocol (org-link-unescape path) desc 'latex)) + (funcall protocol (org-link-unescape path) desc + 'latex (org-element-property link :properties))) ;; External link with a description part. ((and path desc) (format "\\href{%s}{%s}" path desc)) ;; External link without a description part. -- 1.8.1.5