From: Ihor Radchenko <yantar92@gmail.com>
To: Nicolas Goaziou <mail@nicolasgoaziou.fr>, emacs-orgmode@gnu.org
Subject: [PATCH] org-element-export-snippet-parser: Fix snippets without ending @@
Date: Sat, 16 Apr 2022 13:17:38 +0800 [thread overview]
Message-ID: <87ee1xd2tp.fsf@localhost> (raw)
[-- 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)))))
next reply other threads:[~2022-04-16 5:17 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-16 5:17 Ihor Radchenko [this message]
2022-04-16 10:46 ` [PATCH] org-element-export-snippet-parser: Fix snippets without ending @@ Juan Manuel Macías
2022-04-24 5:08 ` Ihor Radchenko
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=87ee1xd2tp.fsf@localhost \
--to=yantar92@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=mail@nicolasgoaziou.fr \
/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).