]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Squashed '.vim/bundle/vim-markdown/' changes from da5a7ac9..8f6cb3a6
authormartin f. krafft <madduck@madduck.net>
Tue, 8 Apr 2025 15:01:19 +0000 (17:01 +0200)
committermartin f. krafft <madduck@madduck.net>
Tue, 8 Apr 2025 15:01:19 +0000 (17:01 +0200)
8f6cb3a6 Merge pull request #636 from KSR-Yasuda/bugfix/CodeFenceHandling
7026436c Merge pull request #660 from KSR-Yasuda/bugfix/ContainCodeInHeading
4a3ddd7d Contain `mkdCode` in `mkdHeadingContent`
a657e697 docs: Correct mappings zo/zO and add za/zA (#652)
46add6c3 feat: Add (optin) support for formatting tables without borders (#643)
66ed2e14 Fix jumping to anchor
4e9b4ded docs: fix a couple of small typos in code comments
6b13e98b Highlight strikethrough text in headings
18f3af70 Highlight footnotes in headings
241161e0 Highlight bold italic text in headings
4f87df57 Highlight bold text in headings
2b9e32ec Highlight italics in headings
a6a1bed7 Fix code fence handling
cc82d88e Expand relative path URL using host path separator
5d3d1b6c docs: Mention need to *not* use semver support in plugin managers (#619)
df4be862 Add syntax group that matches a list item checkbox `mkdListItemCheckbox` (#564)
2cb8d9d8 Merge pull request #607 from lggruspe/fix-setextoatx
3bbbaa32 Allow fenced code highlight in liquid (#609)
aa7d685a Fix handling of frontmatter option (#595)
7231fa4b Allow escaped pipe (bar) characters inside TableFormat
67571a1c Fix invalid range in SetexToAtx
b9c5c34a Add failing tests for SetexToAtx
926cb9a3 Add tests for HeaderDecrease and HeaderIncrease
c3f83ebb Remove outdated advice for Vim plugins (#600)
8a0b4341 Fix broken link (#599)
3a964396 Disable code block syntax highlighting when syntax=OFF (#580)
9068655b Fix fenced code block syntax highlighting (#534)
c031a3e6 Avoid trailing comments `-->` turning the comment into a heading (#517)
95e90840 Merge pull request #573 from StarryLeo/revert-commit-18ed14a
21c8a8b2 chore: Clue in linter about ftdetect augroups
f868afae Revert "refactor: Execute autocmd in group scope"
b4dc23e2 Merge pull request #571 from tomtomjhj/table-format
a0467941 Add tests
e82be74d Fix TableFormat for indented tables, version 2
d7038a62 Merge pull request #570 from preservim/add-ci
aca1aaa9 Revert "Fix TableFormat for indented tables (#569)"
9297be2b Merge remote-tracking branch 'origin/master' into add-ci
0eb5bd6d docs(readme): Add CI workflow badges
6d5c19bf test: Make fold test NeoVIM/VIM compatible
ded139ce refactor: Cleanup test script for use with NeoVIM/VIM
90ca3483 chore(ci): Add Vader workflow to run regression tests
60022432 refactor: Make variable scope explicit
18ed14af refactor: Execute autocmd in group scope
9cdd48bc refactor: Use full option names
0888ec7e refactor: Prefer single quoted strings
8f16759b refactor: Use robust operators
0cb62d8d chore(ci): Add Reviewdog workflow to lint PRs
c9236dc3 chore(ci): Add vint workflow to lint vimscript
347e230c chore(tooling): Add vimscript lint configuration
50d42082 Change shortcut: MoveToCurHeader: `]c` -> `]h` (#556)
6e71e44a Markdown_EditUrlUnderCursor falls back to builtin gf (#566)
6fe1a105 Fix TableFormat for indented tables (#569)
9156bba6 Update canonical URL (forwarding in effect from original URL)
3ba557dc Drop obsolete Travis config (Travis dropped most FOSS)
8e5d86f7 Merge pull request #498 from jrwrigh/master
9497be60 fix: Remove debugging echo message
909c0e51 Merge pull request #492 from jrwrigh/master
dfd92dd4 test: Add test for characters after code block lang
23a51468 Merge pull request #497 from AggroBoy/master
9513e82a tweak html tag matching for code blocks
139b6f66 Merge pull request #477 from cdelledonne/insert-toc
cd46012b Merge pull request #472 from kalafut/master
3bb8e9ae Merge pull request #486 from jbriales/master
cb8d46ad Fix tex syntax test for latest syntax
154b1f85 feat: Allow characters after code block language
c1793167 Merge pull request #451 from yous/fix-url
b0081772 Save current cursor position to jumplist before MoveToParentHeader
4528ec64 Add `:InsertToc` and `:InsertNToc` commands
8db8763e Add GetHeaderList() in ftplugin/markdown.vim
583dc6a5 Add 'mdx' to recognized file extensions
c34496a6 Fix mkdInlineURL not to highlight after closing brackets

git-subtree-dir: .vim/bundle/vim-markdown
git-subtree-split: 8f6cb3a6ca4e3b6bcda0730145a0b700f3481b51

23 files changed:
.github/workflows/reviewdog.yml [new file with mode: 0644]
.github/workflows/vader.yml [new file with mode: 0644]
.github/workflows/vint.yml [new file with mode: 0644]
.travis.yml [deleted file]
.vintrc.yaml [new file with mode: 0644]
CONTRIBUTING.md
README.md
after/ftplugin/markdown.vim
doc/vim-markdown.txt
ftdetect/markdown.vim
ftplugin/markdown.vim
indent/markdown.vim
syntax/markdown.vim
test/folding-toc.vader
test/header-decrease.vader [new file with mode: 0644]
test/insert-toc.vader [new file with mode: 0644]
test/map.vader
test/setextoatx.vader [new file with mode: 0644]
test/strikethrough.vader [new file with mode: 0644]
test/syntax.md
test/syntax.vader
test/table-format.vader
test/vimrc

diff --git a/.github/workflows/reviewdog.yml b/.github/workflows/reviewdog.yml
new file mode 100644 (file)
index 0000000..421e438
--- /dev/null
@@ -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
diff --git a/.github/workflows/vader.yml b/.github/workflows/vader.yml
new file mode 100644 (file)
index 0000000..05b12ec
--- /dev/null
@@ -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! *"
diff --git a/.github/workflows/vint.yml b/.github/workflows/vint.yml
new file mode 100644 (file)
index 0000000..909de43
--- /dev/null
@@ -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 .
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644 (file)
index 338161c..0000000
+++ /dev/null
@@ -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
diff --git a/.vintrc.yaml b/.vintrc.yaml
new file mode 100644 (file)
index 0000000..c44b6ab
--- /dev/null
@@ -0,0 +1,5 @@
+cmdargs:
+  severity: style_problem
+  color: true
+  env:
+    neovim: false
index 86912a4a67ac6b7f9f33041e17539c0eaca3f2ed..736f0238071a1c02f584a042c4a155761bbd8ec9 100644 (file)
@@ -34,7 +34,7 @@ There are many flavors of markdown, each one with an unique feature set. This pl
 
 ## Style
 
 
 ## Style
 
-When choosing between multiple valid Markdown syntaxes, the default behavior must be that specified at: <http://www.cirosantilli.com/markdown-styleguide>
+When choosing between multiple valid Markdown syntaxes, the default behavior must be that specified at: <https://cirosantilli.com/markdown-style-guide>
 
 If you wish to have a behavior that differs from that style guide, add an option to turn it on or off, and leave it off by default.
 
 
 If you wish to have a behavior that differs from that style guide, add an option to turn it on or off, and leave it off by default.
 
@@ -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:
index fd3be68762df7eb7c81fb72bcbe5a2270548142a..3ccf532547fcdde3d4494d2b86f0175f3f773fcc 100644 (file)
--- a/README.md
+++ b/README.md
@@ -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
 Plugin 'godlygeek/tabular'
 
 ```vim
 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,21 @@ If you use [Pathogen](https://github.com/tpope/vim-pathogen), do this:
 
 ```sh
 cd ~/.vim/bundle
 
 ```sh
 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:
 
 ```sh
 ```
 
 To install without Pathogen using the Debian [vim-addon-manager](http://packages.qa.debian.org/v/vim-addon-manager.html), do this:
 
 ```sh
-git clone https://github.com/plasticboy/vim-markdown.git
+git clone https://github.com/preservim/vim-markdown.git
 cd vim-markdown
 sudo make install
 vim-addon-manager install markdown
 ```
 
 cd vim-markdown
 sudo make install
 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 using a package manager with semver support (like [lazy.nvim](https://github.com/folke/lazy.nvim)) make sure you are following the master branch (see https://github.com/preservim/vim-markdown/issues/616).
+
+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
 cd ~/.vim
 
 ```sh
 cd ~/.vim
@@ -65,8 +68,10 @@ The following commands are useful to open and close folds:
 - `zR`: opens all folds
 - `zm`: increases fold level throughout the buffer
 - `zM`: folds everything all the way
 - `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
+- `za`: toggle a fold your cursor is on
+- `zA`: toggle a fold your cursor is on recursively
+- `zo`: open a fold your cursor is on
+- `zO`: 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
 
 - `zc`: close a fold your cursor is on
 - `zC`: close a fold your cursor is on recursively
 
@@ -261,8 +266,6 @@ The following options control which syntax extensions will be turned on. They ar
 
     Highlight TOML front matter as used by [Hugo](https://gohugo.io/content/front-matter/).
 
 
     Highlight TOML front matter as used by [Hugo](https://gohugo.io/content/front-matter/).
 
-    TOML syntax highlight requires [vim-toml](https://github.com/cespare/vim-toml).
-
         let g:vim_markdown_toml_frontmatter = 1
 
 #### JSON Front Matter
         let g:vim_markdown_toml_frontmatter = 1
 
 #### JSON Front Matter
@@ -271,8 +274,6 @@ The following options control which syntax extensions will be turned on. They ar
 
     Highlight JSON front matter as used by [Hugo](https://gohugo.io/content/front-matter/).
 
 
     Highlight JSON front matter as used by [Hugo](https://gohugo.io/content/front-matter/).
 
-    JSON syntax highlight requires [vim-json](https://github.com/elzr/vim-json).
-
         let g:vim_markdown_json_frontmatter = 1
 
 #### Strikethrough
         let g:vim_markdown_json_frontmatter = 1
 
 #### Strikethrough
@@ -350,6 +351,27 @@ The following options control which syntax extensions will be turned on. They ar
 
         let g:vim_markdown_edit_url_in = 'tab'
 
 
         let g:vim_markdown_edit_url_in = 'tab'
 
+### Borderless tables
+
+-   `g:vim_markdown_borderless_table`
+
+    Add support for borderless tables, such as:
+    ```
+    header 1|header 2
+    --|--
+    data 1|data 2
+    ```
+    if set to `1`:
+
+        let g:vim_markdown_borderless_table = 1
+
+    the table would be formatted as usual:
+    ```
+    | header 1 | header 2 |
+    |----------|----------|
+    | data 1   | data 2   |
+    ```
+
 ## Mappings
 
 The following work on normal and visual modes:
 ## Mappings
 
 The following work on normal and visual modes:
@@ -370,19 +392,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.
 
 -   `]]`: go to next header. `<Plug>Markdown_MoveToNextHeader`
 
 
     The rules for the cursor position are the same as the `gx` command.
 
 -   `]]`: 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 previous sibling header if any. `<Plug>Markdown_MoveToPreviousSiblingHeader`
 
 
 -   `][`: 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`
+-   `]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`
 
@@ -433,11 +455,17 @@ The following requires `:filetype plugin on`.
 
 -   `:Tocv`: Same as `:Toc` for symmetry with `:Toch` and `:Tocv`.
 
 
 -   `:Tocv`: Same as `:Toc` for symmetry with `:Toch` and `:Tocv`.
 
+-   `:InsertToc`: Insert table of contents at the current line.
+
+    An optional argument can be used to specify how many levels of headers to display in the table of content, e.g., to display up to and including `h3`, use `:InsertToc 3`.
+
+-   `:InsertNToc`: Same as `:InsertToc`, but the format of `h2` headers in the table of contents is a numbered list, rather than a bulleted list.
+
 ## Credits
 
 The main contributors of vim-markdown are:
 
 ## Credits
 
 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.
 
index 8be6ff918be1c33aca7912f17a1384b86254cea7..390515ffbf7c629a03497010f42b9ca087441d18 100644 (file)
@@ -9,35 +9,41 @@
 
 function! s:is_mkdCode(lnum)
     let name = synIDattr(synID(a:lnum, 1, 0), 'name')
 
 function! s:is_mkdCode(lnum)
     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)
+        if (a:lnum == 1)
+            let b:fence_str = ''
+        endif
+
         let l1 = getline(a:lnum)
         "~~~~~ keep track of fenced code blocks ~~~~~
         "If we hit a code block fence
         let l1 = getline(a:lnum)
         "~~~~~ keep track of fenced code blocks ~~~~~
         "If we hit a code block fence
-        if l1 =~ '````*' || l1 =~ '\~\~\~\~*'
+        if l1 =~# '\v^[[:space:]>]*\v(`{3,}|\~{3,})\s*(\w+)?\s*$'
             " toggle the variable that says if we're in a code block
             if b:fenced_block == 0
                 let b:fenced_block = 1
             " toggle the variable that says if we're in a code block
             if b:fenced_block == 0
                 let b:fenced_block = 1
-            elseif b:fenced_block == 1
+                let b:fence_str = matchstr(l1, '\v(`{3,}|\~{3,})')
+            elseif b:fenced_block == 1 && matchstr(l1, '\v(`{3,}|\~{3,})') ==# b:fence_str
                 let b:fenced_block = 0
                 let b:fenced_block = 0
+                let b:fence_str = ''
             endif
         " else, if we're caring about front matter
             endif
         " else, if we're caring about front matter
-        elseif g:vim_markdown_frontmatter == 1
+        elseif get(g:, 'vim_markdown_frontmatter', 0) == 1
             " if we're in front matter and not on line 1
             if b:front_matter == 1 && a:lnum > 2
                 let l0 = getline(a:lnum-1)
                 " if the previous line fenced front matter
             " if we're in front matter and not on line 1
             if b:front_matter == 1 && a:lnum > 2
                 let l0 = getline(a:lnum-1)
                 " if the previous line fenced front matter
-                if l0 == '---'
+                if l0 ==# '---'
                     " we must not be in front matter
                     let b:front_matter = 0
                 endif
             " else, if we're on line one
             elseif a:lnum == 1
                 " if we hit a front matter fence
                     " we must not be in front matter
                     let b:front_matter = 0
                 endif
             " else, if we're on line one
             elseif a:lnum == 1
                 " if we hit a front matter fence
-                if l1 == '---'
+                if l1 ==# '---'
                     " we're in the front matter
                     let b:front_matter = 1
                 endif
                     " we're in the front matter
                     let b:front_matter = 1
                 endif
@@ -45,8 +51,8 @@ if get(g:, "vim_markdown_folding_style_pythonic", 0)
         endif
 
         " if we're in a code block or front matter
         endif
 
         " if we're in a code block or front matter
-        if b:fenced_block == 1 || b:front_matter == 1
-            if a:lnum == 1
+        if b:fenced_block ==# 1 || b:front_matter ==# 1
+            if a:lnum ==# 1
                 " fold any 'preamble'
                 return '>1'
             else
                 " fold any 'preamble'
                 return '>1'
             else
@@ -58,18 +64,19 @@ if get(g:, "vim_markdown_folding_style_pythonic", 0)
         let l2 = getline(a:lnum+1)
         " if the next line starts with two or more '='
         " and is not code
         let l2 = getline(a:lnum+1)
         " if the next line starts with two or more '='
         " 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)
             return '>0'
         " else, if the nex line starts with two or more '-'
             " next line is underlined (level 1)
             return '>0'
         " 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)
             return '>1'
         endif
 
         "if we're on a non-code line starting with a pound sign
             " next line is underlined (level 2)
             return '>1'
         endif
 
         "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
             " return '>'.(matchend(l1, '^#\+') - 1)
             " set the fold level to the number of hashes
             " set the fold level to the number of hashes -1
             " return '>'.(matchend(l1, '^#\+') - 1)
             " set the fold level to the number of hashes
@@ -87,36 +94,39 @@ if get(g:, "vim_markdown_folding_style_pythonic", 0)
     function! Foldtext_markdown()
         let line = getline(v:foldstart)
         let has_numbers = &number || &relativenumber
     function! Foldtext_markdown()
         let line = getline(v:foldstart)
         let has_numbers = &number || &relativenumber
-        let nucolwidth = &fdc + has_numbers * &numberwidth
+        let nucolwidth = &foldcolumn + has_numbers * &numberwidth
         let windowwidth = winwidth(0) - nucolwidth - 6
         let foldedlinecount = v:foldend - v:foldstart
         let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
         let line = substitute(line, '\%("""\|''''''\)', '', '')
         let fillcharcount = windowwidth - len(line) - len(foldedlinecount) + 1
         let windowwidth = winwidth(0) - nucolwidth - 6
         let foldedlinecount = v:foldend - v:foldstart
         let line = strpart(line, 0, windowwidth - 2 -len(foldedlinecount))
         let line = substitute(line, '\%("""\|''''''\)', '', '')
         let fillcharcount = windowwidth - len(line) - len(foldedlinecount) + 1
-        return line . ' ' . repeat("-", fillcharcount) . ' ' . foldedlinecount
+        return line . ' ' . repeat('-', fillcharcount) . ' ' . foldedlinecount
     endfunction
 else " vim_markdown_folding_style_pythonic == 0
     function! Foldexpr_markdown(lnum)
         if (a:lnum == 1)
             let l0 = ''
     endfunction
 else " vim_markdown_folding_style_pythonic == 0
     function! Foldexpr_markdown(lnum)
         if (a:lnum == 1)
             let l0 = ''
+            let b:fence_str = ''
         else
             let l0 = getline(a:lnum-1)
         endif
 
         " keep track of fenced code blocks
         else
             let l0 = getline(a:lnum-1)
         endif
 
         " keep track of fenced code blocks
-        if l0 =~ '````*' || l0 =~ '\~\~\~\~*'
+        if l0 =~# '\v^[[:space:]>]*\v(`{3,}|\~{3,})\s*(\w+)?\s*$'
             if b:fenced_block == 0
                 let b:fenced_block = 1
             if b:fenced_block == 0
                 let b:fenced_block = 1
-            elseif b:fenced_block == 1
+                let b:fence_str = matchstr(l0, '\v(`{3,}|\~{3,})')
+            elseif b:fenced_block == 1 && matchstr(l0, '\v(`{3,}|\~{3,})') ==# b:fence_str
                 let b:fenced_block = 0
                 let b:fenced_block = 0
+                let b:fence_str = ''
             endif
             endif
-        elseif g:vim_markdown_frontmatter == 1
+        elseif get(g:, 'vim_markdown_frontmatter', 0) == 1
             if b:front_matter == 1
             if b:front_matter == 1
-                if l0 == '---'
+                if l0 ==# '---'
                     let b:front_matter = 0
                 endif
             elseif a:lnum == 2
                     let b:front_matter = 0
                 endif
             elseif a:lnum == 2
-                if l0 == '---'
+                if l0 ==# '---'
                     let b:front_matter = 1
                 endif
             endif
                     let b:front_matter = 1
                 endif
             endif
@@ -128,10 +138,10 @@ else " vim_markdown_folding_style_pythonic == 0
         endif
 
         let l2 = getline(a:lnum+1)
         endif
 
         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)
             return '>1'
             " next line is underlined (level 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)
             if s:vim_markdown_folding_level >= 2
                 return '>1'
             " next line is underlined (level 2)
             if s:vim_markdown_folding_level >= 2
                 return '>1'
@@ -141,7 +151,7 @@ else " vim_markdown_folding_style_pythonic == 0
         endif
 
         let l1 = getline(a:lnum)
         endif
 
         let l1 = getline(a:lnum)
-        if l1 =~ '^#' && !s:is_mkdCode(a:lnum)
+        if l1 =~# '^#' && !s:is_mkdCode(a:lnum)
             " fold level according to option
             if s:vim_markdown_folding_level == 1 || matchend(l1, '^#\+') > s:vim_markdown_folding_level
                 if a:lnum == line('$')
             " fold level according to option
             if s:vim_markdown_folding_level == 1 || matchend(l1, '^#\+') > s:vim_markdown_folding_level
                 if a:lnum == line('$')
@@ -155,7 +165,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
             return '>'.matchend(l0, '^#\+')
         else
             " previous line starts with hashes
             return '>'.matchend(l0, '^#\+')
         else
@@ -168,12 +178,12 @@ endif
 
 let b:fenced_block = 0
 let b:front_matter = 0
 
 let b:fenced_block = 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_style_pythonic", 0)
-            if get(g:, "vim_markdown_override_foldtext", 1)
+    if !get(g:, 'vim_markdown_folding_disabled', 0)
+        if get(g:, 'vim_markdown_folding_style_pythonic', 0)
+            if get(g:, 'vim_markdown_override_foldtext', 1)
                 setlocal foldtext=Foldtext_markdown()
             endif
         endif
                 setlocal foldtext=Foldtext_markdown()
             endif
         endif
@@ -183,9 +193,9 @@ function! s:MarkdownSetupFolding()
 endfunction
 
 function! s:MarkdownSetupFoldLevel()
 endfunction
 
 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
 endfunction
 
     endif
 endfunction
 
index 4d73129328a98f6413d227559bd447a4050626a4..3e843571ab6dfc51c01b1752d74b28242aa9db8a 100644 (file)
@@ -55,7 +55,7 @@ Installation ~
 If you use Vundle [2], add the following lines to your '~/.vimrc':
 >
   Plugin 'godlygeek/tabular'
 If you use Vundle [2], add the following lines to your '~/.vimrc':
 >
   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:
 >
   cd ~/.vim/bundle
 If you use Pathogen [3], do this:
 >
   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
   sudo make install
   vim-addon-manager install markdown
   cd vim-markdown
   sudo make install
   vim-addon-manager install markdown
@@ -102,9 +102,13 @@ The following commands are useful to open and close folds:
                                                               *vim-markdown-zM*
 - 'zM': folds everything all the way
                                                               *vim-markdown-za*
                                                               *vim-markdown-zM*
 - 'zM': folds everything all the way
                                                               *vim-markdown-za*
-- 'za': open a fold your cursor is on
+- 'za': toggle a fold your cursor is on
                                                               *vim-markdown-zA*
                                                               *vim-markdown-zA*
-- 'zA': open a fold your cursor is on recursively
+- 'zA': toggle a fold your cursor is on recursively
+                                                              *vim-markdown-zo*
+- 'zo': open a fold your cursor is on
+                                                              *vim-markdown-zO*
+- 'zO': open a fold your cursor is on recursively
                                                               *vim-markdown-zc*
 - 'zc': close a fold your cursor is on
                                                               *vim-markdown-zC*
                                                               *vim-markdown-zc*
 - 'zc': close a fold your cursor is on
                                                               *vim-markdown-zC*
@@ -490,6 +494,30 @@ Change how to open new files ~
 >
   let g:vim_markdown_edit_url_in = 'tab'
 <
 >
   let g:vim_markdown_edit_url_in = 'tab'
 <
+-------------------------------------------------------------------------------
+                                    *vim-markdown-support-borderless-tables*
+Support borderless tables ~
+
+                                              *g:vim_markdown_borderless_table*
+- 'g:vim_markdown_borderless_table'
+
+  Add support for borderless tables, such as:
+>
+  header 1|header 2
+  --|--
+  data 1|data 2
+<
+  if set to 1:
+>
+  let g:vim_markdown_borderless_table = 1
+<
+  the table would be formatted as usual:
+>
+  | header 1 | header 2 |
+  |----------|----------|
+  | data 1   | data 2   |
+<
+
 ===============================================================================
                                                         *vim-markdown-mappings*
 Mappings ~
 ===============================================================================
                                                         *vim-markdown-mappings*
 Mappings ~
@@ -525,7 +553,7 @@ The following work on normal and visual modes:
 - ']]': go to next header. '<Plug>Markdown_MoveToNextHeader'
 
                                                               *vim-markdown-[[*
 - ']]': go to next header. '<Plug>Markdown_MoveToNextHeader'
 
                                                               *vim-markdown-[[*
-- '[[': go to previous header. Contrast with ']c'.
+- '[[': go to previous header. Contrast with ']h'.
   '<Plug>Markdown_MoveToPreviousHeader'
 
                                                               *vim-markdown-][*
   '<Plug>Markdown_MoveToPreviousHeader'
 
                                                               *vim-markdown-][*
@@ -536,8 +564,8 @@ The following work on normal and visual modes:
 - '[]': go to previous sibling header if any.
   '<Plug>Markdown_MoveToPreviousSiblingHeader'
 
 - '[]': go to previous sibling header if any.
   '<Plug>Markdown_MoveToPreviousSiblingHeader'
 
-                                                              *vim-markdown-]c*
-- ']c': go to Current header. '<Plug>Markdown_MoveToCurHeader'
+                                                              *vim-markdown-]h*
+- ']h': go to Current header. '<Plug>Markdown_MoveToCurHeader'
 
                                                               *vim-markdown-]u*
 - ']u': go to parent header (Up). '<Plug>Markdown_MoveToParentHeader'
 
                                                               *vim-markdown-]u*
 - ']u': go to parent header (Up). '<Plug>Markdown_MoveToParentHeader'
@@ -651,7 +679,7 @@ References ~
 [2] https://github.com/gmarik/vundle
 [3] https://github.com/tpope/vim-pathogen
 [4] http://packages.qa.debian.org/v/vim-addon-manager.html
 [2] https://github.com/gmarik/vundle
 [3] https://github.com/tpope/vim-pathogen
 [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
 [7] https://gohugo.io/content/front-matter/
 [8] https://github.com/cespare/vim-toml
 [6] https://github.com/klen/python-mode
 [7] https://gohugo.io/content/front-matter/
 [8] https://github.com/cespare/vim-toml
index 07682da4cd5da623e60725215198c89f5bda7411..e7c6f864ca91b68e69f26e0f4f39ff99c70db6d0 100644 (file)
@@ -3,6 +3,6 @@ if !has('patch-7.4.480')
     au! filetypedetect BufRead,BufNewFile *.md
 endif
 
     au! filetypedetect BufRead,BufNewFile *.md
 endif
 
-" markdown filetype file
-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
+" vint: -ProhibitAutocmdWithNoGroup
+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
index 200293e840bbc2bb1181900e727cd0270fe00407..33ed3cc96a1e59280caa4f2319048dd731f39bf4 100644 (file)
@@ -1,6 +1,6 @@
 "TODO print messages when on visual mode. I only see VISUAL, not the messages.
 
 "TODO print messages when on visual mode. I only see VISUAL, not the messages.
 
-" Function interface phylosophy:
+" Function interface philosophy:
 "
 " - functions take arbitrary line numbers as parameters.
 "    Current cursor line is only a suitable default parameter.
 "
 " - functions take arbitrary line numbers as parameters.
 "    Current cursor line is only a suitable default parameter.
@@ -56,7 +56,7 @@ let s:levelRegexpDict = {
     \ 6: '\v^######[^#]@='
 \ }
 
     \ 6: '\v^######[^#]@='
 \ }
 
-" Maches any header level of any type.
+" Matches 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.
 "
 " This could be deduced from `s:levelRegexpDict`, but it is more
 " efficient to have a single regexp for this.
@@ -94,7 +94,7 @@ endfunction
 "
 function! s:MoveToCurHeader()
     let l:lineNum = s:GetHeaderLineNum()
 "
 function! s:MoveToCurHeader()
     let l:lineNum = s:GetHeaderLineNum()
-    if l:lineNum != 0
+    if l:lineNum !=# 0
         call cursor(l:lineNum, 1)
     else
         echo 'outside any header'
         call cursor(l:lineNum, 1)
     else
         echo 'outside any header'
@@ -147,13 +147,68 @@ function! s:GetHeaderLevel(...)
         let l:line = a:1
     endif
     let l:linenum = s:GetHeaderLineNum(l:line)
         let l:line = a:1
     endif
     let l:linenum = s:GetHeaderLineNum(l:line)
-    if l:linenum != 0
+    if l:linenum !=# 0
         return s:GetLevelOfHeaderAtLine(l:linenum)
     else
         return 0
     endif
 endfunction
 
         return s:GetLevelOfHeaderAtLine(l:linenum)
     else
         return 0
     endif
 endfunction
 
+" Return list of headers and their levels.
+"
+function! s:GetHeaderList()
+    let l:bufnr = bufnr('%')
+    let l:fenced_block = 0
+    let l:front_matter = 0
+    let l:header_list = []
+    let l:vim_markdown_frontmatter = get(g:, 'vim_markdown_frontmatter', 0)
+    let l:fence_str = ''
+    for i in range(1, line('$'))
+        let l:lineraw = getline(i)
+        let l:l1 = getline(i+1)
+        let l:line = substitute(l:lineraw, '#', "\\\#", 'g')
+        " exclude lines in fenced code blocks
+        if l:line =~# '\v^[[:space:]>]*(`{3,}|\~{3,})\s*(\w+)?\s*$'
+            if l:fenced_block == 0
+                let l:fenced_block = 1
+                let l:fence_str = matchstr(l:line, '\v(`{3,}|\~{3,})')
+            elseif l:fenced_block == 1 && matchstr(l:line, '\v(`{3,}|\~{3,})') ==# l:fence_str
+                let l:fenced_block = 0
+                let l:fence_str = ''
+            endif
+        " exclude lines in frontmatters
+        elseif l:vim_markdown_frontmatter == 1
+            if l:front_matter == 1
+                if l:line ==# '---'
+                    let l:front_matter = 0
+                endif
+            elseif i == 1
+                if l:line ==# '---'
+                    let l:front_matter = 1
+                endif
+            endif
+        endif
+        " match line against header regex
+        if join(getline(i, i + 1), "\n") =~# s:headersRegexp && l:line =~# '^\S'
+            let l:is_header = 1
+        else
+            let l:is_header = 0
+        endif
+        if l:is_header ==# 1 && l:fenced_block ==# 0 && l:front_matter ==# 0
+            " remove hashes from atx headers
+            if match(l:line, '^#') > -1
+                let l:line = substitute(l:line, '\v^#*[ ]*', '', '')
+                let l:line = substitute(l:line, '\v[ ]*#*$', '', '')
+            endif
+            " append line to list
+            let l:level = s:GetHeaderLevel(i)
+            let l:item = {'level': l:level, 'text': l:line, 'lnum': i, 'bufnr': bufnr}
+            let l:header_list = l:header_list + [l:item]
+        endif
+    endfor
+    return l:header_list
+endfunction
+
 " Returns the level of the header at the given line.
 "
 " If there is no header at the given line, returns `0`.
 " Returns the level of the header at the given line.
 "
 " If there is no header at the given line, returns `0`.
@@ -175,6 +230,7 @@ endfunction
 function! s:MoveToParentHeader()
     let l:linenum = s:GetParentHeaderLineNumber()
     if l:linenum != 0
 function! s:MoveToParentHeader()
     let l:linenum = s:GetParentHeaderLineNumber()
     if l:linenum != 0
+        call setpos("''", getpos('.'))
         call cursor(l:linenum, 1)
     else
         echo 'no parent header'
         call cursor(l:linenum, 1)
     else
         echo 'no parent header'
@@ -303,65 +359,38 @@ function! s:Toc(...)
     endif
 
 
     endif
 
 
-    let l:bufnr = bufnr('%')
     let l:cursor_line = line('.')
     let l:cursor_header = 0
     let l:cursor_line = line('.')
     let l:cursor_header = 0
-    let l:fenced_block = 0
-    let l:front_matter = 0
-    let l:header_list = []
+    let l:header_list = s:GetHeaderList()
+    let l:indented_header_list = []
+    if len(l:header_list) == 0
+        echom 'Toc: No headers.'
+        return
+    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_frontmatter = get(g:, "vim_markdown_frontmatter", 0)
-    for i in range(1, line('$'))
-        let l:lineraw = getline(i)
-        let l:l1 = getline(i+1)
-        let l:line = substitute(l:lineraw, "#", "\\\#", "g")
-        if l:line =~ '````*' || l:line =~ '\~\~\~\~*'
-            if l:fenced_block == 0
-                let l:fenced_block = 1
-            elseif l:fenced_block == 1
-                let l:fenced_block = 0
-            endif
-        elseif l:vim_markdown_frontmatter == 1
-            if l:front_matter == 1
-                if l:line == '---'
-                    let l:front_matter = 0
-                endif
-            elseif i == 1
-                if l:line == '---'
-                    let l:front_matter = 1
-                endif
+    let l:vim_markdown_toc_autofit = get(g:, 'vim_markdown_toc_autofit', 0)
+    for h in l:header_list
+        " set header number of the cursor position
+        if l:cursor_header == 0
+            let l:header_line = h.lnum
+            if l:header_line == l:cursor_line
+                let l:cursor_header = index(l:header_list, h) + 1
+            elseif l:header_line > l:cursor_line
+                let l:cursor_header = index(l:header_list, h)
             endif
         endif
             endif
         endif
-        if l:line =~ '^#\+' || (l:l1 =~ '^=\+\s*$' || l:l1 =~ '^-\+\s*$') && l:line =~ '^\S'
-            let l:is_header = 1
-        else
-            let l:is_header = 0
-        endif
-        if l:is_header == 1 && l:fenced_block == 0 && l:front_matter == 0
-            " append line to location list
-            let l:item = {'lnum': i, 'text': l:line, 'valid': 1, 'bufnr': l:bufnr, 'col': 1}
-            let l:header_list = l:header_list + [l:item]
-            " set header number of the cursor position
-            if l:cursor_header == 0
-                if i == l:cursor_line
-                    let l:cursor_header = len(l:header_list)
-                elseif i > l:cursor_line
-                    let l:cursor_header = len(l:header_list) - 1
-                endif
-            endif
-            " keep track of the longest header size (heading level + title)
-            let l:total_len = stridx(l:line, ' ') + strdisplaywidth(l:line)
-            if l:total_len > l:header_max_len
-                let l:header_max_len = l:total_len
-            endif
+        " indent header based on level
+        let l:text = repeat('  ', h.level-1) . h.text
+        " keep track of the longest header size (heading level + title)
+        let l:total_len = strdisplaywidth(l:text)
+        if l:total_len > l:header_max_len
+            let l:header_max_len = l:total_len
         endif
         endif
+        " append indented line to list
+        let l:item = {'lnum': h.lnum, 'text': l:text, 'valid': 1, 'bufnr': h.bufnr, 'col': 1}
+        let l:indented_header_list = l:indented_header_list + [l:item]
     endfor
     endfor
-    call setloclist(0, l:header_list)
-    if len(l:header_list) == 0
-        echom "Toc: No headers."
-        return
-    endif
+    call setloclist(0, l:indented_header_list)
 
     if l:window_type ==# 'horizontal'
         lopen
 
     if l:window_type ==# 'horizontal'
         lopen
@@ -369,7 +398,8 @@ function! s:Toc(...)
         vertical lopen
         " auto-fit toc window when possible to shrink it
         if (&columns/2) > l:header_max_len && l:vim_markdown_toc_autofit == 1
         vertical lopen
         " auto-fit toc window when possible to shrink it
         if (&columns/2) > l:header_max_len && l:vim_markdown_toc_autofit == 1
-            execute 'vertical resize ' . (l:header_max_len + 1)
+            " header_max_len + 1 space for first header + 3 spaces for line numbers
+            execute 'vertical resize ' . (l:header_max_len + 1 + 3)
         else
             execute 'vertical resize ' . (&columns/2)
         endif
         else
             execute 'vertical resize ' . (&columns/2)
         endif
@@ -382,27 +412,84 @@ function! s:Toc(...)
     for i in range(1, line('$'))
         " this is the location-list data for the current item
         let d = getloclist(0)[i-1]
     for i in range(1, line('$'))
         " this is the location-list data for the current item
         let d = getloclist(0)[i-1]
-        " atx headers
-        if match(d.text, "^#") > -1
-            let l:level = len(matchstr(d.text, '#*', 'g'))-1
-            let d.text = substitute(d.text, '\v^#*[ ]*', '', '')
-            let d.text = substitute(d.text, '\v[ ]*#*$', '', '')
-        " setex headers
-        else
-            let l:next_line = getbufline(d.bufnr, d.lnum+1)
-            if match(l:next_line, "=") > -1
-                let l:level = 0
-            elseif match(l:next_line, "-") > -1
-                let l:level = 1
-            endif
-        endif
-        call setline(i, repeat('  ', l:level). d.text)
+        call setline(i, d.text)
     endfor
     setlocal nomodified
     setlocal nomodifiable
     execute 'normal! ' . l:cursor_header . 'G'
 endfunction
 
     endfor
     setlocal nomodified
     setlocal nomodifiable
     execute 'normal! ' . l:cursor_header . 'G'
 endfunction
 
+function! s:InsertToc(format, ...)
+    if a:0 > 0
+        if type(a:1) != type(0)
+            echohl WarningMsg
+            echomsg '[vim-markdown] Invalid argument, must be an integer >= 2.'
+            echohl None
+            return
+        endif
+        let l:max_level = a:1
+        if l:max_level < 2
+            echohl WarningMsg
+            echomsg '[vim-markdown] Maximum level cannot be smaller than 2.'
+            echohl None
+            return
+        endif
+    else
+        let l:max_level = 0
+    endif
+
+    let l:toc = []
+    let l:header_list = s:GetHeaderList()
+    if len(l:header_list) == 0
+        echom 'InsertToc: No headers.'
+        return
+    endif
+
+    if a:format ==# 'numbers'
+        let l:h2_count = 0
+        for header in l:header_list
+            if header.level == 2
+                let l:h2_count += 1
+            endif
+        endfor
+        let l:max_h2_number_len = strlen(string(l:h2_count))
+    else
+        let l:max_h2_number_len = 0
+    endif
+
+    let l:h2_count = 0
+    for header in l:header_list
+        let l:level = header.level
+        if l:level == 1
+            " skip level-1 headers
+            continue
+        elseif l:max_level != 0 && l:level > l:max_level
+            " skip unwanted levels
+            continue
+        elseif l:level == 2
+            " list of level-2 headers can be bullets or numbers
+            if a:format ==# 'bullets'
+                let l:indent = ''
+                let l:marker = '* '
+            else
+                let l:h2_count += 1
+                let l:number_len = strlen(string(l:h2_count))
+                let l:indent = repeat(' ', l:max_h2_number_len - l:number_len)
+                let l:marker = l:h2_count . '. '
+            endif
+        else
+            let l:indent = repeat(' ', l:max_h2_number_len + 2 * (l:level - 2))
+            let l:marker = '* '
+        endif
+        let l:text = '[' . header.text . ']'
+        let l:link = '(#' . substitute(tolower(header.text), '\v[ ]+', '-', 'g') . ')'
+        let l:line = l:indent . l:marker . l:text . l:link
+        let l:toc = l:toc + [l:line]
+    endfor
+
+    call append(line('.'), l:toc)
+endfunction
+
 " Convert Setex headers in range `line1 .. line2` to Atx.
 "
 " Return the number of conversions.
 " Convert Setex headers in range `line1 .. line2` to Atx.
 "
 " Return the number of conversions.
@@ -410,7 +497,9 @@ endfunction
 function! s:SetexToAtx(line1, line2)
     let l:originalNumLines = line('$')
     execute 'silent! ' . a:line1 . ',' . a:line2 . 'substitute/\v(.*\S.*)\n\=+$/# \1/'
 function! s:SetexToAtx(line1, line2)
     let l:originalNumLines = line('$')
     execute 'silent! ' . a:line1 . ',' . a:line2 . 'substitute/\v(.*\S.*)\n\=+$/# \1/'
-    execute 'silent! ' . a:line1 . ',' . a:line2 . 'substitute/\v(.*\S.*)\n-+$/## \1/'
+
+    let l:changed = l:originalNumLines - line('$')
+    execute 'silent! ' . a:line1 . ',' . (a:line2 - l:changed) . 'substitute/\v(.*\S.*)\n-+$/## \1'
     return l:originalNumLines - line('$')
 endfunction
 
     return l:originalNumLines - line('$')
 endfunction
 
@@ -452,6 +541,19 @@ endfunction
 "
 function! s:TableFormat()
     let l:pos = getpos('.')
 "
 function! s:TableFormat()
     let l:pos = getpos('.')
+
+    if get(g:, 'vim_markdown_borderless_table', 0)
+      " add `|` to the beginning of the line if it isn't present
+      normal! {
+      call search('|')
+      execute 'silent .,''}s/\v^(\s{0,})\|?([^\|])/\1|\2/e'
+
+      " add `|` to the end of the line if it isn't present
+      normal! {
+      call search('|')
+      execute 'silent .,''}s/\v([^\|])\|?(\s{0,})$/\1|\2/e'
+    endif
+
     normal! {
     " Search instead of `normal! j` because of the table at beginning of file edge case.
     call search('|')
     normal! {
     " Search instead of `normal! j` because of the table at beginning of file edge case.
     call search('|')
@@ -462,11 +564,11 @@ function! s:TableFormat()
     let l:flags = (&gdefault ? '' : 'g')
     execute 's/\(:\@<!-:\@!\|[^|:-]\)//e' . l:flags
     execute 's/--/-/e' . l:flags
     let l:flags = (&gdefault ? '' : 'g')
     execute 's/\(:\@<!-:\@!\|[^|:-]\)//e' . l:flags
     execute 's/--/-/e' . l:flags
-    Tabularize /|
+    Tabularize /\(\\\)\@<!|
     " Move colons for alignment to left or right side of the cell.
     execute 's/:\( \+\)|/\1:|/e' . l:flags
     execute 's/|\( \+\):/|:\1/e' . l:flags
     " 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/ /-/' . l:flags
+    execute 's/|:\?\zs[ -]\+\ze:\?|/\=repeat("-", len(submatch(0)))/' . l:flags
     call setpos('.', l:pos)
 endfunction
 
     call setpos('.', l:pos)
 endfunction
 
@@ -569,8 +671,13 @@ endfunction
 "
 function! s:OpenUrlUnderCursor()
     let l:url = s:Markdown_GetUrlForPosition(line('.'), col('.'))
 "
 function! s:OpenUrlUnderCursor()
     let l:url = s:Markdown_GetUrlForPosition(line('.'), col('.'))
-    if l:url != ''
-        call s:VersionAwareNetrwBrowseX(l:url)
+    if l:url !=# ''
+      if l:url =~? 'http[s]\?:\/\/[[:alnum:]%\/_#.-]*'
+        "Do nothing
+      else
+        let l:url = expand(expand('%:h').'/'.l:url)
+      endif
+      call s:VersionAwareNetrwBrowseX(l:url)
     else
         echomsg 'The cursor is not on a link.'
     endif
     else
         echomsg 'The cursor is not on a link.'
     endif
@@ -580,8 +687,24 @@ endfunction
 " script while this function is running. We must not replace it.
 if !exists('*s:EditUrlUnderCursor')
     function s:EditUrlUnderCursor()
 " script while this function is running. We must not replace it.
 if !exists('*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)
                 write
             endif
             if get(g:, 'vim_markdown_autowrite', 0)
                 write
             endif
@@ -591,14 +714,14 @@ if !exists('*s:EditUrlUnderCursor')
                 if len(l:parts) == 2
                     let [l:url, l:anchor] = parts
                     let l:anchorexpr = get(g:, 'vim_markdown_anchorexpr', '')
                 if len(l:parts) == 2
                     let [l:url, l:anchor] = parts
                     let l:anchorexpr = get(g:, 'vim_markdown_anchorexpr', '')
-                    if l:anchorexpr != ''
+                    if l:anchorexpr !=# ''
                         let l:anchor = eval(substitute(
                             \ l:anchorexpr, 'v:anchor',
                             \ escape('"'.l:anchor.'"', '"'), ''))
                     endif
                 endif
             endif
                         let l:anchor = eval(substitute(
                             \ l:anchorexpr, 'v:anchor',
                             \ escape('"'.l:anchor.'"', '"'), ''))
                     endif
                 endif
             endif
-            if l:url != ''
+            if l:url !=# ''
                 let l:ext = ''
                 if get(g:, 'vim_markdown_no_extensions_in_markdown', 0)
                     " use another file extension if preferred
                 let l:ext = ''
                 if get(g:, 'vim_markdown_no_extensions_in_markdown', 0)
                     " use another file extension if preferred
@@ -609,29 +732,13 @@ if !exists('*s:EditUrlUnderCursor')
                     endif
                 endif
                 let l:url = fnameescape(fnamemodify(expand('%:h').'/'.l:url.l:ext, ':.'))
                     endif
                 endif
                 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
             endif
                 execute l:editmethod l:url
             endif
-            if l:anchor != ''
-                silent! execute '/'.l:anchor
+            if l:anchor !=# ''
+                call search(l:anchor, 's')
             endif
         else
             endif
         else
-            echomsg 'The cursor is not on a link.'
+            execute l:editmethod . ' <cfile>'
         endif
     endfunction
 endif
         endif
     endfunction
 endif
@@ -666,7 +773,7 @@ if !get(g:, 'vim_markdown_no_default_key_mappings', 0)
     call <sid>MapNotHasmapto('][', 'Markdown_MoveToNextSiblingHeader')
     call <sid>MapNotHasmapto('[]', 'Markdown_MoveToPreviousSiblingHeader')
     call <sid>MapNotHasmapto(']u', 'Markdown_MoveToParentHeader')
     call <sid>MapNotHasmapto('][', 'Markdown_MoveToNextSiblingHeader')
     call <sid>MapNotHasmapto('[]', 'Markdown_MoveToPreviousSiblingHeader')
     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('ge', 'Markdown_EditUrlUnderCursor')
 endif
     call <sid>MapNotHasmapto('gx', 'Markdown_OpenUrlUnderCursor')
     call <sid>MapNotHasmapto('ge', 'Markdown_EditUrlUnderCursor')
 endif
@@ -674,18 +781,20 @@ endif
 command! -buffer -range=% HeaderDecrease call s:HeaderDecrease(<line1>, <line2>)
 command! -buffer -range=% HeaderIncrease call s:HeaderDecrease(<line1>, <line2>, 1)
 command! -buffer -range=% SetexToAtx call s:SetexToAtx(<line1>, <line2>)
 command! -buffer -range=% HeaderDecrease call s:HeaderDecrease(<line1>, <line2>)
 command! -buffer -range=% HeaderIncrease call s:HeaderDecrease(<line1>, <line2>, 1)
 command! -buffer -range=% SetexToAtx call s:SetexToAtx(<line1>, <line2>)
-command! -buffer TableFormat call s:TableFormat()
+command! -buffer -range TableFormat call s:TableFormat()
 command! -buffer Toc call s:Toc()
 command! -buffer Toch call s:Toc('horizontal')
 command! -buffer Tocv call s:Toc('vertical')
 command! -buffer Toct call s:Toc('tab')
 command! -buffer Toc call s:Toc()
 command! -buffer Toch call s:Toc('horizontal')
 command! -buffer Tocv call s:Toc('vertical')
 command! -buffer Toct call s:Toc('tab')
+command! -buffer -nargs=? InsertToc call s:InsertToc('bullets', <args>)
+command! -buffer -nargs=? InsertNToc call s:InsertToc('numbers', <args>)
 
 " Heavily based on vim-notes - http://peterodding.com/code/vim/notes/
 if exists('g:vim_markdown_fenced_languages')
     let s:filetype_dict = {}
     for s:filetype in g:vim_markdown_fenced_languages
 
 " Heavily based on vim-notes - http://peterodding.com/code/vim/notes/
 if exists('g:vim_markdown_fenced_languages')
     let s:filetype_dict = {}
     for s:filetype in g:vim_markdown_fenced_languages
-        let key = matchstr(s:filetype, "[^=]*")
-        let val = matchstr(s:filetype, "[^=]*$")
+        let key = matchstr(s:filetype, '[^=]*')
+        let val = matchstr(s:filetype, '[^=]*$')
         let s:filetype_dict[key] = val
     endfor
 else
         let s:filetype_dict[key] = val
     endfor
 else
@@ -702,8 +811,8 @@ function! s:MarkdownHighlightSources(force)
     " Look for code blocks in the current file
     let filetypes = {}
     for line in getline(1, '$')
     " Look for code blocks in the current file
     let filetypes = {}
     for line in getline(1, '$')
-        let ft = matchstr(line, '```\s*\zs[0-9A-Za-z_+-]*')
-        if !empty(ft) && ft !~ '^\d*$' | let filetypes[ft] = 1 | endif
+        let ft = matchstr(line, '\(`\{3,}\|\~\{3,}\)\s*\zs[0-9A-Za-z_+-]*\ze.*')
+        if !empty(ft) && ft !~# '^\d*$' | let filetypes[ft] = 1 | endif
     endfor
     if !exists('b:mkd_known_filetypes')
         let b:mkd_known_filetypes = {}
     endfor
     if !exists('b:mkd_known_filetypes')
         let b:mkd_known_filetypes = {}
@@ -726,15 +835,17 @@ function! s:MarkdownHighlightSources(force)
             else
                 let filetype = ft
             endif
             else
                 let filetype = ft
             endif
-            let group = 'mkdSnippet' . toupper(substitute(filetype, "[+-]", "_", "g"))
+            let group = 'mkdSnippet' . toupper(substitute(filetype, '[+-]', '_', 'g'))
             if !has_key(b:mkd_included_filetypes, filetype)
                 let include = s:SyntaxInclude(filetype)
                 let b:mkd_included_filetypes[filetype] = 1
             else
                 let include = '@' . toupper(filetype)
             endif
             if !has_key(b:mkd_included_filetypes, filetype)
                 let include = s:SyntaxInclude(filetype)
                 let b:mkd_included_filetypes[filetype] = 1
             else
                 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) && get(g:, 'vim_markdown_conceal_code_blocks', 1) ? ' concealends' : '')
+            let command_backtick = 'syntax region %s matchgroup=%s start="^\s*`\{3,}\s*%s.*$" matchgroup=%s end="\s*`\{3,}$" keepend contains=%s%s'
+            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)
 
             let b:mkd_known_filetypes[ft] = 1
             execute printf('syntax cluster mkdNonListItem add=%s', group)
 
             let b:mkd_known_filetypes[ft] = 1
@@ -766,15 +877,23 @@ function! s:SyntaxInclude(filetype)
     return grouplistname
 endfunction
 
     return grouplistname
 endfunction
 
+function! s:IsHighlightSourcesEnabledForBuffer()
+    " Enable for markdown buffers, and for liquid buffers with markdown format
+    return &filetype =~# 'markdown' || get(b:, 'liquid_subtype', '') =~# 'markdown'
+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 s:IsHighlightSourcesEnabledForBuffer() && line('$') > 1 && &syntax != 'OFF'
         call s:MarkdownHighlightSources(a:force)
     endif
 endfunction
 
 function! s:MarkdownClearSyntaxVariables()
         call s:MarkdownHighlightSources(a:force)
     endif
 endfunction
 
 function! s:MarkdownClearSyntaxVariables()
-    if &filetype =~ 'markdown'
+    if s:IsHighlightSourcesEnabledForBuffer()
         unlet! b:mkd_included_filetypes
     endif
 endfunction
         unlet! b:mkd_included_filetypes
     endif
 endfunction
index 2fa4cda8f7686fb9dd43a76286ea0e6088688080..a954c92346146cb7067a23440d827d0227eb40d7 100755 (executable)
@@ -1,4 +1,4 @@
-if exists("b:did_indent") | finish | endif
+if exists('b:did_indent') | finish | endif
 let b:did_indent = 1
 
 setlocal indentexpr=GetMarkdownIndent()
 let b:did_indent = 1
 
 setlocal indentexpr=GetMarkdownIndent()
@@ -8,7 +8,7 @@ setlocal autoindent
 " Automatically continue blockquote on line break
 setlocal formatoptions+=r
 setlocal comments=b:>
 " Automatically continue blockquote on line break
 setlocal formatoptions+=r
 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
     setlocal formatoptions-=c
     " Accept various markers as bullets
     " Do not automatically insert bullets when auto-wrapping with text-width
     setlocal formatoptions-=c
     " Accept various markers as bullets
@@ -16,24 +16,24 @@ if get(g:, "vim_markdown_auto_insert_bullets", 1)
 endif
 
 " Only define the function once
 endif
 
 " Only define the function once
-if exists("*GetMarkdownIndent") | finish | endif
+if exists('*GetMarkdownIndent') | finish | endif
 
 function! s:IsMkdCode(lnum)
     let name = synIDattr(synID(a:lnum, 1, 0), 'name')
 
 function! s:IsMkdCode(lnum)
     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
 
 function! s:IsLiStart(line)
 endfunction
 
 function! s:IsLiStart(line)
-    return a:line !~ '^ *\([*-]\)\%( *\1\)\{2}\%( \|\1\)*$' &&
-      \    a:line =~ '^\s*[*+-] \+'
+    return a:line !~# '^ *\([*-]\)\%( *\1\)\{2}\%( \|\1\)*$' &&
+      \    a:line =~# '^\s*[*+-] \+'
 endfunction
 
 function! s:IsHeaderLine(line)
 endfunction
 
 function! s:IsHeaderLine(line)
-    return a:line =~ '^\s*#'
+    return a:line =~# '^\s*#'
 endfunction
 
 function! s:IsBlankLine(line)
 endfunction
 
 function! s:IsBlankLine(line)
-    return a:line =~ '^$'
+    return a:line =~# '^$'
 endfunction
 
 function! s:PrevNonBlank(lnum)
 endfunction
 
 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))
         return 0
     endif
     if v:lnum > 2 && s:IsBlankLine(getline(v:lnum - 1)) && s:IsBlankLine(getline(v:lnum - 2))
         return 0
     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.
     let lnum = s:PrevNonBlank(v:lnum - 1)
     " At the start of the file use zero indent.
     " Find a non-blank line above the current line.
     let lnum = s:PrevNonBlank(v:lnum - 1)
     " At the start of the file use zero indent.
index c1a2b2cae04ee9390a049069b8ce4619cc60e33b..07ae0a8a4eefdbec784cf22a23b4bf8ad95ad7bd 100644 (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
 else
   runtime! syntax/html.vim
   so <sfile>:p:h/html.vim
 else
   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
 endif
 
 " don't use standard HiLink, it will not work with included syntax files
   finish
 endif
 
 " 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>
 else
   command! -nargs=+ HtmlHiLink hi def link <args>
   command! -nargs=+ HtmlHiLink hi link <args>
 else
   command! -nargs=+ HtmlHiLink hi def link <args>
@@ -70,10 +70,10 @@ execute 'syn region mkdLink matchgroup=mkdDelimiter  start="\\\@<!!\?\[\ze[^]\n]
 " Autolink without angle brackets.
 " mkd  inline links:      protocol     optional  user:pass@  sub/domain                    .com, .co.uk, etc         optional port   path/querystring/hash fragment
 "                         ------------ _____________________ ----------------------------- _________________________ ----------------- __
 " Autolink without angle brackets.
 " mkd  inline links:      protocol     optional  user:pass@  sub/domain                    .com, .co.uk, etc         optional port   path/querystring/hash fragment
 "                         ------------ _____________________ ----------------------------- _________________________ ----------------- __
-syn match   mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z0-9][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*/
+syn match   mkdInlineURL /https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z0-9][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?[^] \t]*/
 
 " Autolink with parenthesis.
 
 " Autolink with parenthesis.
-syn region  mkdInlineURL matchgroup=mkdDelimiter start="(\(https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z0-9][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?\S*)\)\@=" end=")"
+syn region  mkdInlineURL matchgroup=mkdDelimiter start="(\(https\?:\/\/\(\w\+\(:\w\+\)\?@\)\?\([A-Za-z0-9][-_0-9A-Za-z]*\.\)\{1,}\(\w\{2,}\.\?\)\{1,}\(:[0-9]\{1,5}\)\?[^] \t]*)\)\@=" end=")"
 
 " Autolink with angle brackets.
 syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@<!<\ze[a-z][a-z0-9,.-]\{1,22}:\/\/[^> ]*>" end=">"
 
 " Autolink with angle brackets.
 syn region mkdInlineURL matchgroup=mkdDelimiter start="\\\@<!<\ze[a-z][a-z0-9,.-]\{1,22}:\/\/[^> ]*>" end=">"
@@ -86,14 +86,14 @@ syn region mkdLinkTitle matchgroup=mkdDelimiter start=+'+     end=+'+  contained
 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+     end=+)+  contained
 
 "HTML headings
 syn region mkdLinkTitle matchgroup=mkdDelimiter start=+(+     end=+)+  contained
 
 "HTML headings
-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
+syn region htmlH1       matchgroup=mkdHeading     start="^\s*#"                   end="$" contains=@mkdHeadingContent,@Spell
+syn region htmlH2       matchgroup=mkdHeading     start="^\s*##"                  end="$" contains=@mkdHeadingContent,@Spell
+syn region htmlH3       matchgroup=mkdHeading     start="^\s*###"                 end="$" contains=@mkdHeadingContent,@Spell
+syn region htmlH4       matchgroup=mkdHeading     start="^\s*####"                end="$" contains=@mkdHeadingContent,@Spell
+syn region htmlH5       matchgroup=mkdHeading     start="^\s*#####"               end="$" contains=@mkdHeadingContent,@Spell
+syn region htmlH6       matchgroup=mkdHeading     start="^\s*######"              end="$" contains=@mkdHeadingContent,@Spell
+syn match  htmlH1       /^.\+\n=\+$/ contains=@mkdHeadingContent,@Spell
+syn match  htmlH2       /^.\+\n-\+$/ contains=@mkdHeadingContent,@Spell
 
 "define Markdown groups
 syn match  mkdLineBreak    /  \+$/
 
 "define Markdown groups
 syn match  mkdLineBreak    /  \+$/
@@ -103,14 +103,15 @@ execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/\(\([^\\]\|^\)\\\
 execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/^\s*\z(`\{3,}\)[^`]*$/                       end=/^\s*\z1`*\s*$/'            . s:concealcode
 execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/\(\([^\\]\|^\)\\\)\@<!\~\~/  end=/\(\([^\\]\|^\)\\\)\@<!\~\~/'               . s:concealcode
 execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/^\s*\z(\~\{3,}\)\s*[0-9A-Za-z_+-]*\s*$/      end=/^\s*\z1\~*\s*$/'           . s:concealcode
 execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/^\s*\z(`\{3,}\)[^`]*$/                       end=/^\s*\z1`*\s*$/'            . s:concealcode
 execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/\(\([^\\]\|^\)\\\)\@<!\~\~/  end=/\(\([^\\]\|^\)\\\)\@<!\~\~/'               . s:concealcode
 execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start=/^\s*\z(\~\{3,}\)\s*[0-9A-Za-z_+-]*\s*$/      end=/^\s*\z1\~*\s*$/'           . s:concealcode
-execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start="<pre[^>]*\\\@<!>"                            end="</pre>"'                   . s:concealcode
-execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start="<code[^>]*\\\@<!>"                           end="</code>"'                  . s:concealcode
+execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start="<pre\(\|\_s[^>]*\)\\\@<!>"                   end="</pre>"'                   . s:concealcode
+execute 'syn region mkdCode matchgroup=mkdCodeDelimiter start="<code\(\|\_s[^>]*\)\\\@<!>"                  end="</code>"'                  . 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\)\+/
 syn match  mkdCode         /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ contained
 syn region mkdFootnote     start="\[^"                     end="\]"
 syn match  mkdCode         /^\s*\n\(\(\s\{8,}[^ ]\|\t\t\+[^\t]\).*\n\)\+/
 syn match  mkdCode         /\%^\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/
 syn match  mkdCode         /^\s*\n\(\(\s\{4,}[^ ]\|\t\+[^\t]\).*\n\)\+/ contained
-syn match  mkdListItem     /^\s*\%([-*+]\|\d\+\.\)\ze\s\+/ contained
-syn region mkdListItemLine start="^\s*\%([-*+]\|\d\+\.\)\s\+" end="$" oneline contains=@mkdNonListItem,mkdListItem,@Spell
+syn match  mkdListItem     /^\s*\%([-*+]\|\d\+\.\)\ze\s\+/ contained nextgroup=mkdListItemCheckbox
+syn match  mkdListItemCheckbox     /\[[xXoO ]\]\ze\s\+/ contained contains=mkdListItem
+syn region mkdListItemLine start="^\s*\%([-*+]\|\d\+\.\)\s\+" end="$" oneline contains=@mkdNonListItem,mkdListItem,mkdListItemCheckbox,@Spell
 syn region mkdNonListItemBlock start="\(\%^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@!\|\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!\)" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell
 syn match  mkdRule         /^\s*\*\s\{0,1}\*\s\{0,1}\*\(\*\|\s\)*$/
 syn match  mkdRule         /^\s*-\s\{0,1}-\s\{0,1}-\(-\|\s\)*$/
 syn region mkdNonListItemBlock start="\(\%^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@!\|\n\(\_^\_$\|\s\{4,}[^ ]\|\t+[^\t]\)\@!\)" end="^\(\s*\([-*+]\|\d\+\.\)\s\+\)\@=" contains=@mkdNonListItem,@Spell
 syn match  mkdRule         /^\s*\*\s\{0,1}\*\s\{0,1}\*\(\*\|\s\)*$/
 syn match  mkdRule         /^\s*-\s\{0,1}-\s\{0,1}-\(-\|\s\)*$/
@@ -155,30 +156,32 @@ if get(g:, 'vim_markdown_strikethrough', 0)
     HtmlHiLink mkdStrike        htmlStrike
 endif
 
     HtmlHiLink mkdStrike        htmlStrike
 endif
 
+syn cluster mkdHeadingContent contains=htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdLink,mkdInlineURL,mkdStrike,mkdCode
 syn cluster mkdNonListItem contains=@htmlTop,htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath,mkdStrike
 
 "highlighting for Markdown groups
 syn cluster mkdNonListItem contains=@htmlTop,htmlItalic,htmlBold,htmlBoldItalic,mkdFootnotes,mkdInlineURL,mkdLink,mkdLinkDef,mkdLineBreak,mkdBlockquote,mkdCode,mkdRule,htmlH1,htmlH2,htmlH3,htmlH4,htmlH5,htmlH6,mkdMath,mkdStrike
 
 "highlighting for Markdown groups
-HtmlHiLink mkdString        String
-HtmlHiLink mkdCode          String
-HtmlHiLink mkdCodeDelimiter String
-HtmlHiLink mkdCodeStart     String
-HtmlHiLink mkdCodeEnd       String
-HtmlHiLink mkdFootnote      Comment
-HtmlHiLink mkdBlockquote    Comment
-HtmlHiLink mkdListItem      Identifier
-HtmlHiLink mkdRule          Identifier
-HtmlHiLink mkdLineBreak     Visual
-HtmlHiLink mkdFootnotes     htmlLink
-HtmlHiLink mkdLink          htmlLink
-HtmlHiLink mkdURL           htmlString
-HtmlHiLink mkdInlineURL     htmlLink
-HtmlHiLink mkdID            Identifier
-HtmlHiLink mkdLinkDef       mkdID
-HtmlHiLink mkdLinkDefTarget mkdURL
-HtmlHiLink mkdLinkTitle     htmlString
-HtmlHiLink mkdDelimiter     Delimiter
-
-let b:current_syntax = "mkd"
+HtmlHiLink mkdString           String
+HtmlHiLink mkdCode             String
+HtmlHiLink mkdCodeDelimiter    String
+HtmlHiLink mkdCodeStart        String
+HtmlHiLink mkdCodeEnd          String
+HtmlHiLink mkdFootnote         Comment
+HtmlHiLink mkdBlockquote       Comment
+HtmlHiLink mkdListItem         Identifier
+HtmlHiLink mkdListItemCheckbox Identifier
+HtmlHiLink mkdRule             Identifier
+HtmlHiLink mkdLineBreak        Visual
+HtmlHiLink mkdFootnotes        htmlLink
+HtmlHiLink mkdLink             htmlLink
+HtmlHiLink mkdURL              htmlString
+HtmlHiLink mkdInlineURL        htmlLink
+HtmlHiLink mkdID               Identifier
+HtmlHiLink mkdLinkDef          mkdID
+HtmlHiLink mkdLinkDefTarget    mkdURL
+HtmlHiLink mkdLinkTitle        htmlString
+HtmlHiLink mkdDelimiter        Delimiter
+
+let b:current_syntax = 'mkd'
 
 delcommand HtmlHiLink
 " vim: ts=8
 
 delcommand HtmlHiLink
 " vim: ts=8
index 79c5400185d0b710a64fa8107a599a2916a63285..8d688f77e9cde2eb1f3a742dfbc105f620becc63 100644 (file)
@@ -2,6 +2,7 @@
 
 Before:
   source ../after/ftplugin/markdown.vim
 
 Before:
   source ../after/ftplugin/markdown.vim
+  setlocal foldtext=foldtext()
 
 After:
   setlocal foldexpr=0
 
 After:
   setlocal foldexpr=0
@@ -120,28 +121,28 @@ Execute (check TOC):
   let res = getloclist(0)
   let elem = res[0]
   AssertEqual elem.lnum, 1
   let res = getloclist(0)
   let elem = res[0]
   AssertEqual elem.lnum, 1
-  AssertEqual elem.text, 'chap 1'
+  AssertEqual elem.text, 'chap 1'
   let elem = res[1]
   AssertEqual elem.lnum, 15
   let elem = res[1]
   AssertEqual elem.lnum, 15
-  AssertEqual elem.text, '## chap 1.1'
+  AssertEqual elem.text, '  chap 1.1'
   let elem = res[2]
   AssertEqual elem.lnum, 25
   let elem = res[2]
   AssertEqual elem.lnum, 25
-  AssertEqual elem.text, '### chap 1.1.1'
+  AssertEqual elem.text, '    chap 1.1.1'
   let elem = res[3]
   AssertEqual elem.lnum, 30
   let elem = res[3]
   AssertEqual elem.lnum, 30
-  AssertEqual elem.text, 'chap 2'
+  AssertEqual elem.text, 'chap 2'
   let elem = res[4]
   AssertEqual elem.lnum, 34
   let elem = res[4]
   AssertEqual elem.lnum, 34
-  AssertEqual elem.text, '## chap 2.1'
+  AssertEqual elem.text, '  chap 2.1'
   let elem = res[5]
   AssertEqual elem.lnum, 41
   let elem = res[5]
   AssertEqual elem.lnum, 41
-  AssertEqual elem.text, 'chap 3'
+  AssertEqual elem.text, 'chap 3'
   let elem = res[6]
   AssertEqual elem.lnum, 45
   AssertEqual elem.text, 'chap 4'
   let elem = res[7]
   AssertEqual elem.lnum, 50
   let elem = res[6]
   AssertEqual elem.lnum, 45
   AssertEqual elem.text, 'chap 4'
   let elem = res[7]
   AssertEqual elem.lnum, 50
-  AssertEqual elem.text, 'chap 4.1'
+  AssertEqual elem.text, '  chap 4.1'
 
 Given markdown;
 ---
 
 Given markdown;
 ---
@@ -174,5 +175,5 @@ Execute (check Toc of yaml front matter):
   AssertEqual len(res), 1
   let elem = res[0]
   AssertEqual elem.lnum, 8
   AssertEqual len(res), 1
   let elem = res[0]
   AssertEqual elem.lnum, 8
-  AssertEqual elem.text, 'heading'
+  AssertEqual elem.text, '  heading'
   unlet g:vim_markdown_frontmatter
   unlet g:vim_markdown_frontmatter
diff --git a/test/header-decrease.vader b/test/header-decrease.vader
new file mode 100644 (file)
index 0000000..4fa58ef
--- /dev/null
@@ -0,0 +1,116 @@
+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
+=
+
+b
+-
+
+Execute (HeaderIncrease with setext headers):
+  :HeaderIncrease
+
+Expect (convert to atx headers):
+  ## a
+
+  ### b
+
+Given markdown;
+a
+-
+
+Execute (HeaderDecrease with setext headers):
+  :HeaderDecrease
+
+Expect (convert to atx headers):
+  # a
diff --git a/test/insert-toc.vader b/test/insert-toc.vader
new file mode 100644 (file)
index 0000000..b8d669b
--- /dev/null
@@ -0,0 +1,147 @@
+Given markdown;
+# a
+
+## Foo Level 2
+
+### Foo Level 3
+
+#### Foo Level 4
+
+Bar Level 2
+-----------
+
+### Bar Level 3
+
+Execute (InsertToc format):
+  :2
+  :call append('.', '')
+  :InsertToc
+
+Expect (format):
+  # a
+
+  * [Foo Level 2](#foo-level-2)
+    * [Foo Level 3](#foo-level-3)
+      * [Foo Level 4](#foo-level-4)
+  * [Bar Level 2](#bar-level-2)
+    * [Bar Level 3](#bar-level-3)
+
+  ## Foo Level 2
+
+  ### Foo Level 3
+
+  #### Foo Level 4
+
+  Bar Level 2
+  -----------
+
+  ### Bar Level 3
+
+Given markdown;
+# a
+
+## Foo Level 2
+
+### Foo Level 3
+
+#### Foo Level 4
+
+Bar Level 2
+-----------
+
+### Bar Level 3
+
+Execute (InsertToc only h2 headers):
+  :2
+  :call append('.', '')
+  :InsertToc 2
+
+Expect (only h2 headers):
+  # a
+
+  * [Foo Level 2](#foo-level-2)
+  * [Bar Level 2](#bar-level-2)
+
+  ## Foo Level 2
+
+  ### Foo Level 3
+
+  #### Foo Level 4
+
+  Bar Level 2
+  -----------
+
+  ### Bar Level 3
+
+Given markdown;
+# a
+
+## Foo Level 2
+
+### Foo Level 3
+
+#### Foo Level 4
+
+Bar Level 2
+-----------
+
+## Baz Level 2
+
+## Foobar Level 2
+
+## Foobaz Level 2
+
+## Barfoo Level 2
+
+## Barbaz Level 2
+
+## Bazfoo Level 2
+
+## Bazbar Level 2
+
+## Foobarbaz Level 2
+
+Execute (InsertNToc format, and up to h3 headers):
+  :2
+  :call append('.', '')
+  :InsertNToc 3
+
+Expect (format, and up to h3 headers):
+  # a
+
+   1. [Foo Level 2](#foo-level-2)
+      * [Foo Level 3](#foo-level-3)
+   2. [Bar Level 2](#bar-level-2)
+   3. [Baz Level 2](#baz-level-2)
+   4. [Foobar Level 2](#foobar-level-2)
+   5. [Foobaz Level 2](#foobaz-level-2)
+   6. [Barfoo Level 2](#barfoo-level-2)
+   7. [Barbaz Level 2](#barbaz-level-2)
+   8. [Bazfoo Level 2](#bazfoo-level-2)
+   9. [Bazbar Level 2](#bazbar-level-2)
+  10. [Foobarbaz Level 2](#foobarbaz-level-2)
+
+  ## Foo Level 2
+
+  ### Foo Level 3
+
+  #### Foo Level 4
+
+  Bar Level 2
+  -----------
+
+  ## Baz Level 2
+
+  ## Foobar Level 2
+
+  ## Foobaz Level 2
+
+  ## Barfoo Level 2
+
+  ## Barbaz Level 2
+
+  ## Bazfoo Level 2
+
+  ## Bazbar Level 2
+
+  ## Foobarbaz Level 2
index 7ecdfad188da56b79695f9cf04583ef8f2506aa7..57fe6190256518872b102045a75f32d34468b7d9 100644 (file)
@@ -146,8 +146,8 @@ Given markdown;
 
 b
 
 
 b
 
-Execute (]c):
+Execute (]h):
   normal! 3G
   AssertEqual line('.'), 3
   normal! 3G
   AssertEqual line('.'), 3
-  normal ]c
+  normal ]h
   AssertEqual line('.'), 1
   AssertEqual line('.'), 1
diff --git a/test/setextoatx.vader b/test/setextoatx.vader
new file mode 100644 (file)
index 0000000..a27938f
--- /dev/null
@@ -0,0 +1,48 @@
+Given markdown;
+# a
+
+a
+=
+
+## b
+
+b
+-
+
+Execute (SetexToAtx):
+  :SetexToAtx
+
+Expect (convert setex-style headings to atx):
+  # a
+
+  # a
+
+  ## b
+
+  ## b
+
+Given markdown;
+a
+=
+
+b
+=
+
+c
+-
+
+d
+-
+
+Execute (SetexToAtx with range):
+  :1,8SetexToAtx
+
+Expect (only convert setex headings in original range):
+  # a
+
+  # b
+
+  ## c
+
+  d
+  -
diff --git a/test/strikethrough.vader b/test/strikethrough.vader
new file mode 100644 (file)
index 0000000..4fe392a
--- /dev/null
@@ -0,0 +1,41 @@
+Before:
+  let g:vim_markdown_strikethrough = 1
+  syn off | syn on
+
+After:
+  unlet! g:vim_markdown_strikethrough
+
+Given markdown;
+a ~~b~~ c
+
+Execute (strikethrough):
+  AssertNotEqual SyntaxOf('a'), 'mkdStrike'
+  AssertEqual SyntaxOf('b'), 'mkdStrike'
+  AssertNotEqual SyntaxOf('c'), 'mkdStrike'
+
+Given markdown;
+# ~~h1~~
+## ~~h2~~
+### ~~h3~~
+#### ~~h4~~
+##### ~~h5~~
+###### ~~h6~~
+
+Execute (strikethrough in atx headings):
+  AssertEqual SyntaxOf('h1'), 'mkdStrike'
+  AssertEqual SyntaxOf('h2'), 'mkdStrike'
+  AssertEqual SyntaxOf('h3'), 'mkdStrike'
+  AssertEqual SyntaxOf('h4'), 'mkdStrike'
+  AssertEqual SyntaxOf('h5'), 'mkdStrike'
+  AssertEqual SyntaxOf('h6'), 'mkdStrike'
+
+Given markdown;
+~~h1~~
+=
+
+~~h2~~
+-
+
+Execute (strikethrough in setext headings):
+  AssertEqual SyntaxOf('h1'), 'mkdStrike'
+  AssertEqual SyntaxOf('h2'), 'mkdStrike'
index 33f5500e88716e4e6d7afac4232ca19817e9c5f3..9c89e3f61dcdc1190f6020f9577463c72dad4743 100644 (file)
@@ -31,7 +31,7 @@ end
 [a]( b
 "c" )
 
 [a]( b
 "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:
 
index 5ce94fc2ee99e2f24f9c2c8b4ac0bd6d6463231b..b111de0d347bbf422df65a06c1e76733c90e4086 100644 (file)
@@ -2,6 +2,7 @@ Before:
   unlet! b:mkd_known_filetypes
   unlet! b:mkd_included_filetypes
   unlet! g:vim_markdown_math
   unlet! b:mkd_known_filetypes
   unlet! b:mkd_included_filetypes
   unlet! g:vim_markdown_math
+  unlet! b:liquid_subtype
 
 Given markdown;
 a **b** c
 
 Given markdown;
 a **b** c
@@ -634,7 +635,8 @@ Given markdown;
 
 Execute (link with url title):
   AssertEqual SyntaxOf('https://domain.tld'), 'mkdInlineURL'
 
 Execute (link with url title):
   AssertEqual SyntaxOf('https://domain.tld'), 'mkdInlineURL'
-  AssertEqual SyntaxOf('https://domain.com'), 'mkdInlineURL'
+  AssertNotEqual SyntaxOf(']'), 'mkdInlineURL'
+  AssertEqual SyntaxOf('https://domain.com'), 'mkdURL'
   AssertNotEqual SyntaxOf('not_a_link'), 'mkdInlineURL'
 
 # Code Blocks
   AssertNotEqual SyntaxOf('not_a_link'), 'mkdInlineURL'
 
 # Code Blocks
@@ -738,12 +740,18 @@ def a
 end
 ```
 
 end
 ```
 
+```ruby {linenos=table,hl_lines=[8,"15-17"],linenostart=199}
+class b
+end
+```
+
 Execute (fenced code block syntax with a language specifier):
   let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'MarkdownRefreshSyntax')
   call b:func(0)
   AssertEqual SyntaxOf('include'), 'cInclude'
   AssertEqual SyntaxOf('code'), 'mkdSnippetCPP'
   AssertEqual SyntaxOf('def'), 'rubyDefine'
 Execute (fenced code block syntax with a language specifier):
   let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'MarkdownRefreshSyntax')
   call b:func(0)
   AssertEqual SyntaxOf('include'), 'cInclude'
   AssertEqual SyntaxOf('code'), 'mkdSnippetCPP'
   AssertEqual SyntaxOf('def'), 'rubyDefine'
+  AssertEqual SyntaxOf('class'), 'rubyClass'
 
 Given markdown;
 ``` c++
 
 Given markdown;
 ``` c++
@@ -848,6 +856,17 @@ a
 Execute (fenced code block with extended info strings):
   AssertEqual SyntaxOf('a'), 'mkdCode'
 
 Execute (fenced code block with extended info strings):
   AssertEqual SyntaxOf('a'), 'mkdCode'
 
+Given liquid;
+```vim
+let g:a = 1
+```
+
+Execute (fenced code block syntax in liquid file with markdown subtype):
+  let b:liquid_subtype = 'markdown'
+  let b:func = Markdown_GetFunc('vim-markdown/ftplugin/markdown.vim', 'MarkdownRefreshSyntax')
+  call b:func(0)
+  AssertEqual SyntaxOf('g:a'), 'vimVar'
+
 # Code Blocks in pre and code tag
 
 Given markdown;
 # Code Blocks in pre and code tag
 
 Given markdown;
@@ -957,12 +976,12 @@ $$ \frac{a}{b} $$
 Execute (math tex highlighting):
   let g:vim_markdown_math=0
   syn off | syn on
 Execute (math tex highlighting):
   let g:vim_markdown_math=0
   syn off | syn on
-  AssertNotEqual SyntaxOf('sqrt'), 'texStatement'
-  AssertNotEqual SyntaxOf('frac'), 'texStatement'
+  AssertNotEqual SyntaxOf('sqrt')[0:2], 'tex'
+  AssertNotEqual SyntaxOf('frac')[0:2], 'tex'
   let g:vim_markdown_math=1
   syn off | syn on
   let g:vim_markdown_math=1
   syn off | syn on
-  AssertEqual SyntaxOf('sqrt'), 'texStatement'
-  AssertEqual SyntaxOf('frac'), 'texStatement'
+  AssertEqual SyntaxOf('sqrt')[0:2], 'tex'
+  AssertEqual SyntaxOf('frac')[0:2], 'tex'
 
 Given markdown;
 $a b[$ c
 
 Given markdown;
 $a b[$ c
@@ -985,7 +1004,7 @@ Execute (math ends with $$):
   AssertNotEqual SyntaxOf('c')[0:2], 'tex'
 
 Given markdown;
   AssertNotEqual SyntaxOf('c')[0:2], 'tex'
 
 Given markdown;
-$(0 \le 1)$
+$(0 \leq 1)$
 
 Execute (math conceal in $):
   if has('conceal')
 
 Execute (math conceal in $):
   if has('conceal')
@@ -996,20 +1015,21 @@ Execute (math conceal in $):
     AssertEqual synconcealed(1, 2)[0], 0
     AssertEqual synconcealed(1, 3)[0], 0
     AssertEqual synconcealed(1, 4)[0], 0
     AssertEqual synconcealed(1, 2)[0], 0
     AssertEqual synconcealed(1, 3)[0], 0
     AssertEqual synconcealed(1, 4)[0], 0
-    AssertEqual synconcealed(1, 5)[0], 1, '\le'
+    AssertEqual synconcealed(1, 5)[0], 1, '\leq'
     AssertEqual synconcealed(1, 6)[0], 1
     AssertEqual synconcealed(1, 7)[0], 1
     AssertEqual synconcealed(1, 6)[0], 1
     AssertEqual synconcealed(1, 7)[0], 1
-    AssertEqual synconcealed(1, 8)[0], 0
+    AssertEqual synconcealed(1, 8)[0], 1
     AssertEqual synconcealed(1, 9)[0], 0
     AssertEqual synconcealed(1, 10)[0], 0
     AssertEqual synconcealed(1, 9)[0], 0
     AssertEqual synconcealed(1, 10)[0], 0
-    AssertEqual synconcealed(1, 11)[0], 1, '$'
+    AssertEqual synconcealed(1, 11)[0], 0
+    AssertEqual synconcealed(1, 12)[0], 1, '$'
     setlocal conceallevel=0
   endif
 
 Given markdown;
 $$
 \omega
     setlocal conceallevel=0
   endif
 
 Given markdown;
 $$
 \omega
-0 \le 1
+0 \leq 1
 $$
 
 Execute (math conceal in $$):
 $$
 
 Execute (math conceal in $$):
@@ -1020,8 +1040,8 @@ Execute (math conceal in $$):
     AssertEqual synconcealed(1, 1)[0], 1, '$$'
     AssertEqual synconcealed(2, 1)[0], 1, '\omega'
     AssertEqual synconcealed(3, 1)[0], 0, '0'
     AssertEqual synconcealed(1, 1)[0], 1, '$$'
     AssertEqual synconcealed(2, 1)[0], 1, '\omega'
     AssertEqual synconcealed(3, 1)[0], 0, '0'
-    AssertEqual synconcealed(3, 3)[0], 1, '\le'
-    AssertEqual synconcealed(3, 7)[0], 0, '1'
+    AssertEqual synconcealed(3, 3)[0], 1, '\leq'
+    AssertEqual synconcealed(3, 8)[0], 0, '1'
     AssertEqual synconcealed(4, 1)[0], 1, '$$'
     setlocal conceallevel=0
   endif
     AssertEqual synconcealed(4, 1)[0], 1, '$$'
     setlocal conceallevel=0
   endif
@@ -1282,3 +1302,227 @@ Execute (HTML tag in text):
   AssertEqual SyntaxOf('span'), 'htmlTagName'
   AssertEqual SyntaxOf('<span>'), 'htmlTag'
   AssertEqual SyntaxOf('</span>'), 'htmlEndTag'
   AssertEqual SyntaxOf('span'), 'htmlTagName'
   AssertEqual SyntaxOf('<span>'), 'htmlTag'
   AssertEqual SyntaxOf('</span>'), 'htmlEndTag'
+
+Given markdown;
+# _h1_
+
+## _h2_
+
+### _h3_
+
+#### _h4_
+
+##### _h5_
+
+###### _h6_
+
+Execute (underscore italic text in atx headings):
+  AssertEqual SyntaxOf('h1'), 'htmlItalic'
+  AssertEqual SyntaxOf('h2'), 'htmlItalic'
+  AssertEqual SyntaxOf('h3'), 'htmlItalic'
+  AssertEqual SyntaxOf('h4'), 'htmlItalic'
+  AssertEqual SyntaxOf('h5'), 'htmlItalic'
+  AssertEqual SyntaxOf('h6'), 'htmlItalic'
+
+Given markdown;
+# *h1*
+
+## *h2*
+
+### *h3*
+
+#### *h4*
+
+##### *h5*
+
+###### *h6*
+
+Execute (asterisk italic text in atx headings):
+  AssertEqual SyntaxOf('h1'), 'htmlItalic'
+  AssertEqual SyntaxOf('h2'), 'htmlItalic'
+  AssertEqual SyntaxOf('h3'), 'htmlItalic'
+  AssertEqual SyntaxOf('h4'), 'htmlItalic'
+  AssertEqual SyntaxOf('h5'), 'htmlItalic'
+  AssertEqual SyntaxOf('h6'), 'htmlItalic'
+
+Given markdown;
+_h1_
+=
+
+_h2_
+-
+
+Execute (underscore italic text in setext headings):
+  AssertEqual SyntaxOf('h1'), 'htmlItalic'
+  AssertEqual SyntaxOf('h2'), 'htmlItalic'
+
+Given markdown;
+*h1*
+=
+
+*h2*
+-
+
+Execute (asterisk italic text in setext headings):
+  AssertEqual SyntaxOf('h1'), 'htmlItalic'
+  AssertEqual SyntaxOf('h2'), 'htmlItalic'
+
+Given markdown;
+# __h1__
+
+## __h2__
+
+### __h3__
+
+#### __h4__
+
+##### __h5__
+
+###### __h6__
+
+Execute (underscore bold text in atx headings):
+  AssertEqual SyntaxOf('h1'), 'htmlBold'
+  AssertEqual SyntaxOf('h2'), 'htmlBold'
+  AssertEqual SyntaxOf('h3'), 'htmlBold'
+  AssertEqual SyntaxOf('h4'), 'htmlBold'
+  AssertEqual SyntaxOf('h5'), 'htmlBold'
+  AssertEqual SyntaxOf('h6'), 'htmlBold'
+
+Given markdown;
+# **h1**
+
+## **h2**
+
+### **h3**
+
+#### **h4**
+
+##### **h5**
+
+###### **h6**
+
+Execute (asterisk bold text in atx headings):
+  AssertEqual SyntaxOf('h1'), 'htmlBold'
+  AssertEqual SyntaxOf('h2'), 'htmlBold'
+  AssertEqual SyntaxOf('h3'), 'htmlBold'
+  AssertEqual SyntaxOf('h4'), 'htmlBold'
+  AssertEqual SyntaxOf('h5'), 'htmlBold'
+  AssertEqual SyntaxOf('h6'), 'htmlBold'
+
+Given markdown;
+__h1__
+=
+
+__h2__
+-
+
+Execute (underscore bold text in setext headings):
+  AssertEqual SyntaxOf('h1'), 'htmlBold'
+  AssertEqual SyntaxOf('h2'), 'htmlBold'
+
+Given markdown;
+**h1**
+=
+
+**h2**
+-
+
+Execute (asterisk bold text in setext headings):
+  AssertEqual SyntaxOf('h1'), 'htmlBold'
+  AssertEqual SyntaxOf('h2'), 'htmlBold'
+
+Given markdown;
+# ___h1___
+
+## ___h2___
+
+### ___h3___
+
+#### ___h4___
+
+##### ___h5___
+
+###### ___h6___
+
+Execute (underscore bold italic text in atx headings):
+  AssertEqual SyntaxOf('h1'), 'htmlBoldItalic'
+  AssertEqual SyntaxOf('h2'), 'htmlBoldItalic'
+  AssertEqual SyntaxOf('h3'), 'htmlBoldItalic'
+  AssertEqual SyntaxOf('h4'), 'htmlBoldItalic'
+  AssertEqual SyntaxOf('h5'), 'htmlBoldItalic'
+  AssertEqual SyntaxOf('h6'), 'htmlBoldItalic'
+
+Given markdown;
+# ***h1***
+
+## ***h2***
+
+### ***h3***
+
+#### ***h4***
+
+##### ***h5***
+
+###### ***h6***
+
+Execute (asterisk bold italic text in atx headings):
+  AssertEqual SyntaxOf('h1'), 'htmlBoldItalic'
+  AssertEqual SyntaxOf('h2'), 'htmlBoldItalic'
+  AssertEqual SyntaxOf('h3'), 'htmlBoldItalic'
+  AssertEqual SyntaxOf('h4'), 'htmlBoldItalic'
+  AssertEqual SyntaxOf('h5'), 'htmlBoldItalic'
+  AssertEqual SyntaxOf('h6'), 'htmlBoldItalic'
+
+Given markdown;
+___h1___
+=
+
+___h2___
+-
+
+Execute (underscore bold italic text in setext headings):
+  AssertEqual SyntaxOf('h1'), 'htmlBoldItalic'
+  AssertEqual SyntaxOf('h2'), 'htmlBoldItalic'
+
+Given markdown;
+***h1***
+=
+
+***h2***
+-
+
+Execute (asterisk bold italic text in setext headings):
+  AssertEqual SyntaxOf('h1'), 'htmlBoldItalic'
+  AssertEqual SyntaxOf('h2'), 'htmlBoldItalic'
+
+Given markdown;
+# [^h1]
+
+## [^h2]
+
+### [^h3]
+
+#### [^h4]
+
+##### [^h5]
+
+###### [^h6]
+
+Execute (footnotes in atx headings):
+  AssertEqual SyntaxOf('h1'), 'mkdFootnotes'
+  AssertEqual SyntaxOf('h2'), 'mkdFootnotes'
+  AssertEqual SyntaxOf('h3'), 'mkdFootnotes'
+  AssertEqual SyntaxOf('h4'), 'mkdFootnotes'
+  AssertEqual SyntaxOf('h5'), 'mkdFootnotes'
+  AssertEqual SyntaxOf('h6'), 'mkdFootnotes'
+
+Given markdown;
+[^h1]
+=
+
+[^h2]
+-
+
+Execute (footnotes in setext headings):
+  AssertEqual SyntaxOf('h1'), 'mkdFootnotes'
+  AssertEqual SyntaxOf('h2'), 'mkdFootnotes'
index 2fc06a394b70f4102341d1faa88aff9ab010680b..f7028cb0a81f840c50c0a080341af35980c207c4 100644 (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;
 | left |right|  center  ||
 | :- | --: |:---:|:|
 Given markdown;
 | left |right|  center  ||
 | :- | --: |:---:|:|
@@ -42,3 +55,31 @@ 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 |   |
+
+Given markdown (borderless table);
+   left |right|  center 
+   :- | --: |:---:
+   left |right|  center  
+
+Execute (format borderless table):
+  let g:vim_markdown_borderless_table = 1
+  TableFormat
+  unlet g:vim_markdown_borderless_table
+
+Expect (table with borders):
+     | left | right | center |
+     |:-----|------:|:------:|
+     | left | right | center |
index 638ab3f76be5ab9347e16d327099f2269e7c737f..84a85b09769a18988799e4a677c6f0dea52f44ae 100644 (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
-syntax on
+
+filetype plugin indent on
+syntax enable
 
 function! Markdown_GetScriptID(fname) abort
     let l:snlist = ''
 
 function! Markdown_GetScriptID(fname) abort
     let l:snlist = ''
@@ -24,6 +25,7 @@ function! Markdown_GetScriptID(fname) abort
         endif
     endfor
 endfunction
         endif
     endfor
 endfunction
+
 function! Markdown_GetFunc(fname, funcname) abort
     return function('<SNR>' . Markdown_GetScriptID(a:fname) . '_' . a:funcname)
 endfunction
 function! Markdown_GetFunc(fname, funcname) abort
     return function('<SNR>' . Markdown_GetScriptID(a:fname) . '_' . a:funcname)
 endfunction