From 160820bc9498e9364103e72b55a27cf92576dbb8 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Mon, 13 Apr 2015 00:47:07 +0200 Subject: [PATCH] ox: Implement `org-export-get-reference' * lisp/ox.el (org-export-get-reference): New function. * etc/ORG-NEWS: Signal new function. --- etc/ORG-NEWS | 1 + lisp/ox.el | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/etc/ORG-NEWS b/etc/ORG-NEWS index f930058ca..2f0a7c4df 100644 --- a/etc/ORG-NEWS +++ b/etc/ORG-NEWS @@ -279,6 +279,7 @@ in the output, depending on the parameters. *** Extend ~org-export-first-sibling-p~ and ~org-export-last-sibling-p~ These functions now support any element or object, not only headlines. *** New function: ~org-export-table-row-in-header-p~ +*** New function: ~org-export-get-reference~ *** New function: ~org-element-lineage~ This function deprecates ~org-export-get-genealogy~. It also provides more features. See docstring for details. diff --git a/lisp/ox.el b/lisp/ox.el index d91b3c559..2a7e45dde 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -4165,9 +4165,31 @@ has type \"radio\"." ;;;; For References ;; +;; `org-export-get-reference' associate a unique reference for any +;; object or element. +;; ;; `org-export-get-ordinal' associates a sequence number to any object ;; or element. +(defun org-export-get-reference (datum info) + "Return a unique reference for DATUM, as a string. +DATUM is either an element or an object. INFO is the current +export state, as a plist. Returned reference consists of +alphanumeric characters only." + (let ((type (org-element-type datum)) + (cache (or (plist-get info :internal-references) + (let ((h (make-hash-table :test #'eq))) + (plist-put info :internal-references h) + h)))) + (or (gethash datum cache) + (puthash datum + (format "org%s%d" + (if type + (replace-regexp-in-string "-" "" (symbol-name type)) + "secondarystring") + (incf (gethash type cache 0))) + cache)))) + (defun org-export-get-ordinal (element info &optional types predicate) "Return ordinal number of an element or object. -- 2.11.4.GIT