branch: elpa/adoc-mode commit 9c395f4bf91b82966bff3a4ce1540e5164bc66df Author: sensorflo <sensor...@gmail.com> Commit: sensorflo <sensor...@gmail.com>
it's now less likely that text between two adjacent delimited blocks is misinterpreted as delimited block But sadly that also introduces a bug: contrary to the specification in the AsciiDoc manual, adoc-mode does not allow that either the first line or the last line of a delimited block is blank. --- adoc-mode-test.el | 41 +++++++++++++++++++++++++++++++++++++++++ adoc-mode.el | 25 ++++++++++++++++++++++--- 2 files changed, 63 insertions(+), 3 deletions(-) diff --git a/adoc-mode-test.el b/adoc-mode-test.el index 68ca1efaa4..4e93454f9b 100644 --- a/adoc-mode-test.el +++ b/adoc-mode-test.el @@ -191,6 +191,47 @@ removed before TRANSFORM is evaluated. "sidebar line 1\nsidebar line 2" markup-secondary-text-face "\n" nil "********" markup-meta-hide-face "\n")) +;; Don't mistake text between two same delimited blocks as a delimited block, +;; i.e. wrongly treating the end of block 1 as a beginning and wrongly +;; treating the beginning of block 2 as ending. +(ert-deftest adoctest-test-delimited-blocks-simple () + (adoctest-faces "delimited-blocks-special-case" + + "--------" markup-meta-hide-face "\n" nil + "11\n12\n13\n14" markup-code-face "\n" nil + "--------" markup-meta-hide-face "\n" nil + "\n" nil + "lorem" 'no-face "\n" nil + "\n" nil + "--------" markup-meta-hide-face "\n" nil + "21\n22\n23\n24" markup-code-face "\n" nil + "--------" markup-meta-hide-face "\n" nil + "\n" nil + "ipsum" 'no-face "\n" nil)) + +(ert-deftest adoctest-test-delimited-blocks-simple () + (adoctest-faces "delimited-blocks-empty" + "////////" markup-meta-hide-face "\n" nil + "////////" markup-meta-hide-face "\n" nil + "\n" nil + "++++++++" markup-meta-hide-face "\n" nil + "++++++++" markup-meta-hide-face "\n" nil + "\n" nil + "--------" markup-meta-hide-face "\n" nil + "--------" markup-meta-hide-face "\n" nil + "\n" nil + "........" markup-meta-hide-face "\n" nil + "........" markup-meta-hide-face "\n" nil + "\n" nil + "________" markup-meta-hide-face "\n" nil + "________" markup-meta-hide-face "\n" nil + "\n" nil + "========" markup-meta-hide-face "\n" nil + "========" markup-meta-hide-face "\n" nil + "\n" nil + "********" markup-meta-hide-face "\n" nil + "********" markup-meta-hide-face "\n")) + (ert-deftest adoctest-test-open-block () (adoctest-faces "open-block" "--" markup-meta-hide-face "\n" nil diff --git a/adoc-mode.el b/adoc-mode.el index 632f68abac..1c2708c979 100644 --- a/adoc-mode.el +++ b/adoc-mode.el @@ -900,13 +900,32 @@ Subgroups: adoc-delimited-block-del "\\|") "\\)")) +;; KLUDGE: Contrary to what the AsciiDoc manual specifies, adoc-mode does not +;; allow that either the first or the last line within a delmited block is +;; blank. That shall help to prevent the case that adoc-mode wrongly +;; interprets the end of a delimited block as the beginning, and the beginning +;; of a following delimited block as the ending, thus wrongly interpreting the +;; text between two adjacent delimited blocks as delimited block. It is +;; expected that it is unlikely that one wants to begin or end a delimited +;; block with a blank line, and it is expected that it is likely that +;; delimited blocks are surrounded by blank lines. (defun adoc-re-delimited-block (del) (let* ((tmp (nth del adoc-delimited-block-del)) (start (if (consp tmp) (car tmp) tmp)) (end (if (consp tmp) (cdr tmp) tmp))) (concat "\\(" start "\\)[ \t]*\n" - "\\(\\(?:.*\n\\)*?\\)" + "\\(" + ;; a single leading non-blank line + "[ \t]*[^ \t\n].*\n" + ;; optionally followed by + "\\(?:" + ;; any number of arbitrary lines followed by + "\\(?:.*\n\\)*?" + ;; a trailing non blank line + "[ \t]*[^ \t\n].*\n" + "\\)??" + "\\)??" "\\(" end "\\)[ \t]*$"))) ;; TODO: since its multiline, it doesn't yet work properly. @@ -1399,8 +1418,8 @@ Concerning TYPE, LEVEL and SUB-TYPE see `adoc-re-llisti'." '(0 '(face nil font-lock-multiline t) t) '(1 '(face markup-meta-hide-face adoc-reserved block-del) t) (if (not inhibit-text-reserved) - `(2 '(face ,text-face face markup-verbatim-face adoc-reserved t) t) - `(2 ,text-face t)) + `(2 '(face ,text-face face markup-verbatim-face adoc-reserved t) t t) + `(2 ,text-face t t)) '(3 '(face markup-meta-hide-face adoc-reserved block-del) t))) ;; if adoc-kw-delimited-block, adoc-kw-two-line-title don't find the whole