- TEST=latest
before_script: |
- cd ..
if [ "$TEST" = "package" ]; then
sudo apt-get -y update
sudo apt-get -y install vim
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 -
+ cd "$TRAVIS_BUILD_DIR"
fi
- git clone https://github.com/godlygeek/tabular
- git clone https://github.com/junegunn/vader.vim
script: |
- cd "$TRAVIS_BUILD_DIR"
- ./test/run-tests.sh
+ make test
cp -v after/ftplugin/markdown.vim ${ADDONS}/after/ftplugin/markdown.vim
mkdir -pv ${REGISTRY}
cp -v registry/markdown.yaml ${REGISTRY}/markdown.yaml
+
+test: build/tabular build/vader.vim
+ test/run-tests.sh
+.PHONY: test
+
+update: build/tabular build/vader.vim
+ cd build/tabular && git pull
+ cd build/vader.vim && git pull
+.PHONY: update
+
+build/tabular: | build
+ git clone https://github.com/godlygeek/tabular build/tabular
+
+build/vader.vim: | build
+ git clone https://github.com/junegunn/vader.vim build/vader.vim
+
+build:
+ mkdir build
"
" original version from Steve Losh's gist: https://gist.github.com/1038710
-func! Foldexpr_markdown(lnum)
- if (a:lnum == 1)
- let l0 = ''
- else
- let l0 = getline(a:lnum-1)
- endif
-
- let l1 = getline(a:lnum)
+func! s:is_mkdCode(lnum)
+ return synIDattr(synID(a:lnum, 1, 0), 'name') == 'mkdCode'
+endfunc
- let l2 = getline(a:lnum+1)
+func! s:effective_line(lnum)
+ let line = getline(a:lnum)
+ return (line !~ '^[=-#]' || s:is_mkdCode(a:lnum)) ? '' : line
+endfunc
+func! Foldexpr_markdown(lnum)
+ let l2 = s:effective_line(a:lnum+1)
if l2 =~ '^==\+\s*'
" next line is underlined (level 1)
return '>1'
elseif l2 =~ '^--\+\s*'
" next line is underlined (level 2)
return '>2'
- elseif l1 =~ '^#'
+ endif
+
+ let l1 = s:effective_line(a:lnum)
+ if l1 =~ '^#'
" don't include the section title in the fold
return '-1'
- elseif l0 =~ '^#'
+ endif
+
+ if (a:lnum == 1)
+ let l0 = ''
+ else
+ let l0 = s:effective_line(a:lnum-1)
+ endif
+ if l0 =~ '^#'
" current line starts with hashes
return '>'.matchend(l0, '^#\+')
else
-To run the tests, you must install [Vader](https://github.com/junegunn/vader.vim).
+You can run the tests using the Makefile from the top directory:
-Vader and other plugins must be installed in the same directory as this repository.
+ make test
-Run the tests with:
-
- ./run-tests.sh
+To run them manually please refer to the instructions/commands in the Makefile.
--- /dev/null
+Before:
+ source ../after/ftplugin/markdown.vim
+
+After:
+ setlocal foldexpr=0
+ setlocal foldmethod=manual
+
+Given markdown;
+# Title
+
+## Chapter 1
+
+```
+This is code block
+# This is just a comment
+```
+
+## Capter 2
+
+foobar
+
+Execute (fold level # in code block):
+ AssertEqual foldlevel(1), 0, '# Title'
+ AssertEqual foldlevel(3), 1, '## Chapter 1'
+ AssertEqual foldlevel(7), 2, '# This is just a comment'
+ AssertEqual foldlevel(8), 2, '```'
+ AssertEqual foldlevel(10), 1, '## Chapter 2'
+ AssertEqual foldlevel(12), 2, 'foobar'
+
+Given markdown;
+
+==+ Fold Level 1
+
+--+ Fold Level 2
+
+Execute (fold level ==+, --+):
+ AssertEqual foldlevel(2), 1, '==+'
+ AssertEqual foldlevel(4), 2, '--+'
#!/usr/bin/env bash
-cd "$( dirname "${BASH_SOURCE[0]}" )" && vim -Nu vimrc -c 'Vader! *' > /dev/null
+# Exit on error.
+set -e
+
+cd "$( dirname "${BASH_SOURCE[0]}" )"
+
+for dep in ../build/tabular ../build/vader.vim; do
+ if [[ ! -d $dep ]]; then
+ echo "Missing dependency: $dep"
+ echo "You may just want to use 'make test'."
+ exit 1
+ fi
+done
+
+vim -Nu vimrc -c 'Vader! *' > /dev/null
set nocompatible
set rtp+=../
-set rtp+=../../tabular/
-set rtp+=../../vader.vim/
+set rtp+=../build/tabular/
+set rtp+=../build/vader.vim/
filetype on
filetype plugin on
filetype indent on