From 5c03e2bd5445c5bd9c9535d30223e81fd28e2107 Mon Sep 17 00:00:00 2001 From: SeerLite Date: Thu, 1 Apr 2021 21:18:11 -0300 Subject: [PATCH 1/3] rc markdown: Add -insert hook --- rc/filetype/markdown.kak | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/rc/filetype/markdown.kak b/rc/filetype/markdown.kak index 43f3e601..38e32ea3 100644 --- a/rc/filetype/markdown.kak +++ b/rc/filetype/markdown.kak @@ -14,6 +14,7 @@ hook global BufCreate .*[.](markdown|md|mkd) %{ hook global WinSetOption filetype=markdown %{ require-module markdown + hook window InsertChar \n -group markdown-insert markdown-insert-on-new-line hook window InsertChar \n -group markdown-indent markdown-indent-on-new-line hook -once -always window WinSetOption filetype=.* %{ remove-hooks window markdown-.+ } } @@ -96,10 +97,12 @@ add-highlighter shared/markdown/inline/text/ regex "^( {4}|\t)+([^\n]+)" 2:meta # Commands # ‾‾‾‾‾‾‾‾ +define-command -hidden markdown-insert-on-new-line %{ + try %{ execute-keys -draft -itersel k s ^\h*\K((>\h*)+([*+-]\h)?|(>\h*)*[*+-]\h)\h* y gh j P } +} + define-command -hidden markdown-indent-on-new-line %{ evaluate-commands -draft -itersel %{ - # copy block quote(s), list item prefix and following white spaces - try %{ execute-keys -draft k s ^\h*\K((>\h*)+([*+-]\h)?|(>\h*)*[*+-]\h)\h* y gh j P } # preserve previous line indent try %{ execute-keys -draft K } # remove trailing white spaces From e84dd80244eef284cc6d66bb7f9a43bfa271f662 Mon Sep 17 00:00:00 2001 From: SeerLite Date: Thu, 1 Apr 2021 21:19:20 -0300 Subject: [PATCH 2/3] rc markdown: Fix trailing whitespace removal Modified the test cases accordingly too --- rc/filetype/markdown.kak | 2 +- test/indent/markdown/inside-complex-blockquote/out | 2 +- test/indent/markdown/inside-list-item/out | 2 +- test/indent/markdown/inside-nested-list-item/out | 2 +- test/indent/markdown/inside-simple-blockquote/out | 2 +- test/indent/markdown/inside-strong-emphasis/out | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/rc/filetype/markdown.kak b/rc/filetype/markdown.kak index 38e32ea3..5e5e92b8 100644 --- a/rc/filetype/markdown.kak +++ b/rc/filetype/markdown.kak @@ -106,7 +106,7 @@ define-command -hidden markdown-indent-on-new-line %{ # preserve previous line indent try %{ execute-keys -draft K } # remove trailing white spaces - try %{ execute-keys -draft -itersel %{ k s \h+$ d } } + try %{ execute-keys -draft k s \h+$ d } } } diff --git a/test/indent/markdown/inside-complex-blockquote/out b/test/indent/markdown/inside-complex-blockquote/out index be4f1e99..2b5799f9 100644 --- a/test/indent/markdown/inside-complex-blockquote/out +++ b/test/indent/markdown/inside-complex-blockquote/out @@ -1,2 +1,2 @@ ->> > > block +>> > > block >> > > quote diff --git a/test/indent/markdown/inside-list-item/out b/test/indent/markdown/inside-list-item/out index 61c6d22a..be88314c 100644 --- a/test/indent/markdown/inside-list-item/out +++ b/test/indent/markdown/inside-list-item/out @@ -1,2 +1,2 @@ -* inside +* inside * item diff --git a/test/indent/markdown/inside-nested-list-item/out b/test/indent/markdown/inside-nested-list-item/out index 73b7f06d..a6834ab2 100644 --- a/test/indent/markdown/inside-nested-list-item/out +++ b/test/indent/markdown/inside-nested-list-item/out @@ -1,3 +1,3 @@ - parent - * some + * some * child diff --git a/test/indent/markdown/inside-simple-blockquote/out b/test/indent/markdown/inside-simple-blockquote/out index d286b922..159530c8 100644 --- a/test/indent/markdown/inside-simple-blockquote/out +++ b/test/indent/markdown/inside-simple-blockquote/out @@ -1,2 +1,2 @@ -> block +> block > quote diff --git a/test/indent/markdown/inside-strong-emphasis/out b/test/indent/markdown/inside-strong-emphasis/out index 3c878b78..e506acb2 100644 --- a/test/indent/markdown/inside-strong-emphasis/out +++ b/test/indent/markdown/inside-strong-emphasis/out @@ -1,2 +1,2 @@ -**strong +**strong emphasis** From 3397737b166b14db254bcf4c21f8018591fae61d Mon Sep 17 00:00:00 2001 From: SeerLite Date: Thu, 1 Apr 2021 22:46:40 -0300 Subject: [PATCH 3/3] rc markdown: Fix code fence regex The invalid regex `)\b` currently matches anything, so this didn't cause any errors. It is still invalid though, so I fixed it by moving the `\b` to the end of the non-raw_attribute language name (like the original regex). The raw_attribute one shouldn't need this because the `}` marks the end of the language name anyway. Fixes #4025 --- rc/filetype/markdown.kak | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rc/filetype/markdown.kak b/rc/filetype/markdown.kak index 5e5e92b8..2d7a4d08 100644 --- a/rc/filetype/markdown.kak +++ b/rc/filetype/markdown.kak @@ -48,7 +48,7 @@ evaluate-commands %sh{ ruby rust sass scala scss sh swift toml tupfile typescript yaml sql " for lang in ${languages}; do - printf 'add-highlighter shared/markdown/%s region -match-capture ^(\h*)```\h*(%s|\\{[.=]?%s\\}))\\b ^(\h*)``` regions\n' "${lang}" "${lang}" "${lang}" + printf 'add-highlighter shared/markdown/%s region -match-capture ^(\h*)```\h*(%s\\b|\\{[.=]?%s\\}) ^(\h*)``` regions\n' "${lang}" "${lang}" "${lang}" printf 'add-highlighter shared/markdown/%s/ default-region fill meta\n' "${lang}" [ "${lang}" = kak ] && ref=kakrc || ref="${lang}" printf 'add-highlighter shared/markdown/%s/inner region \A```[^\\n]*\K (?=```) ref %s\n' "${lang}" "${ref}"