Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add space in header regex #598

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions ftplugin/markdown.vim
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@
" 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.
"
" 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.
Expand Down
143 changes: 143 additions & 0 deletions test/header-decrease.vader
Original file line number Diff line number Diff line change
@@ -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):
#

##
32 changes: 29 additions & 3 deletions test/map.vader
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,16 @@ Given markdown;

b

#ignore

# c

d

Execute (]] same level):
AssertEqual line('.'), 1
normal ]]
AssertEqual line('.'), 5
AssertEqual line('.'), 7
normal [[
AssertEqual line('.'), 1

Expand All @@ -110,14 +112,16 @@ Given markdown;

b

##ignore

## c

d

Execute (]] different levels level):
AssertEqual line('.'), 1
normal ]]
AssertEqual line('.'), 5
AssertEqual line('.'), 7
normal [[
AssertEqual line('.'), 1

Expand All @@ -126,6 +130,8 @@ Given markdown;

b

#ignore

## c

d
Expand All @@ -137,7 +143,7 @@ f
Execute (][ different levels level):
AssertEqual line('.'), 1
normal ][
AssertEqual line('.'), 9
AssertEqual line('.'), 11
normal []
AssertEqual line('.'), 1

Expand All @@ -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
3 changes: 0 additions & 3 deletions test/toc.vader
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down