Disable automatically inserting bullets when auto-wrapping.
# Tests
-All new features must have tests. While we don't require unit tests, which are too hard to do in certain cases, you should create a test under the `test/` directory with a predictable name which allows other users to quickly test your feature. Good tests should explain their expected input / output behavior. Failing test should be marked with `FAIL` somewhere near the test, possibly explaining why it fails. For example:
+All new features must have tests. We don't require unit tests: tests that require users to open markdown code in Vim and check things manually are accepted, but you should point clearly to where the tests are.
-```
-## Links
+Wherever possible, use test cases from the [karlcow'w Markdown Test Suite](https://github.com/karlcow/markdown-testsuite), and link to the relevant test files on your merge request.
-[Link text](link URL)
+If a test does not exist there yet, make a pull request to them, and link to that pull request on the pull request you make here.
-... more correct link tests ...
+If the test you want to do is not appropriate for the Markdown Test Suite, create it only under the `test/` directory here.
-###### FAIL: should not be highlighted as a link
-
-Text (with parenthesis) alone should not be highlighted as a link. (Issue #57)
-
-... more failed link tests ...
-
-## Code Blocks
-```
+If we start disagreeing too often on what is appropriate or not, we will fork off that repository.
let g:vim_markdown_initial_foldlevel=1
```
+**Disable Default Key Mappings**
+
+Add the following line to your `.vimrc` to disable default key mappings. You can map them by yourself with `<Plug>` mappings.
+
+```vim
+let g:vim_markdown_no_default_key_mappings=1
+```
+
## Mappings
The following work on normal and visual modes:
-- `]]`: go to next header.
-- `[[`: go to previous header. Contrast with `]c`.
-- `][`: go to next sibling header if any.
-- `[]`: go to previous sibling header if any.
-- `]c`: go to Current header.
-- `]u`: go to parent header (Up).
+- `]]`: go to next header. `<Plug>(Markdown_MoveToNextHeader)`
+- `[[`: go to previous header. Contrast with `]c`. `<Plug>(Markdown_MoveToPreviousHeader)`
+- `][`: go to next sibling header if any. `<Plug>(Markdown_MoveToNextSiblingHeader)`
+- `[]`: go to previous sibling header if any. `<Plug>(Markdown_MoveToPreviousSiblingHeader)`
+- `]c`: go to Current header. `<Plug>(Markdown_MoveToCurHeader)`
+- `]u`: go to parent header (Up). `<Plug>(Markdown_MoveToParentHeader)`
+
+## Commands
+
+The following commands currently only work for atx style headers (`#`). Pull request are welcome to extend them to Setext style headers (`===`).
+
+- `:Toc`: create a quickfix vertical window navigable table of contents with the headers.
+
+ Hit `<Enter>` on a line to jump to the corresponding line of the markdown file.
+
+- `:Toch`: Same as `:Toc` but in an horizontal window.
+- `:Toct`: Same as `:Toc` but in a new tab.
+- `:Tocv`: Same as `:Toc` for symmetry with `:Toch` and `Tocv`.
## Credits
endif
endfunction
+function! b:Markdown_Toc(...)
+ if a:0 > 0
+ let l:window_type = a:1
+ else
+ let l:window_type = 'vertical'
+ endif
+ silent vimgrep '^#' %
+ if l:window_type ==# 'horizontal'
+ copen
+ elseif l:window_type ==# 'vertical'
+ vertical copen
+ let &winwidth=(&columns/2)
+ elseif l:window_type ==# 'tab'
+ tab copen
+ else
+ copen
+ endif
+ set modifiable
+ %s/\v^([^|]*\|){2,2} #//
+ for i in range(1, line('$'))
+ let l:line = getline(i)
+ let l:header = matchstr(l:line, '^#*')
+ let l:length = len(l:header)
+ let l:line = substitute(l:line, '\v^#*[ ]*', '', '')
+ let l:line = substitute(l:line, '\v[ ]*#*$', '', '')
+ let l:line = repeat(' ', (2 * l:length)) . l:line
+ call setline(i, l:line)
+ endfor
+ set nomodified
+ set nomodifiable
+ normal! gg
+endfunction
+
" Wrapper to do move commands in visual mode.
"
function! s:VisMove(f)
execute 'vn <buffer><silent> ' . a:rhs . ' <esc>:call <sid>VisMove(''' . a:lhs . ''')<cr>'
endfunction
-call <sid>MapNormVis(']]', 'b:Markdown_MoveToNextHeader')
-call <sid>MapNormVis('[[', 'b:Markdown_MoveToPreviousHeader')
-call <sid>MapNormVis('][', 'b:Markdown_MoveToNextSiblingHeader')
-call <sid>MapNormVis('[]', 'b:Markdown_MoveToPreviousSiblingHeader')
+
+call <sid>MapNormVis('<Plug>(Markdown_MoveToNextHeader)', 'b:Markdown_MoveToNextHeader')
+call <sid>MapNormVis('<Plug>(Markdown_MoveToPreviousHeader)', 'b:Markdown_MoveToPreviousHeader')
+call <sid>MapNormVis('<Plug>(Markdown_MoveToNextSiblingHeader)', 'b:Markdown_MoveToNextSiblingHeader')
+call <sid>MapNormVis('<Plug>(Markdown_MoveToPreviousSiblingHeader)', 'b:Markdown_MoveToPreviousSiblingHeader')
" Menmonic: Up
-call <sid>MapNormVis(']u', 'b:Markdown_MoveToParentHeader')
+call <sid>MapNormVis('<Plug>(Markdown_MoveToParentHeader)', 'b:Markdown_MoveToParentHeader')
" Menmonic: Current
-call <sid>MapNormVis(']c', 'b:Markdown_MoveToCurHeader')
+call <sid>MapNormVis('<Plug>(Markdown_MoveToCurHeader)', 'b:Markdown_MoveToCurHeader')
+
+if ! exists('g:vim_markdown_no_default_key_mappings')
+\ || !g:vim_markdown_no_default_key_mappings
+ nmap ]] <Plug>(Markdown_MoveToNextHeader)
+ nmap [[ <Plug>(Markdown_MoveToPreviousHeader)
+ nmap ][ <Plug>(Markdown_MoveToNextSiblingHeader)
+ nmap [] <Plug>(Markdown_MoveToPreviousSiblingHeader)
+ nmap ]u <Plug>(Markdown_MoveToParentHeader)
+ nmap ]c <Plug>(Markdown_MoveToCurHeader)
+
+ vmap ]] <Plug>(Markdown_MoveToNextHeader)
+ vmap [[ <Plug>(Markdown_MoveToPreviousHeader)
+ vmap ][ <Plug>(Markdown_MoveToNextSiblingHeader)
+ vmap [] <Plug>(Markdown_MoveToPreviousSiblingHeader)
+ vmap ]u <Plug>(Markdown_MoveToParentHeader)
+ vmap ]c <Plug>(Markdown_MoveToCurHeader)
+endif
+
+command! -buffer Toc call b:Markdown_Toc()
+command! -buffer Toch call b:Markdown_Toc('horizontal')
+command! -buffer Tocv call b:Markdown_Toc('vertical')
+command! -buffer Toct call b:Markdown_Toc('tab')
--- /dev/null
+This file is used for tests which require there to be multiple headers in different relative positions to each other.
+
+Each header should have an unique text that identifies it.
+
+# h1 space
+
+#h1 nospace
+
+# h1 trailing hash #
+
+## h2 space
+
+##h2 nospace
+
+## h2 trailing hash ##
+
+### h3 space
+
+###h3 nospace
+
+### h3 trailing hash ###
+
+# h1 before h2
+
+## h2 between h1s
+
+# h1 after h2
-# Original markdown
-
-This section covers only features from the [original markdown](daringfireball.net/projects/markdown/syntax), in the same order that they are defined on the specification.
-
-Extensions will be tested on a separate section.
-
-## Paragraphs
-
-Paragraph.
-
-Line
-break.
-
-## Headers
-
-The following should be highlighted as headers:
-
-# h1
-
- # h1
-
-# h1 #
-
-h1
-==
-
-## h2
-
-## h2 ##
-
-h2
---
-
-### h3
-
-#### h4
-
-##### h5
-
-###### h6
-
-The following is unspecified by Markdown and may not highlight properly:
-
-####### h7
-
-## Blockquotes
-
-> Block quote
-
-> First line only
-block quote
-
-> Block quote
-> > Block quote level 2
-
-> # Markdown inside block quote
->
-> [Link text](link-url)
-
-## Lists
-
-Only the list marker should be highlighted:
-
-* 0
-* 1
-
-+ 0
-+ 1
-
-- 0
-- 1
-
-1. 0
-2. 1
-
-*Not* lists:
-
-1 0
-
- - 0
-
-## Links
-
-[Link text](link-url)
-
-Reference style link: [Link text][reference]
-
-With space: [Link text] [reference]
-
-[reference]: address
-[reference2]: address "Optional Title"
-
-## Code blocks
-
-Inline: `inline code`
-
-Indented:
-
- indented code block
-
- # not a header
-
- - not a list
-
-Indented code block and lists:
-
-- 0
-
- Paragraph.
-
- indented code block inside list
-
-- 0
-
- - 1
-
- Paragraph (TODO FAIL).
-
- indented code block inside list
-
-## Emphasis
-
-The following should be italicized:
-
-*single asterisks*
-
-_single underscores_
-
-The following should be boldface:
-
-**double asterisks**
-
-__double underscores__
-
-# Extensions
-
-Fenced code blocks TODO add option to turn ON/OFF:
-
-```
-fenced code block
-```
-
Fenced code living in an indented environment is correctly highlighted:
1. run this command to do this: