emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <n.goaziou@gmail.com>
To: Bastien <bzg@gnu.org>
Cc: Noah Slater <nslater@tumbolia.org>, emacs-orgmode@gnu.org
Subject: Re: Radio targets with mixed capitalisation do not work in HTML export
Date: Sun, 23 Mar 2014 18:13:09 +0100	[thread overview]
Message-ID: <87zjkglty2.fsf@gmail.com> (raw)
In-Reply-To: <87r45v8vz7.fsf@bzg.ath.cx> (Bastien's message of "Fri, 21 Mar 2014 15:30:52 +0100")

[-- Attachment #1: Type: text/plain, Size: 1208 bytes --]

Hello,

Bastien <bzg@gnu.org> writes:

> Nicolas Goaziou <n.goaziou@gmail.com> writes:
>
>> For example, `org-make-target-link-regexp' generates a regexp enclosed
>> within "\\<...\\>". Unfortunately, that will not match a radio link
>> starting with an entity, e.g., <<<\alpha-test>>> \alpha-test. It is
>> probably due to the fact that radio targets were initially meant to
>> contain only plain text, not Org syntax.
>
> FWIW, I'd be fine to only allow plain text in radio targets, instead
> of the full syntax.  Your take.
>
>>> It's one of the last thing I want to get fixed before we release Org
>>> 8.2.3.
>>
>> If you don't mind, I need a bit more time (around a week) for 8.2.3. In
>> particular, there are speed issues in `org-element-context' that I would
>> like to fix first.
>
> Sure -- there is absolutely no rush, and I have my own share of things
> I need to fix too, so let's no hurry at all.  I was mentioning 8.2.3
> because Stefan created the emacs-24 branch, which means that the move
> toward Emacs 24.4 is accelerating now, but there is no deadline that
> I'm aware of.

Here are 3 patches (for maint) fixing radio-target behaviour.

Feedback welcome.


Regards,

-- 
Nicolas Goaziou

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Change-and-syntax-to-symbol.patch --]
[-- Type: text/x-diff, Size: 1082 bytes --]

From a55057e99d72241d039a1f8d57ced3cbb5dcb68d Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Sun, 23 Mar 2014 11:23:08 +0100
Subject: [PATCH 1/3] Change "\" and "~" syntax to symbol

* lisp/org.el (org-mode): Change "\" and "~" characters syntax from
  `punctuation' to `symbol' so they are on par with other characters used
  in Org syntax (e.g., "/", "*"...).

This change is needed to correctly find radio links starting with an
entity:

  <<<\alpha-test>>> \alpha-test
---
 lisp/org.el | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/lisp/org.el b/lisp/org.el
index 70bf19e..56ae096 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -5341,6 +5341,8 @@ The following commands are available:
   ;; Modify a few syntax entries
   (modify-syntax-entry ?@ "w")
   (modify-syntax-entry ?\" "\"")
+  (modify-syntax-entry ?\\ "_")
+  (modify-syntax-entry ?~ "_")
   (if org-startup-truncated (setq truncate-lines t))
   (when org-startup-indented (require 'org-indent) (org-indent-mode 1))
   (org-set-local 'font-lock-unfontify-region-function
-- 
1.9.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: 0002-Fix-radio-target-parsing.patch --]
[-- Type: text/x-diff, Size: 7191 bytes --]

From 2f46aae4d602402f201c8d3291a985de374d7593 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Sun, 23 Mar 2014 11:28:26 +0100
Subject: [PATCH 2/3] Fix radio target parsing

* lisp/org-element.el (org-element-all-successors,
  org-element-object-restrictions): Prioritize `link' over other
  successors in order to find radio links starting with another syntax
  object (e.g., an entity).  Also allow text markup within radio
  targets.
(org-element-link-parser): Add contents to radio targets.

* lisp/org.el (org-make-target-link-regexp): Fix regexp so it can
  match targets starting with an Org object (i.e., an entity).
(org-ctrl-c-ctrl-c): Fix function when applied on an object contained
within a radio target.

* testing/lisp/test-org-element.el (test-org-element/radio-target-parser): Add test.
* testing/lisp/test-ox.el (test-org-export/resolve-radio-link): Add test.
---
 lisp/org-element.el              | 19 +++++++++++--------
 lisp/org.el                      | 10 ++++++----
 testing/lisp/test-org-element.el | 15 +++++++++++----
 testing/lisp/test-ox.el          |  9 +++++++++
 4 files changed, 37 insertions(+), 16 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 9bb7944..9589714 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -187,10 +187,10 @@ is not sufficient to know if point is at a paragraph ending.  See
   "List of recursive element types aka Greater Elements.")
 
 (defconst org-element-all-successors
-  '(export-snippet footnote-reference inline-babel-call inline-src-block
-		   latex-or-entity line-break link macro plain-link radio-target
-		   statistics-cookie sub/superscript table-cell target
-		   text-markup timestamp)
+  '(link export-snippet footnote-reference inline-babel-call
+	 inline-src-block latex-or-entity line-break macro plain-link
+	 radio-target statistics-cookie sub/superscript table-cell target
+	 text-markup timestamp)
   "Complete list of successors.")
 
 (defconst org-element-object-successor-alist
@@ -328,13 +328,13 @@ Don't modify it, set `org-element-affiliated-keywords' instead.")
       (paragraph ,@standard-set)
       ;; Remove any variable object from radio target as it would
       ;; prevent it from being properly recognized.
-      (radio-target latex-or-entity sub/superscript)
+      (radio-target latex-or-entity sub/superscript text-markup)
       (strike-through ,@standard-set)
       (subscript ,@standard-set)
       (superscript ,@standard-set)
       ;; Ignore inline babel call and inline src block as formulas are
       ;; possible.  Also ignore line breaks and statistics cookies.
-      (table-cell export-snippet footnote-reference latex-or-entity link macro
+      (table-cell link export-snippet footnote-reference latex-or-entity macro
 		  radio-target sub/superscript target text-markup timestamp)
       (table-row table-cell)
       (underline ,@standard-set)
@@ -346,7 +346,8 @@ a list of successors that will be called within an element or
 object of such type.
 
 For example, in a `radio-target' object, one can only find
-entities, latex-fragments, subscript and superscript.
+entities, latex-fragments, subscript, superscript and text
+markup.
 
 This alist also applies to secondary string.  For example, an
 `headline' type element doesn't directly contain objects, but
@@ -3095,7 +3096,9 @@ Assume point is at the beginning of the link."
        ((and org-target-link-regexp (looking-at org-target-link-regexp))
 	(setq type "radio"
 	      link-end (match-end 0)
-	      path (org-match-string-no-properties 0)))
+	      path (org-match-string-no-properties 0)
+	      contents-begin (match-beginning 0)
+	      contents-end (match-end 0)))
        ;; Type 2: Standard link, i.e. [[http://orgmode.org][homepage]]
        ((looking-at org-bracket-link-regexp)
 	(setq contents-begin (match-beginning 3)
diff --git a/lisp/org.el b/lisp/org.el
index 56ae096..6d6fbeb 100644
--- a/lisp/org.el
+++ b/lisp/org.el
@@ -6097,7 +6097,7 @@ The regular expression finds the targets also if there is a line break
 between words."
   (and targets
        (concat
-	"\\<\\("
+	"\\_<\\("
 	(mapconcat
 	 (lambda (x)
 	   (setq x (regexp-quote x))
@@ -6106,7 +6106,7 @@ between words."
 	   x)
 	 targets
 	 "\\|")
-	"\\)\\>")))
+	"\\)\\_>")))
 
 (defun org-activate-tags (limit)
   (if (re-search-forward (org-re "^\\*+.*[ \t]\\(:[[:alnum:]_@#%:]+:\\)[ \r\n]") limit t)
@@ -20262,13 +20262,15 @@ This command does many different things, depending on context:
 	  ;; When at a link, act according to the parent instead.
 	  (link (setq context (org-element-property :parent context))
 		(setq type (org-element-type context)))
-	  ;; Unsupported object types: check parent element instead.
+	  ;; Unsupported object types: refer to the first supported
+	  ;; element or object containing it.
 	  ((bold code entity export-snippet inline-babel-call inline-src-block
 		 italic latex-fragment line-break macro strike-through subscript
 		 superscript underline verbatim)
 	   (while (and (setq context (org-element-property :parent context))
 		       (not (memq (setq type (org-element-type context))
-				  '(paragraph verse-block table-cell)))))))
+				  '(radio-target paragraph verse-block
+						 table-cell)))))))
 	;; For convenience: at the first line of a paragraph on the
 	;; same line as an item, apply function on that item instead.
 	(when (eq type 'paragraph)
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index c65151e..9d00af9 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -1688,12 +1688,19 @@ Outside list"
   "Test `radio-target' parser."
   ;; Standard test.
   (should
-   (org-test-with-temp-text "<<<radio>>>"
-     (org-element-map (org-element-parse-buffer) 'radio-target 'identity)))
+   (eq 'radio-target
+       (org-test-with-temp-text "<<<radio>>>"
+	 (org-element-type (org-element-context)))))
   ;; Radio targets with objects.
   (should
-   (org-test-with-temp-text "<<<radio \\alpha>>>"
-     (org-element-map (org-element-parse-buffer) 'radio-target 'identity))))
+   (eq 'radio-target
+       (org-test-with-temp-text "<<<radio \\alpha>>>"
+	 (org-element-type (org-element-context)))))
+  ;; Radio targets starting with an object.
+  (should
+   (eq 'radio-target
+       (org-test-with-temp-text "<<<\\alpha radio>>>"
+	 (org-element-type (org-element-context))))))
 
 
 ;;;; Section
