all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* [PATCH] org-element-export-snippet-parser: Fix snippets without ending @@
@ 2022-04-16  5:17 Ihor Radchenko
  2022-04-16 10:46 ` Juan Manuel Macías
  2022-04-24  5:08 ` Ihor Radchenko
  0 siblings, 2 replies; 3+ messages in thread
From: Ihor Radchenko @ 2022-04-16  5:17 UTC (permalink / raw)
  To: Nicolas Goaziou, emacs-orgmode

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

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-org-element-export-snippet-parser-Fix-snippets-witho.patch --]
[-- Type: text/x-patch, Size: 1371 bytes --]

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


[-- Attachment #3: Type: text/plain, Size: 1817 bytes --]


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)))))

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] org-element-export-snippet-parser: Fix snippets without ending @@
  2022-04-16  5:17 [PATCH] org-element-export-snippet-parser: Fix snippets without ending @@ Ihor Radchenko
@ 2022-04-16 10:46 ` Juan Manuel Macías
  2022-04-24  5:08 ` Ihor Radchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Juan Manuel Macías @ 2022-04-16 10:46 UTC (permalink / raw)
  To: Ihor Radchenko; +Cc: orgmode

Ihor Radchenko writes:

> Our current parser recognises the opening "@@html:" as a standalone
> snippet.
>
> Unless I misunderstand something, it is not intentional.
>
> The fix is attached.

This fix makes a lot of sense to me. I've always been intrigued by this
'strange' behavior of html export snippets. Of course, the main danger of
this unintentional behavior is error propagation. I remember seeing it
on a few sites, like here: https://emacs.stackexchange.com/a/30470

Best regards,

Juan Manuel 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] org-element-export-snippet-parser: Fix snippets without ending @@
  2022-04-16  5:17 [PATCH] org-element-export-snippet-parser: Fix snippets without ending @@ Ihor Radchenko
  2022-04-16 10:46 ` Juan Manuel Macías
@ 2022-04-24  5:08 ` Ihor Radchenko
  1 sibling, 0 replies; 3+ messages in thread
From: Ihor Radchenko @ 2022-04-24  5:08 UTC (permalink / raw)
  To: Nicolas Goaziou; +Cc: emacs-orgmode

Ihor Radchenko <yantar92@gmail.com> writes:

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

Applied.

I installed the patch onto main as 96529e933 (Bastien asked to refrain from modifying
bugfix until Org 9.5.4, unless there is a critical bug).

Best,
ihor


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-04-24  5:08 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-16  5:17 [PATCH] org-element-export-snippet-parser: Fix snippets without ending @@ Ihor Radchenko
2022-04-16 10:46 ` Juan Manuel Macías
2022-04-24  5:08 ` Ihor Radchenko

Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.