From e640e6d8591a4a10a3ed9a23b90c215e288f7032 Mon Sep 17 00:00:00 2001 From: Tim Allen Date: Tue, 1 Aug 2017 20:36:40 +1000 Subject: [PATCH] Consecutive markdown list bullets are not a valid list prefix. Previously, if you opened a new line after an underlined heading (what the CommonMark spec calls a "Setext heading") or inserted a newline into a line that started with `**strong emphasis**` the Markdown autoindent hook would assume the leading symbols were list bullets and paste them at the beginning of the new line. However, the CommonMark specification says that list bullets must be followed by at least one horizontal whitespace character, so Setext heading underlines and strong emphasis are not valid list bullets and should not be matched by the autoindent pattern. This commit changes the regex that selects the pastable prefix of the previous line so that it must match either: - One or more `>` characters with optional whitespace between them (a blockquote prefix), optionally followed by a list bullet; or - An optional blockquote prefix and a list bullet Since we don't strictly need either the blockquote prefix nor the list bullet, we could concievably just make both optional... but for lines without either, the regex would find a zero-length match, and for the purposes of copy/paste Kakoune treats that as a one-character match. Therefore, the regex is written to fail if neither pattern is found. --- rc/base/markdown.kak | 2 +- test/indent/markdown/inside-strong-emphasis/cmd | 1 + test/indent/markdown/inside-strong-emphasis/in | 1 + test/indent/markdown/inside-strong-emphasis/out | 2 ++ test/indent/markdown/inside-strong-emphasis/rc | 3 +++ test/indent/markdown/open-after-setext-heading-2/cmd | 1 + test/indent/markdown/open-after-setext-heading-2/in | 2 ++ test/indent/markdown/open-after-setext-heading-2/out | 3 +++ test/indent/markdown/open-after-setext-heading-2/rc | 3 +++ 9 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 test/indent/markdown/inside-strong-emphasis/cmd create mode 100644 test/indent/markdown/inside-strong-emphasis/in create mode 100644 test/indent/markdown/inside-strong-emphasis/out create mode 100644 test/indent/markdown/inside-strong-emphasis/rc create mode 100644 test/indent/markdown/open-after-setext-heading-2/cmd create mode 100644 test/indent/markdown/open-after-setext-heading-2/in create mode 100644 test/indent/markdown/open-after-setext-heading-2/out create mode 100644 test/indent/markdown/open-after-setext-heading-2/rc diff --git a/rc/base/markdown.kak b/rc/base/markdown.kak index 3eaa77a3..8d50cad8 100644 --- a/rc/base/markdown.kak +++ b/rc/base/markdown.kak @@ -127,7 +127,7 @@ add-highlighter -group /markdown/content regex \H\K\h\h$ 0:PrimarySelection def -hidden markdown-indent-on-new-line %{ eval -draft -itersel %{ # copy block quote(s), list item prefix and following white spaces - try %{ exec -draft k s ^\h*\K((>\h*)|[*+-])+\h* y gh j P } + try %{ exec -draft k s ^\h*\K((>\h*)+([*+-]\h)?|(>\h*)*[*+-]\h)\h* y gh j P } # preserve previous line indent try %{ exec -draft \; K } # remove trailing white spaces diff --git a/test/indent/markdown/inside-strong-emphasis/cmd b/test/indent/markdown/inside-strong-emphasis/cmd new file mode 100644 index 00000000..54aed4f8 --- /dev/null +++ b/test/indent/markdown/inside-strong-emphasis/cmd @@ -0,0 +1 @@ +i diff --git a/test/indent/markdown/inside-strong-emphasis/in b/test/indent/markdown/inside-strong-emphasis/in new file mode 100644 index 00000000..1f6d4b18 --- /dev/null +++ b/test/indent/markdown/inside-strong-emphasis/in @@ -0,0 +1 @@ +**strong %(e)mphasis** diff --git a/test/indent/markdown/inside-strong-emphasis/out b/test/indent/markdown/inside-strong-emphasis/out new file mode 100644 index 00000000..3c878b78 --- /dev/null +++ b/test/indent/markdown/inside-strong-emphasis/out @@ -0,0 +1,2 @@ +**strong +emphasis** diff --git a/test/indent/markdown/inside-strong-emphasis/rc b/test/indent/markdown/inside-strong-emphasis/rc new file mode 100644 index 00000000..7b9ff85e --- /dev/null +++ b/test/indent/markdown/inside-strong-emphasis/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/base/markdown.kak" +set buffer filetype markdown diff --git a/test/indent/markdown/open-after-setext-heading-2/cmd b/test/indent/markdown/open-after-setext-heading-2/cmd new file mode 100644 index 00000000..13e7564e --- /dev/null +++ b/test/indent/markdown/open-after-setext-heading-2/cmd @@ -0,0 +1 @@ +o diff --git a/test/indent/markdown/open-after-setext-heading-2/in b/test/indent/markdown/open-after-setext-heading-2/in new file mode 100644 index 00000000..831d9d37 --- /dev/null +++ b/test/indent/markdown/open-after-setext-heading-2/in @@ -0,0 +1,2 @@ +Some Heading +%(-)----------- diff --git a/test/indent/markdown/open-after-setext-heading-2/out b/test/indent/markdown/open-after-setext-heading-2/out new file mode 100644 index 00000000..4ff5ae19 --- /dev/null +++ b/test/indent/markdown/open-after-setext-heading-2/out @@ -0,0 +1,3 @@ +Some Heading +------------ + diff --git a/test/indent/markdown/open-after-setext-heading-2/rc b/test/indent/markdown/open-after-setext-heading-2/rc new file mode 100644 index 00000000..7b9ff85e --- /dev/null +++ b/test/indent/markdown/open-after-setext-heading-2/rc @@ -0,0 +1,3 @@ +source "%val{runtime}/colors/default.kak" +source "%val{runtime}/rc/base/markdown.kak" +set buffer filetype markdown