mirror of
1
0
Fork 0

Update vim-markdown.

This commit is contained in:
Kurtis Moxley 2022-05-19 22:45:21 +08:00
parent e3f0835434
commit 0883030a2b
19 changed files with 217 additions and 150 deletions

View File

@ -0,0 +1,13 @@
name: Reviewdog
on: [pull_request]
jobs:
vint:
name: vint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: vint
uses: reviewdog/action-vint@v1
with:
github_token: ${{ secrets.github_token }}
reporter: github-pr-review

View File

@ -0,0 +1,31 @@
name: Vader
on: [push, pull_request]
jobs:
vader:
name: vader
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
vimFlavor: ["vim", "nvim"]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Enable Universe package repository
run: |
sudo add-apt-repository universe
sudo apt-get update
- name: Install ${{ matrix.vimFlavor }}
run: |
sudo apt-get install ${{ matrix.vimFlavor == 'nvim' && 'neovim' || 'vim' }}
- name: Review versions
run: |
${{ matrix.vimFlavor }} --version
- name: Fetch Vader and other dependencies
run: |
make build/tabular build/vim-toml build/vim-json build/vader.vim
- name: Run test suite
run: |
cd test
${{ matrix.vimFlavor == 'nvim' && 'nvim --headless' || 'vim -N' }} \
-u vimrc "+Vader! *"

View File

@ -0,0 +1,15 @@
name: Vint
on: [push]
jobs:
vint:
name: vint
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
- name: Setup dependencies
run: pip install vim-vint
- name: Lint Vimscript
run: vint .

View File

@ -1,34 +0,0 @@
language: vim
os:
- linux
- osx
env:
- TEST=package
- TEST=latest
before_script: |
if [ "$TEST" = "package" ]; then
if [ "$TRAVIS_OS_NAME" = "linux" ]; then
sudo apt-get -y update
sudo apt-get -y install vim
fi
else
cd ..
git clone --depth 1 https://github.com/vim/vim
cd vim
./configure --with-features=huge
make
sudo make install
export PATH="/usr/local/bin:$PATH"
cd "$TRAVIS_BUILD_DIR"
fi
if [ "$TRAVIS_OS_NAME" = "osx" ]; then
curl https://bootstrap.pypa.io/get-pip.py | sudo python
fi
sudo -H pip install virtualenv
script:
- make test
- make doc

View File

@ -0,0 +1,5 @@
cmdargs:
severity: style_problem
color: true
env:
neovim: false

View File

