From fa7ee10641e42353faa786b2ba0808a6a782b5db Mon Sep 17 00:00:00 2001 From: fap Date: Sat, 31 Jul 2021 00:44:02 +0200 Subject: [PATCH] FIX: (adoc-promote): headings get wrongfully turned into sub-type 2 If the heading contains whitespace or a newline after the heading title it gets turned into a sub-type 2 heading. - add failing tests - fix issue by throwing away whitespace in match group 3 --- adoc-mode-test.el | 8 ++++++++ adoc-mode.el | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/adoc-mode-test.el b/adoc-mode-test.el index d4fdc67..966437e 100644 --- a/adoc-mode-test.el +++ b/adoc-mode-test.el @@ -696,6 +696,14 @@ removed before TRANSFORM is evaluated. (ert-deftest adoctest-test-promote-title () (adoctest-trans "= foo" "== foo" '(adoc-promote-title 1)) + (adoctest-trans "= + + bar" + "== foo + + bar" + '(adoc-promote-title 1)) + (adoctest-trans "= foo " "== foo" '(adoc-promote-title 1)) (adoctest-trans "===== foo" "= foo" '(adoc-promote-title 1)) (adoctest-trans "== foo" "==== foo" '(adoc-promote-title 2)) diff --git a/adoc-mode.el b/adoc-mode.el index 171437b..2b28789 100644 --- a/adoc-mode.el +++ b/adoc-mode.el @@ -175,6 +175,7 @@ (require 'markup-faces) ; https://github.com/sensorflo/markup-faces (require 'cl-lib) +(eval-when-compile (require 'subr-x)) (require 'tempo) (defconst adoc-mode-version "0.6.6" @@ -2699,7 +2700,7 @@ trailing delimiter ('== my title =='). ((looking-at (adoc-re-one-line-title level)) (setq type 1) (setq text (match-string 2)) - (setq sub-type (if (< 0 (length (match-string 3))) 2 1)) + (setq sub-type (if (< 0 (length (string-trim-right (match-string 3)))) 2 1)) (setq found t)) ;; WARNING: if you decide to replace adoc-re-two-line-title with a ;; method ensuring the correct length of the underline, be aware that