From: Hiroshi Shirosaki Date: Wed, 9 Jan 2019 11:18:54 +0000 (+0900) Subject: Merge pull request #367 from 91khr/master X-Git-Url: https://git.madduck.net/etc/vim.git/commitdiff_plain/f6ffce242a286d5239cf025666fe80af021a7319?hp=13c836661996b9c03bbcaf6b56a49d3925ffe925 Merge pull request #367 from 91khr/master Add support for strike through which is supported by GFM --- diff --git a/.travis.yml b/.travis.yml index 90cc371..338161c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -25,7 +25,7 @@ before_script: | cd "$TRAVIS_BUILD_DIR" fi if [ "$TRAVIS_OS_NAME" = "osx" ]; then - sudo -H easy_install pip + curl https://bootstrap.pypa.io/get-pip.py | sudo python fi sudo -H pip install virtualenv diff --git a/README.md b/README.md index 8c056ce..982248e 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ Syntax highlighting, matching rules and mappings for [the original Markdown](http://daringfireball.net/projects/markdown/) and extensions. 1. [Installation](#installation) +1. [Basic usage](#basic-usage) 1. [Options](#options) 1. [Mappings](#mappings) 1. [Commands](#commands) @@ -52,6 +53,37 @@ cd ~/.vim tar --strip=1 -zxf vim-markdown-master.tar.gz ``` +## Basic usage + +### Folding + +Folding is enabled for headers by default. + +The following commands are useful to open and close folds: + +- `zr`: reduces fold level throughout the buffer +- `zR`: opens all folds +- `zm`: increases fold level throughout the buffer +- `zM`: folds everything all the way +- `za`: open a fold your cursor is on +- `zA`: open a fold your cursor is on recursively +- `zc`: close a fold your cursor is on +- `zC`: close a fold your cursor is on recursively + +[Options](#options) are available to disable folding or change folding style. + +Try `:help fold-expr` and `:help fold-commands` for details. + +### Concealing + +Concealing is set for some syntax such as bold, italic, code block and link. + +Concealing lets you conceal text with other text. The actual source text is not modified. If you put your cursor on the concealed line, the conceal goes away. + +[Options](#options) are available to disable or change concealing. + +Try `:help concealcursor` and `:help conceallevel` for details. + ## Options ### Disable Folding @@ -293,6 +325,30 @@ If you would like to use a file extension other than `.md` you may do so using t let g:vim_markdown_auto_extension_ext = 'txt' ``` +### Do not automatically insert bulletpoints + +Automatically inserting bulletpoints can lead to problems when wrapping text +(see issue #232 for details), so it can be disabled: + +```vim +let g:vim_markdown_auto_insert_bullets = 0 +``` + +In that case, you probably also want to set the new list item indent to 0 as +well, or you will have to remove an indent each time you add a new list item: + +```vim +let g:vim_markdown_new_list_item_indent = 0 +``` + +### Change how to open new files + +By default when following a link the target file will be opened in your current buffer. This behavior can change if you prefer using splits or tabs by using the `vim_markdown_edit_url_in` variable. Possible values are `tab`, `vsplit`, `hsplit`, `current` opening in a new tab, vertical split, horizontal split, and current buffer respectively. Defaults to current buffer if not set: + +```vim +let g:vim_markdown_edit_url_in = 'tab' +``` + ## Mappings The following work on normal and visual modes: diff --git a/doc/vim-markdown.txt b/doc/vim-markdown.txt index 714d3a9..29ed66d 100644 --- a/doc/vim-markdown.txt +++ b/doc/vim-markdown.txt @@ -5,7 +5,10 @@ Contents ~ 1. Introduction |vim-markdown-introduction| 2. Installation |vim-markdown-installation| - 3. Options |vim-markdown-options| + 3. Basic usage |vim-markdown-basic-usage| + 1. Folding |vim-markdown-folding| + 2. Concealing |vim-markdown-concealing| + 4. Options |vim-markdown-options| 1. Disable Folding |vim-markdown-disable-folding| 2. Change fold style |vim-markdown-change-fold-style| 3. Set header folding level |vim-markdown-set-header-folding-level| @@ -26,12 +29,16 @@ Contents ~ |vim-markdown-do-not-require-.md-extensions-for-markdown-links| 13. Auto-write when following link |vim-markdown-auto-write-when-following-link| - 14. Change default file extension |vim-markdown-auto-extension-ext| - 4. Mappings |vim-markdown-mappings| - 5. Commands |vim-markdown-commands| - 6. Credits |vim-markdown-credits| - 7. License |vim-markdown-license| - 8. References |vim-markdown-references| + 14. Change default file extension + |vim-markdown-change-default-file-extension| + 15. Do not automatically insert bulletpoints + |vim-markdown-do-not-automatically-insert-bulletpoints| + 16. Change how to open new files |vim-markdown-change-how-to-open-new-files| + 5. Mappings |vim-markdown-mappings| + 6. Commands |vim-markdown-commands| + 7. Credits |vim-markdown-credits| + 8. License |vim-markdown-license| + 9. References |vim-markdown-references| =============================================================================== *vim-markdown-introduction* @@ -73,6 +80,52 @@ If you are not using any package manager, download the tarball [5] and do this: cd ~/.vim tar --strip=1 -zxf vim-markdown-master.tar.gz < +=============================================================================== + *vim-markdown-basic-usage* +Basic usage ~ + +------------------------------------------------------------------------------- + *vim-markdown-folding* +Folding ~ + +Folding is enabled for headers by default. + +The following commands are useful to open and close folds: + + *vim-markdown-zr* +- 'zr': reduces fold level throughout the buffer + *vim-markdown-zR* +- 'zR': opens all folds + *vim-markdown-zm* +- 'zm': increases fold level throughout the buffer + *vim-markdown-zM* +- 'zM': folds everything all the way + *vim-markdown-za* +- 'za': open a fold your cursor is on + *vim-markdown-zA* +- 'zA': open a fold your cursor is on recursively + *vim-markdown-zc* +- 'zc': close a fold your cursor is on + *vim-markdown-zC* +- 'zC': close a fold your cursor is on recursively + +Options are available to disable folding or change folding style. + +Try ':help fold-expr' and ':help fold-commands' for details. + +------------------------------------------------------------------------------- + *vim-markdown-concealing* +Concealing ~ + +Concealing is set for some syntax such as bold, italic, code block and link. + +Concealing lets you conceal text with other text. The actual source text is not +modified. If you put your cursor on the concealed line, the conceal goes away. + +Options are available to disable or change concealing. + +Try ':help concealcursor' and ':help conceallevel' for details. + =============================================================================== *vim-markdown-options* Options ~ @@ -144,7 +197,7 @@ never increases its default size (half screen), it only shrinks. Text emphasis restriction to single-lines ~ By default text emphasis works across multiple lines until a closing token is -found. However, it's possible to restrict text emphasis to a single line (ie, +found. However, it's possible to restrict text emphasis to a single line (i.e., for it to be applied a closing token must be found on the same line). To do so: > let g:vim_markdown_emphasis_multiline = 0 @@ -197,9 +250,9 @@ Default is "['c++=cpp', 'viml=vim', 'bash=sh', 'ini=dosini']". *vim-markdown-follow-named-anchors* Follow named anchors ~ -This feature allows ge to follow named anchors in links of the form -'file#anchor' or just '#anchor', where file may omit the '.md' extension as -usual. Two variables control its operation: +This feature allows the 'ge' command to follow named anchors in links of the +form 'file#anchor' or just '#anchor', where file may omit the '.md' extension +as usual. Two variables control its operation: > let g:vim_markdown_follow_anchor = 1 < @@ -311,7 +364,7 @@ this option will automatically save any edits you made before moving you: let g:vim_markdown_autowrite = 1 < ------------------------------------------------------------------------------- - *vim-markdown-auto-extension-ext* + *vim-markdown-change-default-file-extension* Change default file extension ~ If you would like to use a file extension other than '.md' you may do so using @@ -319,6 +372,32 @@ the 'vim_markdown_auto_extension_ext' variable: > let g:vim_markdown_auto_extension_ext = 'txt' < +------------------------------------------------------------------------------- + *vim-markdown-do-not-automatically-insert-bulletpoints* +Do not automatically insert bulletpoints ~ + +Automatically inserting bulletpoints can lead to problems when wrapping text +(see issue #232 for details), so it can be disabled: +> + let g:vim_markdown_auto_insert_bullets = 0 +< +In that case, you probably also want to set the new list item indent to 0 as +well, or you will have to remove an indent each time you add a new list item: +> + let g:vim_markdown_new_list_item_indent = 0 +< +------------------------------------------------------------------------------- + *vim-markdown-change-how-to-open-new-files* +Change how to open new files ~ + +By default when following a link the target file will be opened in your current +buffer. This behavior can change if you prefer using splits or tabs by using +the 'vim_markdown_edit_url_in' variable. Possible values are 'tab', 'vsplit', +'hsplit', 'current' opening in a new tab, vertical split, horizontal split, and +current buffer respectively. Defaults to current buffer if not set: +> + let g:vim_markdown_edit_url_in = 'tab' +< =============================================================================== *vim-markdown-mappings* Mappings ~ diff --git a/ftdetect/markdown.vim b/ftdetect/markdown.vim index 611ecaa..07682da 100644 --- a/ftdetect/markdown.vim +++ b/ftdetect/markdown.vim @@ -1,3 +1,8 @@ +if !has('patch-7.4.480') + " Before this patch, vim used modula2 for .md. + au! filetypedetect BufRead,BufNewFile *.md +endif + " markdown filetype file -au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} set filetype=markdown -au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn}.{des3,des,bf,bfa,aes,idea,cast,rc2,rc4,rc5,desx} set filetype=markdown +au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} setfiletype markdown +au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn}.{des3,des,bf,bfa,aes,idea,cast,rc2,rc4,rc5,desx} setfiletype markdown diff --git a/ftplugin/markdown.vim b/ftplugin/markdown.vim index 1aa3494..659df91 100644 --- a/ftplugin/markdown.vim +++ b/ftplugin/markdown.vim @@ -609,7 +609,23 @@ if !exists('*s:EditUrlUnderCursor') endif endif let l:url = fnameescape(fnamemodify(expand('%:h').'/'.l:url.l:ext, ':.')) - execute 'edit' l:url + let l:editmethod = '' + " determine how to open the linked file (split, tab, etc) + if exists('g:vim_markdown_edit_url_in') + if g:vim_markdown_edit_url_in == 'tab' + let l:editmethod = 'tabnew' + elseif g:vim_markdown_edit_url_in == 'vsplit' + let l:editmethod = 'vsp' + elseif g:vim_markdown_edit_url_in == 'hsplit' + let l:editmethod = 'sp' + else + let l:editmethod = 'edit' + endif + else + " default to current buffer + let l:editmethod = 'edit' + endif + execute l:editmethod l:url endif if l:anchor != '' silent! execute '/'.l:anchor @@ -718,7 +734,7 @@ function! s:MarkdownHighlightSources(force) let include = '@' . toupper(filetype) endif let command = 'syntax region %s matchgroup=%s start="^\s*```\s*%s$" matchgroup=%s end="\s*```$" keepend contains=%s%s' - execute printf(command, group, startgroup, ft, endgroup, include, has('conceal') && get(g:, 'vim_markdown_conceal', 1) ? ' concealends' : '') + execute printf(command, group, startgroup, ft, endgroup, include, has('conceal') && get(g:, 'vim_markdown_conceal', 1) && get(g:, 'vim_markdown_conceal_code_blocks', 1) ? ' concealends' : '') execute printf('syntax cluster mkdNonListItem add=%s', group) let b:mkd_known_filetypes[ft] = 1 diff --git a/indent/markdown.vim b/indent/markdown.vim index 103e160..2fa4cda 100755 --- a/indent/markdown.vim +++ b/indent/markdown.vim @@ -5,15 +5,15 @@ setlocal indentexpr=GetMarkdownIndent() setlocal nolisp setlocal autoindent -" Automatically insert bullets -setlocal formatoptions+=r -" Do not automatically insert bullets when auto-wrapping with text-width -setlocal formatoptions-=c -" Accept various markers as bullets -setlocal comments=b:*,b:+,b:- - " Automatically continue blockquote on line break -setlocal comments+=b:> +setlocal formatoptions+=r +setlocal comments=b:> +if get(g:, "vim_markdown_auto_insert_bullets", 1) + " Do not automatically insert bullets when auto-wrapping with text-width + setlocal formatoptions-=c + " Accept various markers as bullets + setlocal comments+=b:*,b:+,b:- +endif " Only define the function once if exists("*GetMarkdownIndent") | finish | endif diff --git a/syntax/markdown.vim b/syntax/markdown.vim index aad7dc4..86b10b0 100644 --- a/syntax/markdown.vim +++ b/syntax/markdown.vim @@ -36,10 +36,14 @@ syn sync linebreaks=1 let s:conceal = '' let s:concealends = '' +let s:concealcode = '' if has('conceal') && get(g:, 'vim_markdown_conceal', 1) let s:conceal = ' conceal' let s:concealends = ' concealends' endif +if has('conceal') && get(g:, 'vim_markdown_conceal_code_blocks', 1) + let s:concealcode = ' concealends' +endif " additions to HTML groups if get(g:, 'vim_markdown_emphasis_multiline', 1) @@ -82,25 +86,25 @@ syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+ end=+'+ contained syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+ end=+)+ contained "HTML headings -syn region htmlH1 start="^\s*#" end="$" contains=mkdLink,mkdInlineURL,@Spell -syn region htmlH2 start="^\s*##" end="$" contains=mkdLink,mkdInlineURL,@Spell -syn region htmlH3 start="^\s*###" end="$" contains=mkdLink,mkdInlineURL,@Spell -syn region htmlH4 start="^\s*####" end="$" contains=mkdLink,mkdInlineURL,@Spell -syn region htmlH5 start="^\s*#####" end="$" contains=mkdLink,mkdInlineURL,@Spell -syn region htmlH6 start="^\s*######" end="$" contains=mkdLink,mkdInlineURL,@Spell +syn region htmlH1 matchgroup=mkdHeading start="^\s*#" end="$" contains=mkdLink,mkdInlineURL,@Spell +syn region htmlH2 matchgroup=mkdHeading start="^\s*##" end="$" contains=mkdLink,mkdInlineURL,@Spell +syn region htmlH3 matchgroup=mkdHeading start="^\s*###" end="$" contains=mkdLink,mkdInlineURL,@Spell +syn region htmlH4 matchgroup=mkdHeading start="^\s*####" end="$" contains=mkdLink,mkdInlineURL,@Spell +syn region htmlH5 matchgroup=mkdHeading start="^\s*#####" end="$" contains=mkdLink,mkdInlineURL,@Spell +syn region htmlH6 matchgroup=mkdHeading start="^\s*######" end="$" contains=mkdLink,mkdInlineURL,@Spell syn match htmlH1 /^.\+\n=\+$/ contains=mkdLink,mkdInlineURL,@Spell syn match htmlH2 /^.\+\n-\+$/ contains=mkdLink,mkdInlineURL,@Spell "define Markdown groups syn match mkdLineBreak / \+$/ syn region mkdBlockquote start=/^\s*>/ end=/$/ contains=mkdLink,mkdInlineURL,mkdLineBreak,@Spell -syn region mkdCode start=/\(\([^\\]\|^\)\\\)\@]*\\\@" end="" -syn region mkdCode start="]*\\\@" end="" +execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/\(\([^\\]\|^\)\\\)\@]*\\\@" end=""' . s:concealcode +execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start="]*\\\@" end=""' . s:concealcode syn region mkdFootnote start="\[^" end="\]" syn match mkdCode /^\s*\n\(\(\s\{8,}[^ ]\|\t\t\+[^\t]\).*\n\)\+/ syn match mkdCode /\%^\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ @@ -115,7 +119,7 @@ syn match mkdRule /^\s*_\s\{0,1}_\s\{0,1}_\(_\|\s\)*$/ " YAML frontmatter if get(g:, 'vim_markdown_frontmatter', 0) syn include @yamlTop syntax/yaml.vim - syn region Comment matchgroup=mkdDelimiter start="\%^---$" end="^---$" contains=@yamlTop keepend + syn region Comment matchgroup=mkdDelimiter start="\%^---$" end="^\(---\|\.\.\.\)$" contains=@yamlTop keepend unlet! b:current_syntax endif @@ -156,6 +160,7 @@ syn cluster mkdNonListItem contains=@htmlTop,htmlItalic,htmlBold,htmlBoldItalic, "highlighting for Markdown groups HtmlHiLink mkdString String HtmlHiLink mkdCode String +HtmlHiLink mkdCodeDelimiter String HtmlHiLink mkdCodeStart String HtmlHiLink mkdCodeEnd String HtmlHiLink mkdFootnote Comment diff --git a/test/syntax.vader b/test/syntax.vader index 0adae58..fdf9c0b 100644 --- a/test/syntax.vader +++ b/test/syntax.vader @@ -1139,19 +1139,19 @@ Given markdown; ###### h6 Execute (atx headers): - AssertEqual SyntaxOf('# h1 space'), 'htmlH1' - AssertEqual SyntaxOf('#h1 nospace'), 'htmlH1' - AssertEqual SyntaxOf('# h1 2 spaces'), 'htmlH1' - AssertEqual SyntaxOf('# h1 trailing hash #'), 'htmlH1' - AssertEqual SyntaxOf('## h2 space'), 'htmlH2' - AssertEqual SyntaxOf('##h2 nospace'), 'htmlH2' - AssertEqual SyntaxOf('## h2 trailing hash ##'), 'htmlH2' - AssertEqual SyntaxOf('### h3 space'), 'htmlH3' - AssertEqual SyntaxOf('###h3 nospace'), 'htmlH3' - AssertEqual SyntaxOf('### h3 trailing hash ###'), 'htmlH3' - AssertEqual SyntaxOf('#### h4'), 'htmlH4' - AssertEqual SyntaxOf('##### h5'), 'htmlH5' - AssertEqual SyntaxOf('###### h6'), 'htmlH6' + AssertEqual SyntaxOf(' h1 space'), 'htmlH1' + AssertEqual SyntaxOf('h1 nospace'), 'htmlH1' + AssertEqual SyntaxOf(' h1 2 spaces'), 'htmlH1' + AssertEqual SyntaxOf(' h1 trailing hash '), 'htmlH1' + AssertEqual SyntaxOf(' h2 space'), 'htmlH2' + AssertEqual SyntaxOf('h2 nospace'), 'htmlH2' + AssertEqual SyntaxOf(' h2 trailing hash '), 'htmlH2' + AssertEqual SyntaxOf(' h3 space'), 'htmlH3' + AssertEqual SyntaxOf('h3 nospace'), 'htmlH3' + AssertEqual SyntaxOf(' h3 trailing hash '), 'htmlH3' + AssertEqual SyntaxOf(' h4'), 'htmlH4' + AssertEqual SyntaxOf(' h5'), 'htmlH5' + AssertEqual SyntaxOf(' h6'), 'htmlH6' Given markdown; # h1 before h2 @@ -1161,9 +1161,9 @@ Given markdown; # h1 after h2 Execute (atx headers relative positions): - AssertEqual SyntaxOf('# h1 before h2'), 'htmlH1' - AssertEqual SyntaxOf('## h2 between h1s'), 'htmlH2' - AssertEqual SyntaxOf('# h1 after h2'), 'htmlH1' + AssertEqual SyntaxOf(' h1 before h2'), 'htmlH1' + AssertEqual SyntaxOf(' h2 between h1s'), 'htmlH2' + AssertEqual SyntaxOf(' h1 after h2'), 'htmlH1' Given markdown; setex h1 @@ -1214,9 +1214,9 @@ setex h2 Execute (mixed atx and setex headers): AssertEqual SyntaxOf('setex h1 before atx'), 'htmlH1' AssertEqual SyntaxOf('==================='), 'htmlH1' - AssertEqual SyntaxOf('## atx h2'), 'htmlH2' - AssertEqual SyntaxOf('### atx h3'), 'htmlH3' - AssertEqual SyntaxOf('# atx h1'), 'htmlH1' + AssertEqual SyntaxOf(' atx h2'), 'htmlH2' + AssertEqual SyntaxOf(' atx h3'), 'htmlH3' + AssertEqual SyntaxOf(' atx h1'), 'htmlH1' AssertEqual SyntaxOf('setex h2'), 'htmlH2' AssertEqual SyntaxOf('------------------'), 'htmlH2'