diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim index 5e402269..812583a8 100644 --- a/ftplugin/markdown.vim +++ b/ftplugin/markdown.vim @@ -48,12 +48,12 @@ " For each level, contains the regexp that matches at that level only. " let s:levelRegexpDict = { - \ 1: '\v^(#[^#]@=|.+\n\=+$)', - \ 2: '\v^(##[^#]@=|.+\n-+$)', - \ 3: '\v^###[^#]@=', - \ 4: '\v^####[^#]@=', - \ 5: '\v^#####[^#]@=', - \ 6: '\v^######[^#]@=' + \ 1: '\v^(#\_s@=|.+\n\=+$)', + \ 2: '\v^(##\_s@=|.+\n-+$)', + \ 3: '\v^###\_s@=', + \ 4: '\v^####\_s@=', + \ 5: '\v^#####\_s@=', + \ 6: '\v^######\_s@=' \ } " Maches any header level of any type. @@ -61,7 +61,7 @@ let s:levelRegexpDict = { " This could be deduced from `s:levelRegexpDict`, but it is more " efficient to have a single regexp for this. " -let s:headersRegexp = '\v^(#|.+\n(\=+|-+)$)' +let s:headersRegexp = '\v^(#{1,6}\_s|.+\n(\=+|-+)$)' " Returns the line number of the first header before `line`, called the " current header. diff --git a/test/header-decrease.vader b/test/header-decrease.vader new file mode 100644 index 00000000..39510d3c --- /dev/null +++ b/test/header-decrease.vader @@ -0,0 +1,143 @@ +Given markdown; +# a + +## b + +### c + +#### d + +##### e + +Execute (HeaderIncrease without forbidden level): + :HeaderIncrease + +Expect (increase level of all headers): + ## a + + ### b + + #### c + + ##### d + + ###### e + +Given markdown; +# a + +###### b + +Execute (HeaderIncrease with forbidden level): + :HeaderIncrease + +Expect (no changes): + # a + + ###### b + +Given markdown; +## a + +### b + +#### c + +##### d + +###### e + +Execute (HeaderDecrease without forbidden level): + :HeaderDecrease + +Expect (decrease level of all headers): + # a + + ## b + + ### c + + #### d + + ##### e + +Given markdown; +# a + +## b + +### c + +#### d + +##### e + +###### f + +Execute (HeaderDecrease with forbidden level): + :HeaderDecrease + +Expect (no changes): + # a + + ## b + + ### c + + #### d + + ##### e + + ###### f + +Given markdown; +## a + +##hashtag + +Execute (HeaderDecrease with hashtag): + :HeaderDecrease + +Expect (hashtags are not affected): + # a + + ##hashtag + +Given markdown; +# a + +#hashtag + +Execute (HeaderIncrease with hashtag): + :HeaderIncrease + +Expect (hashtags are not affected): + ## a + + #hashtag + +Given markdown; +# + +## + +Execute (HeaderIncrease with empty atx headings): + :HeaderIncrease + +Expect (increase level of all headers): + ## + + ### + +Given markdown; +## + +### + +Execute (HeaderDecrease with empty atx headings): + :HeaderDecrease + +Expect (decrease level of all headers): + # + + ## diff --git a/test/map.vader b/test/map.vader index 57fe6190..7c9304bd 100644 --- a/test/map.vader +++ b/test/map.vader @@ -94,6 +94,8 @@ Given markdown; b +#ignore + # c d @@ -101,7 +103,7 @@ d Execute (]] same level): AssertEqual line('.'), 1 normal ]] - AssertEqual line('.'), 5 + AssertEqual line('.'), 7 normal [[ AssertEqual line('.'), 1 @@ -110,6 +112,8 @@ Given markdown; b +##ignore + ## c d @@ -117,7 +121,7 @@ d Execute (]] different levels level): AssertEqual line('.'), 1 normal ]] - AssertEqual line('.'), 5 + AssertEqual line('.'), 7 normal [[ AssertEqual line('.'), 1 @@ -126,6 +130,8 @@ Given markdown; b +#ignore + ## c d @@ -137,7 +143,7 @@ f Execute (][ different levels level): AssertEqual line('.'), 1 normal ][ - AssertEqual line('.'), 9 + AssertEqual line('.'), 11 normal [] AssertEqual line('.'), 1 @@ -151,3 +157,23 @@ Execute (]h): AssertEqual line('.'), 3 normal ]h AssertEqual line('.'), 1 + +Given markdown; +# + +## + +# + +## + +Execute (]] empty atx heading): + AssertEqual line('.'), 1 + normal ]] + AssertEqual line('.'), 3 + normal [[ + AssertEqual line('.'), 1 + normal ][ + AssertEqual line('.'), 5 + normal [] + AssertEqual line('.'), 1 diff --git a/test/toc.vader b/test/toc.vader index 51269526..545c5419 100644 --- a/test/toc.vader +++ b/test/toc.vader @@ -138,14 +138,11 @@ Execute (Toc multiple headers): Expect (multiple headers): h1 space - h1 nospace h1 2 spaces h1 trailing hash h2 space - h2 nospace h2 trailing hash h3 space - h3 nospace h3 trailing hash h4 h5