diff --git a/testing/lisp/test-ox.el b/testing/lisp/test-ox.el
index f5572d3..759e7a1 100644
--- a/testing/lisp/test-ox.el
+++ b/testing/lisp/test-ox.el
@@ -1858,6 +1858,15 @@ Another text. (ref:text)
        (org-export-resolve-radio-link
 	(org-element-map tree 'link 'identity info t)
 	info))))
+  ;; Radio target with objects at its beginning.
+  (should
+   (org-test-with-temp-text "<<<\\alpha radio>>> \\alpha radio"
+     (org-update-radio-target-regexp)
+     (let* ((tree (org-element-parse-buffer))
+	    (info `(:parse-tree ,tree)))
+       (org-export-resolve-radio-link
+	(org-element-map tree 'link 'identity info t)
+	info))))
   ;; Multiple radio targets.
   (should
    (equal '("radio1" "radio2")
-- 
1.9.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #4: 0003-export-back-ends-Update-radio-target-export.patch --]
[-- Type: text/x-diff, Size: 5926 bytes --]

From 3a1c47e9d96b7c43abd9fba246c61dc757027d01 Mon Sep 17 00:00:00 2001
From: Nicolas Goaziou <n.goaziou@gmail.com>
Date: Sun, 23 Mar 2014 18:04:22 +0100
Subject: [PATCH 3/3] export back-ends: Update radio target export

* contrib/lisp/ox-groff.el (org-groff-link):
* lisp/ox-ascii.el (org-ascii-link):
* lisp/ox-beamer.el (org-beamer-link):
* lisp/ox-html.el (org-html-link):
* lisp/ox-latex.el (org-latex-link):
* lisp/ox-md.el (org-md-link):
* lisp/ox-odt.el (org-odt-link): Update radio target export according
  to recent changes.

See 2f46aae4d602402f201c8d3291a985de374d7593.
---
 contrib/lisp/ox-groff.el |  3 ++-
 lisp/ox-ascii.el         |  5 +----
 lisp/ox-beamer.el        |  5 +++--
 lisp/ox-html.el          |  6 +++---
 lisp/ox-latex.el         |  5 +++--
 lisp/ox-md.el            |  4 +---
 lisp/ox-odt.el           | 10 +++++-----
 7 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/contrib/lisp/ox-groff.el b/contrib/lisp/ox-groff.el
index 1141292..1990f87 100644
--- a/contrib/lisp/ox-groff.el
+++ b/contrib/lisp/ox-groff.el
@@ -1274,7 +1274,8 @@ INFO is a plist holding contextual information.  See
       (let ((destination (org-export-resolve-radio-link link info)))
         (when destination
           (format "\\fI [%s] \\fP"
-                  (org-export-solidify-link-text path)))))
+                  (org-export-solidify-link-text
+		   (org-element-property :value destination))))))
 
      ;; Links pointing to a headline: find destination and build
      ;; appropriate referencing command.
diff --git a/lisp/ox-ascii.el b/lisp/ox-ascii.el
index e8f1b1f..11ce0c3 100644
--- a/lisp/ox-ascii.el
+++ b/lisp/ox-ascii.el
@@ -1387,10 +1387,7 @@ INFO is a plist holding contextual information."
 		(org-export-resolve-coderef ref info))))
      ;; Do not apply a special syntax on radio links.  Though, use
      ;; transcoded target's contents as output.
-     ((string= type "radio")
-      (let ((destination (org-export-resolve-radio-link link info)))
-	(when destination
-	  (org-export-data (org-element-contents destination) info))))
+     ((string= type "radio") desc)
      ;; Do not apply a special syntax on fuzzy links pointing to
      ;; targets.
      ((string= type "fuzzy")
diff --git a/lisp/ox-beamer.el b/lisp/ox-beamer.el
index 3102b62..41de7a6 100644
--- a/lisp/ox-beamer.el
+++ b/lisp/ox-beamer.el
@@ -690,8 +690,9 @@ used as a communication channel."
 	(when destination
 	  (format "\\hyperlink%s{%s}{%s}"
 		  (or (org-beamer--element-has-overlay-p link) "")
-		  (org-export-solidify-link-text path)
-		  (org-export-data (org-element-contents destination) info)))))
+		  (org-export-solidify-link-text
+		   (org-element-property :value destination))
+		  contents))))
      ((and (member type '("custom-id" "fuzzy" "id"))
 	   (let ((destination (if (string= type "fuzzy")
 				  (org-export-resolve-fuzzy-link link info)
diff --git a/lisp/ox-html.el b/lisp/ox-html.el
index cabf2b6..c590d86 100644
--- a/lisp/ox-html.el
+++ b/lisp/ox-html.el
@@ -2721,9 +2721,9 @@ INFO is a plist holding contextual information.  See
       (let ((destination (org-export-resolve-radio-link link info)))
 	(when destination
 	  (format "<a href=\"#%s\"%s>%s</a>"
-		  (org-export-solidify-link-text path)
-		  attributes
-		  (org-export-data (org-element-contents destination) info)))))
+		  (org-export-solidify-link-text
+		   (org-element-property :value destination))
+		  attributes desc))))
      ;; Links pointing to a headline: Find destination and build
      ;; appropriate referencing command.
      ((member type '("custom-id" "fuzzy" "id"))
diff --git a/lisp/ox-latex.el b/lisp/ox-latex.el
index 9421a93..00e941b 100644
--- a/lisp/ox-latex.el
+++ b/lisp/ox-latex.el
@@ -1813,8 +1813,9 @@ INFO is a plist holding contextual information.  See
       (let ((destination (org-export-resolve-radio-link link info)))
 	(when destination
 	  (format "\\hyperref[%s]{%s}"
-		  (org-export-solidify-link-text path)
-		  (org-export-data (org-element-contents destination) info)))))
+		  (org-export-solidify-link-text
+		   (org-element-property :value destination))
+		  desc))))
      ;; Links pointing to a headline: Find destination and build
      ;; appropriate referencing command.
      ((member type '("custom-id" "fuzzy" "id"))
diff --git a/lisp/ox-md.el b/lisp/ox-md.el
index 39843d5..84e075d 100644
--- a/lisp/ox-md.el
+++ b/lisp/ox-md.el
@@ -307,9 +307,7 @@ a communication channel."
 	   (let ((ref (org-element-property :path link)))
 	     (format (org-export-get-coderef-format ref contents)
 		     (org-export-resolve-coderef ref info))))
-	  ((equal type "radio")
-	   (let ((destination (org-export-resolve-radio-link link info)))
-	     (org-export-data (org-element-contents destination) info)))
+	  ((equal type "radio") contents)
 	  ((equal type "fuzzy")
 	   (let ((destination (org-export-resolve-fuzzy-link link info)))
 	     (if (org-string-nw-p contents) contents
diff --git a/lisp/ox-odt.el b/lisp/ox-odt.el
index 1e966fe..da2ca3f 100644
--- a/lisp/ox-odt.el
+++ b/lisp/ox-odt.el
@@ -2735,11 +2735,11 @@ INFO is a plist holding contextual information.  See
      ((string= type "radio")
       (let ((destination (org-export-resolve-radio-link link info)))
 	(when destination
-	  (let ((desc (org-export-data (org-element-contents destination) info))
-		(href (org-export-solidify-link-text path)))
-	    (format
-	     "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
-	     href desc)))))
+	  (format
+	   "<text:bookmark-ref text:reference-format=\"text\" text:ref-name=\"OrgXref.%s\">%s</text:bookmark-ref>"
+	   (org-export-solidify-link-text
+	    (org-element-property :value destination))
+	   desc))))
      ;; Links pointing to a headline: Find destination and build
      ;; appropriate referencing command.
      ((member type '("custom-id" "fuzzy" "id"))
-- 
1.9.1


  parent reply	other threads:[~2014-03-23 17:12 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-02 17:24 Radio targets with mixed capitalisation do not work in HTML export Noah Slater
2014-03-17  2:02 ` Bastien
2014-03-17 10:11   ` Nicolas Goaziou
2014-03-17 11:29     ` Bastien
2014-03-17 12:04       ` Bastien
2014-03-17 14:27         ` Nicolas Goaziou
2014-03-17 15:50           ` Bastien
2014-03-20 21:58             ` Bastien
2014-03-21 14:25               ` Nicolas Goaziou
2014-03-21 14:30                 ` Bastien
2014-03-21 17:25                   ` Nicolas Goaziou
2014-03-21 17:28                     ` Bastien
2014-03-21 18:47                       ` Noah Slater
2014-03-21 21:38                         ` Bastien
2014-03-23 17:13                   ` Nicolas Goaziou [this message]
2014-03-23 17:26                     ` Bastien
2014-03-24 10:24                       ` Nicolas Goaziou
2014-03-24 14:11                         ` Bastien
2014-03-25  9:24                           ` Nicolas Goaziou
2014-03-25 11:07                             ` Bastien
2014-03-24 13:23                       ` Nicolas Goaziou
2014-03-17 12:38       ` Nicolas Goaziou
2014-03-17 12:59         ` Bastien
2014-03-17 13:11           ` Nicolas Goaziou
2014-03-17 14:18             ` Bastien

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87zjkglty2.fsf@gmail.com \
    --to=n.goaziou@gmail.com \
    --cc=bzg@gnu.org \
    --cc=emacs-orgmode@gnu.org \
    --cc=nslater@tumbolia.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).