[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[O] [RFC] Change in export block syntax
From: |
Nicolas Goaziou |
Subject: |
[O] [RFC] Change in export block syntax |
Date: |
Mon, 26 Oct 2015 15:09:57 +0100 |
Hello,
This one is a long standing issue. I didn't include it in the projects
thread since the patch was almost finished.
Basically, syntax between export blocks and special blocks is ambiguous,
as it depends on the export back-end loaded. For example,
#+begin_odt
<<target>>
#+end_odt
will be parsed very differently if `ox-odt' is loaded or not. In the
former case, the target is inactive whereas in the latter case, it can
be reached with an internal link.
As a solution, export blocks are explicitly marked as such at the syntax
level to disambiguate their parsing from special blocks. The new syntax
is:
#+BEGIN_EXPORT backend
...
#+END_EXPORT
instead of
#+BEGIN_backend
...
#+END_backend
So, basically, "export" is a reserved block type, much like "src". As
a consequence, =INCLUDE= keywords syntax is modified, e.g.,
,#+INCLUDE: "file.org" HTML
becomes
,#+INCLUDE: "file.org" export html
The following function, included in ORG-NEWS, updates any Org document
to the new syntax. It is meant to be applied after applying the patch.
(defun org-repair-export-blocks ()
"Repair export blocks and INCLUDE keywords in current buffer."
(when (eq major-mode 'org-mode)
(let ((case-fold-search t)
(back-end-re (regexp-opt
'("HTML" "ASCII" "LATEX" "ODT" "MARKDOWN" "MD" "ORG"
"MAN" "BEAMER" "TEXINFO" "GROFF" "KOMA-LETTER")
t)))
(org-with-wide-buffer
(goto-char (point-min))
(let ((block-re (concat "^[ \t]*#\\+BEGIN_" back-end-re)))
(save-excursion
(while (re-search-forward block-re nil t)
(let ((element (save-match-data (org-element-at-point))))
(when (eq (org-element-type element) 'special-block)
(save-excursion
(goto-char (org-element-property :end element))
(save-match-data (search-backward "_"))
(forward-char)
(insert "EXPORT")
(delete-region (point) (line-end-position)))
(replace-match "EXPORT \\1" nil nil nil 1))))))
(let ((include-re
(format "^[ \t]*#\\+INCLUDE: .*?%s[ \t]*$" back-end-re)))
(while (re-search-forward include-re nil t)
(let ((element (save-match-data (org-element-at-point))))
(when (and (eq (org-element-type element) 'keyword)
(string= (org-element-property :key element)
"INCLUDE"))
(replace-match "EXPORT \\1" nil nil nil 1)))))))))
The patch is still lacking documentation update. Once applied, I plan to
implement two checkers in Org lint: one to detect old syntax and another
one to signal a missing back-end after BEGIN_EXPORT string.
Feedback welcome,
Regards,
--
Nicolas Goaziou 0x80A93738
0001-Change-export-block-syntax.patch
Description: Text Data
- [O] [RFC] Change in export block syntax,
Nicolas Goaziou <=