@ -46,7 +46,7 @@ All new features must have unit tests.
Issues are tracked within GitHub. Issues are tracked within GitHub.
When reporting issues, your report is more effective if you include a minimal example file that reproduces the problem. Try to trim out as much as possible, until you have the smallest possible file that still reproduces the issue. Paste the example inline into your issue report, quoted using four spaces at the beginning of each line, like this example from issue [#189](https://github.com/plasticboy/vim-markdown/issues/189): When reporting issues, your report is more effective if you include a minimal example file that reproduces the problem. Try to trim out as much as possible, until you have the smallest possible file that still reproduces the issue. Paste the example inline into your issue report, quoted using four spaces at the beginning of each line, like this example from issue [#189](https://github.com/preservim/vim-markdown/issues/189):
``` ```
Minimal example: Minimal example:

View File

@ -1,6 +1,7 @@
# Vim Markdown # Vim Markdown
[![Build Status](https://travis-ci.org/plasticboy/vim-markdown.svg)](https://travis-ci.org/plasticboy/vim-markdown) [![Vint](https://github.com/preservim/vim-markdown/workflows/Vint/badge.svg)](https://github.com/preservim/vim-markdown/actions?workflow=Vint)
[![Vader](https://github.com/preservim/vim-markdown/workflows/Vader/badge.svg)](https://github.com/preservim/vim-markdown/actions?workflow=Vader)
Syntax highlighting, matching rules and mappings for [the original Markdown](http://daringfireball.net/projects/markdown/) and extensions. Syntax highlighting, matching rules and mappings for [the original Markdown](http://daringfireball.net/projects/markdown/) and extensions.
@ -18,7 +19,7 @@ If you use [Vundle](https://github.com/gmarik/vundle), add the following lines t
```vim ```vim
Plugin 'godlygeek/tabular' Plugin 'godlygeek/tabular'
Plugin 'plasticboy/vim-markdown' Plugin 'preservim/vim-markdown'
``` ```
The `tabular` plugin must come *before* `vim-markdown`. The `tabular` plugin must come *before* `vim-markdown`.
@ -34,19 +35,19 @@ If you use [Pathogen](https://github.com/tpope/vim-pathogen), do this:
```sh ```sh
cd ~/.vim/bundle cd ~/.vim/bundle
git clone https://github.com/plasticboy/vim-markdown.git git clone https://github.com/preservim/vim-markdown.git
``` ```
To install without Pathogen using the Debian [vim-addon-manager](http://packages.qa.debian.org/v/vim-addon-manager.html), do this: To install without Pathogen using the Debian [vim-addon-manager](http://packages.qa.debian.org/v/vim-addon-manager.html), do this:
```sh ```sh
git clone https://github.com/plasticboy/vim-markdown.git git clone https://github.com/preservim/vim-markdown.git
cd vim-markdown cd vim-markdown
sudo make install sudo make install
vim-addon-manager install markdown vim-addon-manager install markdown
``` ```
If you are not using any package manager, download the [tarball](https://github.com/plasticboy/vim-markdown/archive/master.tar.gz) and do this: If you are not using any package manager, download the [tarball](https://github.com/preservim/vim-markdown/archive/master.tar.gz) and do this:
```sh ```sh
cd ~/.vim cd ~/.vim
@ -370,19 +371,19 @@ The following work on normal and visual modes:
Known limitation: does not work for links that span multiple lines. Known limitation: does not work for links that span multiple lines.
- `ge`: open the link under the cursor in Vim for editing. Useful for relative markdown links. `<Plug>Markdown_EditUrlUnderCursor` - `ge`: open the link under the cursor in Vim for editing. Useful for relative markdown links. Falls back to `gf` with force editing, if not on a markdown link. `<Plug>Markdown_EditUrlUnderCursor`
The rules for the cursor position are the same as the `gx` command. The rules for the cursor position are the same as the `gx` command.
- `]]`: go to next header. `<Plug>Markdown_MoveToNextHeader` - `]]`: go to next header. `<Plug>Markdown_MoveToNextHeader`
- `[[`: go to previous header. Contrast with `]c`. `<Plug>Markdown_MoveToPreviousHeader` - `[[`: go to previous header. Contrast with `]h`. `<Plug>Markdown_MoveToPreviousHeader`
- `][`: go to next sibling header if any. `<Plug>Markdown_MoveToNextSiblingHeader` - `][`: go to next sibling header if any. `<Plug>Markdown_MoveToNextSiblingHeader`
- `[]`: go to previous sibling header if any. `<Plug>Markdown_MoveToPreviousSiblingHeader` - `[]`: go to previous sibling header if any. `<Plug>Markdown_MoveToPreviousSiblingHeader`
- `]c`: go to Current header. `<Plug>Markdown_MoveToCurHeader` - `]h`: go to Current header. `<Plug>Markdown_MoveToCurHeader`
- `]u`: go to parent header (Up). `<Plug>Markdown_MoveToParentHeader` - `]u`: go to parent header (Up). `<Plug>Markdown_MoveToParentHeader`
@ -443,7 +444,7 @@ The following requires `:filetype plugin on`.
The main contributors of vim-markdown are: The main contributors of vim-markdown are:
- **Ben Williams** (A.K.A. **plasticboy**). The original developer of vim-markdown. [Homepage](http://plasticboy.com/). - **Ben Williams** (A.K.A. **@plasticboy**). The original developer of vim-markdown. [Homepage](http://plasticboy.com/).
If you feel that your name should be on this list, please make a pull request listing your contributions. If you feel that your name should be on this list, please make a pull request listing your contributions.

View File

@ -9,15 +9,15 @@
function! s:is_mkdCode(lnum) function! s:is_mkdCode(lnum)
let name = synIDattr(synID(a:lnum, 1, 0), 'name') let name = synIDattr(synID(a:lnum, 1, 0), 'name')
return (name =~ '^mkd\%(Code$\|Snippet\)' || name != '' && name !~ '^\%(mkd\|html\)') return (name =~# '^mkd\%(Code$\|Snippet\)' || name !=# '' && name !~? '^\%(mkd\|html\)')
endfunction endfunction
if get(g:, "vim_markdown_folding_style_pythonic", 0) if get(g:, 'vim_markdown_folding_style_pythonic', 0)
function! Foldexpr_markdown(lnum) function! Foldexpr_markdown(lnum)
let l1 = getline(a:lnum) let l1 = getline(a:lnum)
"~~~~~ keep track of fenced code blocks ~~~~~ "~~~~~ keep track of fenced code blocks ~~~~~
"If we hit a code block fence "If we hit a code block fence
if l1 =~ '````*' || l1 =~ '\~\~\~\~*' if l1 =~# '````*' || l1 =~# '\~\~\~\~*'
" toggle the variable that says if we're in a code block " toggle the variable that says if we're in a code block
if b:fenced_block == 0 if b:fenced_block == 0
let b:fenced_block = 1 let b:fenced_block = 1
@ -30,14 +30,14 @@ if get(g:, "vim_markdown_folding_style_pythonic", 0)
if b:front_matter == 1 && a:lnum > 2 if b:front_matter == 1 && a:lnum > 2
let l0 = getline(a:lnum-1) let l0 = getline(a:lnum-1)
" if the previous line fenced front matter " if the previous line fenced front matter
if l0 == '---' if l0 ==# '---'
" we must not be in front matter " we must not be in front matter
let b:front_matter = 0 let b:front_matter = 0
endif endif
" else, if we're on line one " else, if we're on line one
elseif a:lnum == 1 elseif a:lnum == 1
" if we hit a front matter fence " if we hit a front matter fence
if l1 == '---' if l1 ==# '---'
" we're in the front matter " we're in the front matter
let b:front_matter = 1 let b:front_matter = 1
endif endif
@ -45,8 +45,8 @@ if get(g:, "vim_markdown_folding_style_pythonic", 0)
endif endif
" if we're in a code block or front matter " if we're in a code block or front matter
if b:fenced_block == 1 || b:front_matter == 1 if b:fenced_block ==# 1 || b:front_matter ==# 1
if a:lnum == 1 if a:lnum ==# 1
" fold any 'preamble' " fold any 'preamble'
return '>1' return '>1'
else else
@ -58,18 +58,19 @@ if get(g:, "vim_markdown_folding_style_pythonic", 0)
let l2 = getline(a:lnum+1) let l2 = getline(a:lnum+1)
" if the next line starts with two or more '=' " if the next line starts with two or more '='
" and is not code " and is not code
if l2 =~ '^==\+\s*' && !s:is_mkdCode(a:lnum+1) if l2 =~# '^==\+\s*' && !s:is_mkdCode(a:lnum+1)
" next line is underlined (level 1) " next line is underlined (level 1)
return '>0' return '>0'
" else, if the nex line starts with two or more '-' " else, if the nex line starts with two or more '-'
" but is not comment closer (-->)
" and is not code " and is not code
elseif l2 =~ '^--\+\s*' && !s:is_mkdCode(a:lnum+1) elseif l2 =~# '^--\+\s*$' && !s:is_mkdCode(a:lnum+1)
" next line is underlined (level 2) " next line is underlined (level 2)
return '>1' return '>1'
endif endif
"if we're on a non-code line starting with a pound sign "if we're on a non-code line starting with a pound sign
if l1 =~ '^#' && !s:is_mkdCode(a:lnum) if l1 =~# '^#' && !s:is_mkdCode(a:lnum)
" set the fold level to the number of hashes -1 " set the fold level to the number of hashes -1
" return '>'.(matchend(l1, '^#\+') - 1) " return '>'.(matchend(l1, '^#\+') - 1)
" set the fold level to the number of hashes " set the fold level to the number of hashes
@ -87,13 +88,13 @@ if get(g:, "vim_markdown_folding_style_pythonic", 0)
function! Foldtext_markdown() function! Foldtext_markdown()
let line = getline(v:foldstart) let line = getline(v:foldstart)
let has_numbers = &number || &relativenumber let has_numbers = &number || &relativenumber
let nucolwidth = &fdc + has_numbers * &numberwidth let nucolwidth = &foldcolumn + has_numbers * &numberwidth
let windowwidth = winwidth(0) - nucolwidth - 6 let windowwidth = winwidth(0) - nucolwidth - 6
let foldedlinecount = v:foldend - v:foldstart let foldedlinecount = v:foldend - v:foldstart
let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount)) let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
let line = substitute(line, '\%("""\|''''''\)', '', '') let line = substitute(line, '\%("""\|''''''\)', '', '')
let fillcharcount = windowwidth - len(line) - len(foldedlinecount) + 1 let fillcharcount = windowwidth - len(line) - len(foldedlinecount) + 1
return line . ' ' . repeat("-", fillcharcount) . ' ' . foldedlinecount return line . ' ' . repeat('-', fillcharcount) . ' ' . foldedlinecount
endfunction endfunction
else " vim_markdown_folding_style_pythonic == 0 else " vim_markdown_folding_style_pythonic == 0
function! Foldexpr_markdown(lnum) function! Foldexpr_markdown(lnum)
@ -104,7 +105,7 @@ else " vim_markdown_folding_style_pythonic == 0
endif endif
" keep track of fenced code blocks " keep track of fenced code blocks
if l0 =~ '````*' || l0 =~ '\~\~\~\~*' if l0 =~# '````*' || l0 =~# '\~\~\~\~*'
if b:fenced_block == 0 if b:fenced_block == 0
let b:fenced_block = 1 let b:fenced_block = 1
elseif b:fenced_block == 1 elseif b:fenced_block == 1
@ -112,11 +113,11 @@ else " vim_markdown_folding_style_pythonic == 0
endif endif
elseif g:vim_markdown_frontmatter == 1 elseif g:vim_markdown_frontmatter == 1
if b:front_matter == 1 if b:front_matter == 1
if l0 == '---' if l0 ==# '---'
let b:front_matter = 0 let b:front_matter = 0
endif endif
elseif a:lnum == 2 elseif a:lnum == 2
if l0 == '---' if l0 ==# '---'
let b:front_matter = 1 let b:front_matter = 1
endif endif
endif endif
@ -128,10 +129,10 @@ else " vim_markdown_folding_style_pythonic == 0
endif endif
let l2 = getline(a:lnum+1) let l2 = getline(a:lnum+1)
if l2 =~ '^==\+\s*' && !s:is_mkdCode(a:lnum+1) if l2 =~# '^==\+\s*' && !s:is_mkdCode(a:lnum+1)
" next line is underlined (level 1) " next line is underlined (level 1)
return '>1' return '>1'
elseif l2 =~ '^--\+\s*' && !s:is_mkdCode(a:lnum+1) elseif l2 =~# '^--\+\s*$' && !s:is_mkdCode(a:lnum+1)
" next line is underlined (level 2) " next line is underlined (level 2)
if s:vim_markdown_folding_level >= 2 if s:vim_markdown_folding_level >= 2
return '>1' return '>1'
@ -141,7 +142,7 @@ else " vim_markdown_folding_style_pythonic == 0
endif endif
let l1 = getline(a:lnum) let l1 = getline(a:lnum)
if l1 =~ '^#' && !s:is_mkdCode(a:lnum) if l1 =~# '^#' && !s:is_mkdCode(a:lnum)
" fold level according to option " fold level according to option
if s:vim_markdown_folding_level == 1 || matchend(l1, '^#\+') > s:vim_markdown_folding_level if s:vim_markdown_folding_level == 1 || matchend(l1, '^#\+') > s:vim_markdown_folding_level
if a:lnum == line('$') if a:lnum == line('$')
@ -155,7 +156,7 @@ else " vim_markdown_folding_style_pythonic == 0
endif endif
endif endif
if l0 =~ '^#' && !s:is_mkdCode(a:lnum-1) if l0 =~# '^#' && !s:is_mkdCode(a:lnum-1)
" previous line starts with hashes " previous line starts with hashes
return '>'.matchend(l0, '^#\+') return '>'.matchend(l0, '^#\+')
else else
@ -168,12 +169,12 @@ endif
let b:fenced_block = 0 let b:fenced_block = 0
let b:front_matter = 0 let b:front_matter = 0
let s:vim_markdown_folding_level = get(g:, "vim_markdown_folding_level", 1) let s:vim_markdown_folding_level = get(g:, 'vim_markdown_folding_level', 1)
function! s:MarkdownSetupFolding() function! s:MarkdownSetupFolding()
if !get(g:, "vim_markdown_folding_disabled", 0) if !get(g:, 'vim_markdown_folding_disabled', 0)
if get(g:, "vim_markdown_folding_style_pythonic", 0) if get(g:, 'vim_markdown_folding_style_pythonic', 0)
if get(g:, "vim_markdown_override_foldtext", 1) if get(g:, 'vim_markdown_override_foldtext', 1)
setlocal foldtext=Foldtext_markdown() setlocal foldtext=Foldtext_markdown()
endif endif
endif endif
@ -183,9 +184,9 @@ function! s:MarkdownSetupFolding()
endfunction endfunction
function! s:MarkdownSetupFoldLevel() function! s:MarkdownSetupFoldLevel()
if get(g:, "vim_markdown_folding_style_pythonic", 0) if get(g:, 'vim_markdown_folding_style_pythonic', 0)
" set default foldlevel " set default foldlevel
execute "setlocal foldlevel=".s:vim_markdown_folding_level execute 'setlocal foldlevel='.s:vim_markdown_folding_level
endif endif
endfunction endfunction

View File

@ -55,7 +55,7 @@ Installation ~
If you use Vundle [2], add the following lines to your '~/.vimrc': If you use Vundle [2], add the following lines to your '~/.vimrc':
> >
Plugin 'godlygeek/tabular' Plugin 'godlygeek/tabular'
Plugin 'plasticboy/vim-markdown' Plugin 'preservim/vim-markdown'
< <
The 'tabular' plugin must come _before_ 'vim-markdown'. The 'tabular' plugin must come _before_ 'vim-markdown'.
@ -67,11 +67,11 @@ Then run inside Vim:
If you use Pathogen [3], do this: If you use Pathogen [3], do this:
> >
cd ~/.vim/bundle cd ~/.vim/bundle
git clone https://github.com/plasticboy/vim-markdown.git git clone https://github.com/preservim/vim-markdown.git
< <
To install without Pathogen using the Debian vim-addon-manager [4], do this: To install without Pathogen using the Debian vim-addon-manager [4], do this:
> >
git clone https://github.com/plasticboy/vim-markdown.git git clone https://github.com/preservim/vim-markdown.git
cd vim-markdown cd vim-markdown
sudo make install sudo make install
vim-addon-manager install markdown vim-addon-manager install markdown
@ -525,7 +525,7 @@ The following work on normal and visual modes:
- ']]': go to next header. '<Plug>Markdown_MoveToNextHeader' - ']]': go to next header. '<Plug>Markdown_MoveToNextHeader'
*vim-markdown-[[* *vim-markdown-[[*
- '[[': go to previous header. Contrast with ']c'. - '[[': go to previous header. Contrast with ']h'.
'<Plug>Markdown_MoveToPreviousHeader' '<Plug>Markdown_MoveToPreviousHeader'
*vim-markdown-][* *vim-markdown-][*
@ -536,8 +536,8 @@ The following work on normal and visual modes:
- '[]': go to previous sibling header if any. - '[]': go to previous sibling header if any.
'<Plug>Markdown_MoveToPreviousSiblingHeader' '<Plug>Markdown_MoveToPreviousSiblingHeader'
*vim-markdown-]c* *vim-markdown-]h*
- ']c': go to Current header. '<Plug>Markdown_MoveToCurHeader' - ']h': go to Current header. '<Plug>Markdown_MoveToCurHeader'
*vim-markdown-]u* *vim-markdown-]u*
- ']u': go to parent header (Up). '<Plug>Markdown_MoveToParentHeader' - ']u': go to parent header (Up). '<Plug>Markdown_MoveToParentHeader'
@ -651,7 +651,7 @@ References ~
[2] https://github.com/gmarik/vundle [2] https://github.com/gmarik/vundle
[3] https://github.com/tpope/vim-pathogen [3] https://github.com/tpope/vim-pathogen
[4] http://packages.qa.debian.org/v/vim-addon-manager.html [4] http://packages.qa.debian.org/v/vim-addon-manager.html
[5] https://github.com/plasticboy/vim-markdown/archive/master.tar.gz [5] https://github.com/preservim/vim-markdown/archive/master.tar.gz
[6] https://github.com/klen/python-mode [6] https://github.com/klen/python-mode
[7] https://gohugo.io/content/front-matter/ [7] https://gohugo.io/content/front-matter/
[8] https://github.com/cespare/vim-toml [8] https://github.com/cespare/vim-toml

View File

@ -3,6 +3,6 @@ if !has('patch-7.4.480')
au! filetypedetect BufRead,BufNewFile *.md au! filetypedetect BufRead,BufNewFile *.md
endif endif
" markdown filetype file " vint: -ProhibitAutocmdWithNoGroup
au BufRead,BufNewFile *.{md,mdx,mdown,mkd,mkdn,markdown,mdwn} setfiletype markdown au BufRead,BufNewFile *.{md,mdx,mdown,mkd,mkdn,markdown,mdwn} setfiletype markdown
au BufRead,BufNewFile *.{md,mdx,mdown,mkd,mkdn,markdown,mdwn}.{des3,des,bf,bfa,aes,idea,cast,rc2,rc4,rc5,desx} setfiletype markdown au BufRead,BufNewFile *.{md,mdx,mdown,mkd,mkdn,markdown,mdwn}.{des3,des,bf,bfa,aes,idea,cast,rc2,rc4,rc5,desx} setfiletype markdown

View File

@ -94,7 +94,7 @@ endfunction
" "
function! s:MoveToCurHeader() function! s:MoveToCurHeader()
let l:lineNum = s:GetHeaderLineNum() let l:lineNum = s:GetHeaderLineNum()
if l:lineNum != 0 if l:lineNum !=# 0
call cursor(l:lineNum, 1) call cursor(l:lineNum, 1)
else else
echo 'outside any header' echo 'outside any header'
@ -147,7 +147,7 @@ function! s:GetHeaderLevel(...)
let l:line = a:1 let l:line = a:1
endif endif
let l:linenum = s:GetHeaderLineNum(l:line) let l:linenum = s:GetHeaderLineNum(l:line)
if l:linenum != 0 if l:linenum !=# 0
return s:GetLevelOfHeaderAtLine(l:linenum) return s:GetLevelOfHeaderAtLine(l:linenum)
else else
return 0 return 0
@ -161,13 +161,13 @@ function! s:GetHeaderList()
let l:fenced_block = 0 let l:fenced_block = 0
let l:front_matter = 0 let l:front_matter = 0
let l:header_list = [] let l:header_list = []
let l:vim_markdown_frontmatter = get(g:, "vim_markdown_frontmatter", 0) let l:vim_markdown_frontmatter = get(g:, 'vim_markdown_frontmatter', 0)
for i in range(1, line('$')) for i in range(1, line('$'))
let l:lineraw = getline(i) let l:lineraw = getline(i)
let l:l1 = getline(i+1) let l:l1 = getline(i+1)
let l:line = substitute(l:lineraw, "#", "\\\#", "g") let l:line = substitute(l:lineraw, '#', "\\\#", 'g')
" exclude lines in fenced code blocks " exclude lines in fenced code blocks
if l:line =~ '````*' || l:line =~ '\~\~\~\~*' if l:line =~# '````*' || l:line =~# '\~\~\~\~*'
if l:fenced_block == 0 if l:fenced_block == 0
let l:fenced_block = 1 let l:fenced_block = 1
elseif l:fenced_block == 1 elseif l:fenced_block == 1
@ -176,24 +176,24 @@ function! s:GetHeaderList()
" exclude lines in frontmatters " exclude lines in frontmatters
elseif l:vim_markdown_frontmatter == 1 elseif l:vim_markdown_frontmatter == 1
if l:front_matter == 1 if l:front_matter == 1
if l:line == '---' if l:line ==# '---'
let l:front_matter = 0 let l:front_matter = 0
endif endif
elseif i == 1 elseif i == 1
if l:line == '---' if l:line ==# '---'
let l:front_matter = 1 let l:front_matter = 1
endif endif
endif endif
endif endif
" match line against header regex " match line against header regex
if join(getline(i, i + 1), "\n") =~ s:headersRegexp && l:line =~ '^\S' if join(getline(i, i + 1), "\n") =~# s:headersRegexp && l:line =~# '^\S'
let l:is_header = 1 let l:is_header = 1
else else
let l:is_header = 0 let l:is_header = 0
endif endif
if l:is_header == 1 && l:fenced_block == 0 && l:front_matter == 0 if l:is_header ==# 1 && l:fenced_block ==# 0 && l:front_matter ==# 0
" remove hashes from atx headers " remove hashes from atx headers
if match(l:line, "^#") > -1 if match(l:line, '^#') > -1
let l:line = substitute(l:line, '\v^#*[ ]*', '', '') let l:line = substitute(l:line, '\v^#*[ ]*', '', '')
let l:line = substitute(l:line, '\v[ ]*#*$', '', '') let l:line = substitute(l:line, '\v[ ]*#*$', '', '')
endif endif
@ -361,11 +361,11 @@ function! s:Toc(...)
let l:header_list = s:GetHeaderList() let l:header_list = s:GetHeaderList()
let l:indented_header_list = [] let l:indented_header_list = []
if len(l:header_list) == 0 if len(l:header_list) == 0
echom "Toc: No headers." echom 'Toc: No headers.'
return return
endif endif
let l:header_max_len = 0 let l:header_max_len = 0
let l:vim_markdown_toc_autofit = get(g:, "vim_markdown_toc_autofit", 0) let l:vim_markdown_toc_autofit = get(g:, 'vim_markdown_toc_autofit', 0)
for h in l:header_list for h in l:header_list
" set header number of the cursor position " set header number of the cursor position
if l:cursor_header == 0 if l:cursor_header == 0
@ -438,7 +438,7 @@ function! s:InsertToc(format, ...)
let l:toc = [] let l:toc = []
let l:header_list = s:GetHeaderList() let l:header_list = s:GetHeaderList()
if len(l:header_list) == 0 if len(l:header_list) == 0
echom "InsertToc: No headers." echom 'InsertToc: No headers.'
return return
endif endif
@ -550,7 +550,7 @@ function! s:TableFormat()
" Move colons for alignment to left or right side of the cell. " Move colons for alignment to left or right side of the cell.
execute 's/:\( \+\)|/\1:|/e' . l:flags execute 's/:\( \+\)|/\1:|/e' . l:flags
execute 's/|\( \+\):/|:\1/e' . l:flags execute 's/|\( \+\):/|:\1/e' . l:flags
execute 's/ /-/' . l:flags execute 's/|:\?\zs[ -]\+\ze:\?|/\=repeat("-", len(submatch(0)))/' . l:flags
call setpos('.', l:pos) call setpos('.', l:pos)
endfunction endfunction
@ -653,7 +653,7 @@ endfunction
" "
function! s:OpenUrlUnderCursor() function! s:OpenUrlUnderCursor()
let l:url = s:Markdown_GetUrlForPosition(line('.'), col('.')) let l:url = s:Markdown_GetUrlForPosition(line('.'), col('.'))
if l:url != '' if l:url !=# ''
call s:VersionAwareNetrwBrowseX(l:url) call s:VersionAwareNetrwBrowseX(l:url)
else else
echomsg 'The cursor is not on a link.' echomsg 'The cursor is not on a link.'
@ -664,8 +664,24 @@ endfunction
" script while this function is running. We must not replace it. " script while this function is running. We must not replace it.
if !exists('*s:EditUrlUnderCursor') if !exists('*s:EditUrlUnderCursor')
function s:EditUrlUnderCursor() function s:EditUrlUnderCursor()
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
let l:url = s:Markdown_GetUrlForPosition(line('.'), col('.')) let l:url = s:Markdown_GetUrlForPosition(line('.'), col('.'))
if l:url != '' if l:url !=# ''
if get(g:, 'vim_markdown_autowrite', 0) if get(g:, 'vim_markdown_autowrite', 0)
write write
endif endif
@ -675,14 +691,14 @@ if !exists('*s:EditUrlUnderCursor')
if len(l:parts) == 2 if len(l:parts) == 2
let [l:url, l:anchor] = parts let [l:url, l:anchor] = parts
let l:anchorexpr = get(g:, 'vim_markdown_anchorexpr', '') let l:anchorexpr = get(g:, 'vim_markdown_anchorexpr', '')
if l:anchorexpr != '' if l:anchorexpr !=# ''
let l:anchor = eval(substitute( let l:anchor = eval(substitute(
\ l:anchorexpr, 'v:anchor', \ l:anchorexpr, 'v:anchor',
\ escape('"'.l:anchor.'"', '"'), '')) \ escape('"'.l:anchor.'"', '"'), ''))
endif endif
endif endif
endif endif
if l:url != '' if l:url !=# ''
let l:ext = '' let l:ext = ''
if get(g:, 'vim_markdown_no_extensions_in_markdown', 0) if get(g:, 'vim_markdown_no_extensions_in_markdown', 0)
" use another file extension if preferred " use another file extension if preferred
@ -693,29 +709,13 @@ if !exists('*s:EditUrlUnderCursor')
endif endif
endif endif
let l:url = fnameescape(fnamemodify(expand('%:h').'/'.l:url.l:ext, ':.')) let l:url = fnameescape(fnamemodify(expand('%:h').'/'.l:url.l:ext, ':.'))
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 execute l:editmethod l:url
endif endif
if l:anchor != '' if l:anchor !=# ''
silent! execute '/'.l:anchor silent! execute '/'.l:anchor
endif endif
else else
echomsg 'The cursor is not on a link.' execute l:editmethod . ' <cfile>'
endif endif
endfunction endfunction
endif endif
@ -750,7 +750,7 @@ if !get(g:, 'vim_markdown_no_default_key_mappings', 0)
call <sid>MapNotHasmapto('][', 'Markdown_MoveToNextSiblingHeader') call <sid>MapNotHasmapto('][', 'Markdown_MoveToNextSiblingHeader')
call <sid>MapNotHasmapto('[]', 'Markdown_MoveToPreviousSiblingHeader') call <sid>MapNotHasmapto('[]', 'Markdown_MoveToPreviousSiblingHeader')
call <sid>MapNotHasmapto(']u', 'Markdown_MoveToParentHeader') call <sid>MapNotHasmapto(']u', 'Markdown_MoveToParentHeader')
call <sid>MapNotHasmapto(']c', 'Markdown_MoveToCurHeader') call <sid>MapNotHasmapto(']h', 'Markdown_MoveToCurHeader')
call <sid>MapNotHasmapto('gx', 'Markdown_OpenUrlUnderCursor') call <sid>MapNotHasmapto('gx', 'Markdown_OpenUrlUnderCursor')
call <sid>MapNotHasmapto('ge', 'Markdown_EditUrlUnderCursor') call <sid>MapNotHasmapto('ge', 'Markdown_EditUrlUnderCursor')
endif endif
@ -770,8 +770,8 @@ command! -buffer -nargs=? InsertNToc call s:InsertToc('numbers', <args>)
if exists('g:vim_markdown_fenced_languages') if exists('g:vim_markdown_fenced_languages')
let s:filetype_dict = {} let s:filetype_dict = {}
for s:filetype in g:vim_markdown_fenced_languages for s:filetype in g:vim_markdown_fenced_languages
let key = matchstr(s:filetype, "[^=]*") let key = matchstr(s:filetype, '[^=]*')
let val = matchstr(s:filetype, "[^=]*$") let val = matchstr(s:filetype, '[^=]*$')
let s:filetype_dict[key] = val let s:filetype_dict[key] = val
endfor endfor
else else
@ -788,8 +788,8 @@ function! s:MarkdownHighlightSources(force)
" Look for code blocks in the current file " Look for code blocks in the current file
let filetypes = {} let filetypes = {}
for line in getline(1, '$') for line in getline(1, '$')
let ft = matchstr(line, '```\s*\zs[0-9A-Za-z_+-]*\ze.*') let ft = matchstr(line, '\(`\{3,}\|\~\{3,}\)\s*\zs[0-9A-Za-z_+-]*\ze.*')
if !empty(ft) && ft !~ '^\d*$' | let filetypes[ft] = 1 | endif if !empty(ft) && ft !~# '^\d*$' | let filetypes[ft] = 1 | endif
endfor endfor
if !exists('b:mkd_known_filetypes') if !exists('b:mkd_known_filetypes')
let b:mkd_known_filetypes = {} let b:mkd_known_filetypes = {}
@ -812,15 +812,17 @@ function! s:MarkdownHighlightSources(force)
else else
let filetype = ft let filetype = ft
endif endif
let group = 'mkdSnippet' . toupper(substitute(filetype, "[+-]", "_", "g")) let group = 'mkdSnippet' . toupper(substitute(filetype, '[+-]', '_', 'g'))
if !has_key(b:mkd_included_filetypes, filetype) if !has_key(b:mkd_included_filetypes, filetype)
let include = s:SyntaxInclude(filetype) let include = s:SyntaxInclude(filetype)
let b:mkd_included_filetypes[filetype] = 1 let b:mkd_included_filetypes[filetype] = 1
else else
let include = '@' . toupper(filetype) let include = '@' . toupper(filetype)
endif endif
let command = 'syntax region %s matchgroup=%s start="^\s*```\s*%s.*$" matchgroup=%s end="\s*```$" keepend contains=%s%s' let command_backtick = 'syntax region %s matchgroup=%s start="^\s*`\{3,}\s*%s.*$" matchgroup=%s end="\s*`\{3,}$" keepend contains=%s%s'
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' : '') let command_tilde = 'syntax region %s matchgroup=%s start="^\s*\~\{3,}\s*%s.*$" matchgroup=%s end="\s*\~\{3,}$" keepend contains=%s%s'
execute printf(command_backtick, group, startgroup, ft, endgroup, include, has('conceal') && get(g:, 'vim_markdown_conceal', 1) && get(g:, 'vim_markdown_conceal_code_blocks', 1) ? ' concealends' : '')
execute printf(command_tilde, 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) execute printf('syntax cluster mkdNonListItem add=%s', group)
let b:mkd_known_filetypes[ft] = 1 let b:mkd_known_filetypes[ft] = 1
@ -854,13 +856,17 @@ endfunction
function! s:MarkdownRefreshSyntax(force) function! s:MarkdownRefreshSyntax(force)
if &filetype =~ 'markdown' && line('$') > 1 " Use != to compare &syntax's value to use the same logic run on
" $VIMRUNTIME/syntax/synload.vim.
"
" vint: next-line -ProhibitEqualTildeOperator
if &filetype =~# 'markdown' && line('$') > 1 && &syntax != 'OFF'
call s:MarkdownHighlightSources(a:force) call s:MarkdownHighlightSources(a:force)
endif endif
endfunction endfunction
function! s:MarkdownClearSyntaxVariables() function! s:MarkdownClearSyntaxVariables()
if &filetype =~ 'markdown' if &filetype =~# 'markdown'
unlet! b:mkd_included_filetypes unlet! b:mkd_included_filetypes
endif endif
endfunction endfunction

18
sources_non_forked/vim-markdown/indent/markdown.vim Normal file → Executable file
View File

@ -1,4 +1,4 @@
if exists("b:did_indent") | finish | endif if exists('b:did_indent') | finish | endif
let b:did_indent = 1 let b:did_indent = 1
setlocal indentexpr=GetMarkdownIndent() setlocal indentexpr=GetMarkdownIndent()
@ -8,7 +8,7 @@ setlocal autoindent
" Automatically continue blockquote on line break " Automatically continue blockquote on line break
setlocal formatoptions+=r setlocal formatoptions+=r
setlocal comments=b:> setlocal comments=b:>
if get(g:, "vim_markdown_auto_insert_bullets", 1) if get(g:, 'vim_markdown_auto_insert_bullets', 1)
" Do not automatically insert bullets when auto-wrapping with text-width " Do not automatically insert bullets when auto-wrapping with text-width
setlocal formatoptions-=c setlocal formatoptions-=c
" Accept various markers as bullets " Accept various markers as bullets
@ -16,24 +16,24 @@ if get(g:, "vim_markdown_auto_insert_bullets", 1)
endif endif
" Only define the function once " Only define the function once
if exists("*GetMarkdownIndent") | finish | endif if exists('*GetMarkdownIndent') | finish | endif
function! s:IsMkdCode(lnum) function! s:IsMkdCode(lnum)
let name = synIDattr(synID(a:lnum, 1, 0), 'name') let name = synIDattr(synID(a:lnum, 1, 0), 'name')
return (name =~ '^mkd\%(Code$\|Snippet\)' || name != '' && name !~ '^\%(mkd\|html\)') return (name =~# '^mkd\%(Code$\|Snippet\)' || name !=# '' && name !~? '^\%(mkd\|html\)')
endfunction endfunction
function! s:IsLiStart(line) function! s:IsLiStart(line)
return a:line !~ '^ *\([*-]\)\%( *\1\)\{2}\%( \|\1\)*$' && return a:line !~# '^ *\([*-]\)\%( *\1\)\{2}\%( \|\1\)*$' &&
\ a:line =~ '^\s*[*+-] \+' \ a:line =~# '^\s*[*+-] \+'
endfunction endfunction
function! s:IsHeaderLine(line) function! s:IsHeaderLine(line)
return a:line =~ '^\s*#' return a:line =~# '^\s*#'
endfunction endfunction
function! s:IsBlankLine(line) function! s:IsBlankLine(line)
return a:line =~ '^$' return a:line =~# '^$'
endfunction endfunction
function! s:PrevNonBlank(lnum) function! s:PrevNonBlank(lnum)
@ -48,7 +48,7 @@ function GetMarkdownIndent()
if v:lnum > 2 && s:IsBlankLine(getline(v:lnum - 1)) && s:IsBlankLine(getline(v:lnum - 2)) if v:lnum > 2 && s:IsBlankLine(getline(v:lnum - 1)) && s:IsBlankLine(getline(v:lnum - 2))
return 0 return 0
endif endif
let list_ind = get(g:, "vim_markdown_new_list_item_indent", 4) let list_ind = get(g:, 'vim_markdown_new_list_item_indent', 4)
" Find a non-blank line above the current line. " Find a non-blank line above the current line.
let lnum = s:PrevNonBlank(v:lnum - 1) let lnum = s:PrevNonBlank(v:lnum - 1)
" At the start of the file use zero indent. " At the start of the file use zero indent.

View File

@ -7,7 +7,7 @@
" Read the HTML syntax to start with " Read the HTML syntax to start with
if version < 600 if v:version < 600
so <sfile>:p:h/html.vim so <sfile>:p:h/html.vim
else else
runtime! syntax/html.vim runtime! syntax/html.vim
@ -17,14 +17,14 @@ else
endif endif
endif endif
if version < 600 if v:version < 600
syntax clear syntax clear
elseif exists("b:current_syntax") elseif exists('b:current_syntax')
finish finish
endif endif
" don't use standard HiLink, it will not work with included syntax files " don't use standard HiLink, it will not work with included syntax files
if version < 508 if v:version < 508
command! -nargs=+ HtmlHiLink hi link <args> command! -nargs=+ HtmlHiLink hi link <args>
else else
command! -nargs=+ HtmlHiLink hi def link <args> command! -nargs=+ HtmlHiLink hi def link <args>
@ -178,7 +178,7 @@ HtmlHiLink mkdLinkDefTarget mkdURL
HtmlHiLink mkdLinkTitle htmlString HtmlHiLink mkdLinkTitle htmlString
HtmlHiLink mkdDelimiter Delimiter HtmlHiLink mkdDelimiter Delimiter
let b:current_syntax = "mkd" let b:current_syntax = 'mkd'
delcommand HtmlHiLink delcommand HtmlHiLink
" vim: ts=8 " vim: ts=8

View File

@ -2,6 +2,7 @@
Before: Before:
source ../after/ftplugin/markdown.vim source ../after/ftplugin/markdown.vim
setlocal foldtext=foldtext()
After: After:
setlocal foldexpr=0 setlocal foldexpr=0

View File

@ -146,8 +146,8 @@ Given markdown;
b b
Execute (]c): Execute (]h):
normal! 3G normal! 3G
AssertEqual line('.'), 3 AssertEqual line('.'), 3
normal ]c normal ]h
AssertEqual line('.'), 1 AssertEqual line('.'), 1

0
sources_non_forked/vim-markdown/test/run-tests.sh Normal file → Executable file
View File

View File

@ -31,7 +31,7 @@ end
[a]( b [a]( b
"c" ) "c" )
a (`a`) b. Fix: <https://github.com/plasticboy/vim-markdown/issues/113> a (`a`) b. Fix: <https://github.com/preservim/vim-markdown/issues/113>
Escaped: Escaped:

View File

@ -30,6 +30,19 @@ Expect (table is not modified):
|---|---| |---|---|
| c | d | | c | d |
Given markdown (indented table);
| a | b |
|---|---|
| c | d |
Execute (format well formatted, indented table):
TableFormat
Expect (table is not modified):
| a | b |
|---|---|
| c | d |
Given markdown; Given markdown;
| left |right| center || | left |right| center ||
| :- | --: |:---:|:| | :- | --: |:---:|:|
@ -42,3 +55,16 @@ Expect (preserve colons to align text):
| left | right | center | | | left | right | center | |
|:-----|------:|:------:|:--| |:-----|------:|:------:|:--|
| left | right | center | | | left | right | center | |
Given markdown (indented table with colons);
| left |right| center ||
| :- | --: |:---:|:|
| left |right| center ||
Execute (format indented table with colons):
TableFormat
Expect (preserve colons to align text):
| left | right | center | |
|:-----|------:|:------:|:--|
| left | right | center | |

View File

@ -1,16 +1,17 @@
set nocompatible set nocompatible
set rtp+=../
set rtp+=../build/tabular/
set rtp+=../build/vim-toml/
set rtp+=../build/vim-json/
set rtp+=../build/vader.vim/
set rtp-=~/.vim
set rtp-=~/.vim/after
let $LANG='en_US' let $LANG='en_US'
filetype off
set runtimepath+=../
set runtimepath+=../build/tabular/
set runtimepath+=../build/vim-toml/
set runtimepath+=../build/vim-json/
set runtimepath+=../build/vader.vim/
filetype on filetype on
filetype plugin on
filetype indent on filetype plugin indent on
syntax on syntax enable
function! Markdown_GetScriptID(fname) abort function! Markdown_GetScriptID(fname) abort
let l:snlist = '' let l:snlist = ''
@ -24,6 +25,7 @@ function! Markdown_GetScriptID(fname) abort
endif endif
endfor endfor
endfunction endfunction
function! Markdown_GetFunc(fname, funcname) abort function! Markdown_GetFunc(fname, funcname) abort
return function('<SNR>' . Markdown_GetScriptID(a:fname) . '_' . a:funcname) return function('<SNR>' . Markdown_GetScriptID(a:fname) . '_' . a:funcname)
endfunction endfunction