emacs-orgmode
[Top][All Lists]
Advanced

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

[PATCH] org-element-export-snippet-parser: Fix snippets without ending @


From: Ihor Radchenko
Subject: [PATCH] org-element-export-snippet-parser: Fix snippets without ending @@
Date: Sat, 16 Apr 2022 13:17:38 +0800

There is an edge case when parsing export snippets:

@@html:fo aksjdaksjd ajs d

askdjas aksj daj sao@@

Our current parser recognises the opening "@@html:" as a standalone
snippet.

Unless I misunderstand something, it is not intentional.

The fix is attached.

Nicolas, unless you have any objections, I will install the attached
patch to bugfix.

Best,
Ihor

>From c866dcc8e593da2fca2611b100b4ab3ea9641e03 Mon Sep 17 00:00:00 2001
Message-Id: 
<c866dcc8e593da2fca2611b100b4ab3ea9641e03.1650085947.git.yantar92@gmail.com>
From: Ihor Radchenko <yantar92@gmail.com>
Date: Sat, 16 Apr 2022 13:08:57 +0800
Subject: [PATCH] org-element-export-snippet-parser: Fix snippets without
 ending @@

* lisp/org-element.el (org-element-export-snippet-parser): Do not
recognise snippets without closing @@ as empty "@@backend:" snippets.

Example:
@@html:fo aksjdaksjd ajs d

askdjas aksj daj sao@@

Reported in
https://github.com/lucasvreis/org-parser/blob/master/SPEC.org#export-snippets
---
 lisp/org-element.el | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/lisp/org-element.el b/lisp/org-element.el
index 9db1406b3..661902e04 100644
--- a/lisp/org-element.el
+++ b/lisp/org-element.el
@@ -2980,8 +2980,9 @@ (defun org-element-export-snippet-parser ()
       (when (and (looking-at "@@\\([-A-Za-z0-9]+\\):")
                 (setq contents-end
                       (save-match-data (goto-char (match-end 0))
-                                       (re-search-forward "@@" nil t)
-                                       (match-beginning 0))))
+                                        (when
+                                           (re-search-forward "@@" nil t)
+                                         (match-beginning 0)))))
        (let* ((begin (match-beginning 0))
               (back-end (match-string-no-properties 1))
               (value (buffer-substring-no-properties
-- 
2.35.1

Parsed buffer without patch:

Note (export-snippet (:back-end "html" :value "@@html:" :begin 1 :end 8
:post-blank 0 :parent #2))

(org-data
 (:begin 1 :contents-begin 1 :contents-end 52 :end 52 :robust-begin 3 
:robust-end 50 :post-blank 0 :post-affiliated 1 :path "/tmp/bug.org" :mode 
org-data :CATEGORY "bug" :granularity nil)
 (section
  (:begin 1 :end 52 :contents-begin 1 :contents-end 52 :robust-begin 1 
:robust-end 50 :post-blank 0 :post-affiliated 1 :mode first-section 
:granularity nil :parent #0)
  (paragraph
   (:begin 1 :end 29 :contents-begin 1 :contents-end 28 :post-blank 1 
:post-affiliated 1 :mode top-comment :granularity nil :parent #1)
   (export-snippet
    (:back-end "html" :value "@@html:" :begin 1 :end 8 :post-blank 0 :parent 
#2))
   #("fo aksjdaksjd ajs d\n" 0 20
     (:parent #2)))
  (paragraph
   (:begin 29 :end 52 :contents-begin 29 :contents-end 52 :post-blank 0 
:post-affiliated 29 :mode nil :granularity nil :parent #1)
   #("askdjas aksj daj sao@@\n" 0 23
     (:parent #2)))))

With patch:

(org-data
 (:begin 1 :contents-begin 1 :contents-end 52 :end 52 :robust-begin 3 
:robust-end 50 :post-blank 0 :post-affiliated 1 :path "/tmp/bug.org" :mode 
org-data :CATEGORY "bug" :granularity nil)
 (section
  (:begin 1 :end 52 :contents-begin 1 :contents-end 52 :robust-begin 1 
:robust-end 50 :post-blank 0 :post-affiliated 1 :mode first-section 
:granularity nil :parent #0)
  (paragraph
   (:begin 1 :end 29 :contents-begin 1 :contents-end 28 :post-blank 1 
:post-affiliated 1 :mode top-comment :granularity nil :parent #1)
   #("@@html:fo aksjdaksjd ajs d\n" 0 27
     (:parent #2)))
  (paragraph
   (:begin 29 :end 52 :contents-begin 29 :contents-end 52 :post-blank 0 
:post-affiliated 29 :mode nil :granularity nil :parent #1)
   #("askdjas aksj daj sao@@\n" 0 23
     (:parent #2)))))

reply via email to

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