[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Re: [BUG] Underlined text in parentheses is not exported correct

From: Ihor Radchenko
Subject: [PATCH] Re: [BUG] Underlined text in parentheses is not exported correctly
Date: Fri, 31 Dec 2021 22:43:07 +0800

Juan Manuel Macías <maciaschain@posteo.net> writes:

>> The priority appears to be intentional.
> I see. But then the compatibility with the rest of the emphasis is
> broken. I mean, the user would expect things like (_underline_) will be
> exported as (\uline{underline}), in the same way that (/emphasis/) is
> exported as (\emph{emphasis}). I would say there is a slight
> inconsistency in the syntax here.

I agree with you. I think that the initial intention was to avoid
parsing things like (x+y)_1+x_2 as underline.

However, thinking about it more, I feel that prioritising underline
should work better. The underline parser recently got changed into a
stricter version. Now, only underlines starting after spaces,-,(,',",
and { are recognised as an underlines.

So, the attached patch is changing the priority of the parsing.
Maybe Nicolas knows some tricky cases when the patch makes things wrong,
but those cases are certainly not covered by tests.


>From 12272f1ea89c169dcbece009c3a227e354019366 Mon Sep 17 00:00:00 2001
From: Ihor Radchenko <yantar92@gmail.com>
Date: Fri, 31 Dec 2021 22:39:03 +0800
Subject: [PATCH] Fix underline parser inside parenthesis

* lisp/org-element.el (org-element--object-lex): prioritise underline
parser over subscript.  `org-element-underline-parser' is more strict
compared to `org-element-subscript-parser'.
* testing/lisp/test-org-element.el (test-org-element/underline-parser):
Add test.

Fixes 87v8z52eom.fsf@posteo.net/T/#t">https://list.orgmode.org/87v8z52eom.fsf@posteo.net/T/#t
 lisp/org-element.el              |  8 ++++----
 testing/lisp/test-org-element.el | 11 ++++++++++-
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 45ddc79b7..c9d1d80bb 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -4850,10 +4850,10 @@ (defun org-element--object-lex (restriction)
                    (pcase (char-after)
                      (?^ (and (memq 'superscript restriction)
-                     (?_ (or (and (memq 'subscript restriction)
-                                  (org-element-subscript-parser))
-                             (and (memq 'underline restriction)
-                                  (org-element-underline-parser))))
+                     (?_ (or (and (memq 'underline restriction)
+                                  (org-element-underline-parser))
+                              (and (memq 'subscript restriction)
+                                  (org-element-subscript-parser))))
                      (?* (and (memq 'bold restriction)
                      (?/ (and (memq 'italic restriction)
diff --git a/testing/lisp/test-org-element.el b/testing/lisp/test-org-element.el
index 338204eab..b58d71c8c 100644
--- a/testing/lisp/test-org-element.el
+++ b/testing/lisp/test-org-element.el
@@ -2661,7 +2661,16 @@ (ert-deftest test-org-element/underline-parser ()
      (org-test-with-temp-text "_first line\nsecond line_"
           (org-element-parse-buffer) 'underline #'identity nil t)))
-    '("first line\nsecond line"))))
+    '("first line\nsecond line")))
+  ;; Starting after non-blank
+  (should
+   (eq 'underline
+       (org-test-with-temp-text "(_under<point>line_)"
+         (org-element-type (org-element-context)))))
+  (should-not
+   (eq 'underline
+       (org-test-with-temp-text "x_under<point>line_)"
+         (org-element-type (org-element-context))))))
 ;;;; Verbatim

reply via email to

[Prev in Thread] Current Thread [Next in Thread]