summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Hathaway <jesse@mbuki-mvuki.org>2021-07-04 07:39:29 -0500
committerGitHub <noreply@github.com>2021-07-04 21:39:29 +0900
commit36fcb01e05979b410da1dcee10979b0f4e610eb6 (patch)
treedad3fad01d795f7017b357ff74ba7b4497eed678
parente4ddd32c840c405b12abe76fefc860062989e429 (diff)
downloadale-36fcb01e05979b410da1dcee10979b0f4e610eb6.zip
Add pandoc as a markdown fixer (#3641)
Utilize pandoc to fix markdown files, currently set to Github-Flavored Markdown, but that can be changed by setting, ale_markdown_pandoc_options.
-rw-r--r--autoload/ale/fix/registry.vim5
-rw-r--r--autoload/ale/fixers/pandoc.vim16
-rw-r--r--doc/ale-markdown.txt19
-rw-r--r--doc/ale-supported-languages-and-tools.txt1
-rw-r--r--doc/ale.txt1
-rw-r--r--supported-tools.md1
-rw-r--r--test/fixers/test_pandoc_fixer_callback.vader23
7 files changed, 66 insertions, 0 deletions
diff --git a/autoload/ale/fix/registry.vim b/autoload/ale/fix/registry.vim
index 5a138484..0d110c79 100644
--- a/autoload/ale/fix/registry.vim
+++ b/autoload/ale/fix/registry.vim
@@ -316,6 +316,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['reason'],
\ 'description': 'Fix ReasonML files with refmt.',
\ },
+\ 'pandoc': {
+\ 'function': 'ale#fixers#pandoc#Fix',
+\ 'suggested_filetypes': ['markdown'],
+\ 'description': 'Fix markdown files with pandoc.',
+\ },
\ 'shfmt': {
\ 'function': 'ale#fixers#shfmt#Fix',
\ 'suggested_filetypes': ['sh'],
diff --git a/autoload/ale/fixers/pandoc.vim b/autoload/ale/fixers/pandoc.vim
new file mode 100644
index 00000000..d704c8a2
--- /dev/null
+++ b/autoload/ale/fixers/pandoc.vim
@@ -0,0 +1,16 @@
+scriptencoding utf-8
+" Author: Jesse Hathaway <jesse@mbuki-mvuki.org>
+" Description: Fix markdown files with pandoc.
+
+call ale#Set('markdown_pandoc_executable', 'pandoc')
+call ale#Set('markdown_pandoc_options', '-f gfm -t gfm -s -')
+
+function! ale#fixers#pandoc#Fix(buffer) abort
+ let l:executable = ale#Var(a:buffer, 'markdown_pandoc_executable')
+ let l:options = ale#Var(a:buffer, 'markdown_pandoc_options')
+
+ return {
+ \ 'command': ale#Escape(l:executable)
+ \ . ' ' . l:options,
+ \}
+endfunction
diff --git a/doc/ale-markdown.txt b/doc/ale-markdown.txt
index 99848878..feb37fc9 100644
--- a/doc/ale-markdown.txt
+++ b/doc/ale-markdown.txt
@@ -34,6 +34,25 @@ g:ale_markdown_mdl_options *g:ale_markdown_mdl_options*
===============================================================================
+pandoc *ale-markdown-pandoc*
+
+g:ale_markdown_pandoc_executable *g:ale_markdown_pandoc_executable*
+ *b:ale_markdown_pandoc_executable*
+ Type: |String|
+ Default: `'pandoc'`
+
+ This variable can be set to specify where to find the pandoc executable
+
+
+g:ale_markdown_pandoc_options *g:ale_markdown_pandoc_options*
+ *b:ale_markdown_pandoc_options*
+ Type: |String|
+ Default: `'-f gfm -t gfm -s -'`
+
+ This variable can be set to change the default options passed to pandoc
+
+
+===============================================================================
prettier *ale-markdown-prettier*
See |ale-javascript-prettier| for information about the available options.
diff --git a/doc/ale-supported-languages-and-tools.txt b/doc/ale-supported-languages-and-tools.txt
index 71fb64b8..36399178 100644
--- a/doc/ale-supported-languages-and-tools.txt
+++ b/doc/ale-supported-languages-and-tools.txt
@@ -301,6 +301,7 @@ Notes:
* `languagetool`!!
* `markdownlint`!!
* `mdl`
+ * `pandoc`
* `prettier`
* `proselint`
* `redpen`
diff --git a/doc/ale.txt b/doc/ale.txt
index 6c6a363e..5d2ff444 100644
--- a/doc/ale.txt
+++ b/doc/ale.txt
@@ -2847,6 +2847,7 @@ documented in additional help files.
markdown................................|ale-markdown-options|
markdownlint..........................|ale-markdown-markdownlint|
mdl...................................|ale-markdown-mdl|
+ pandoc................................|ale-markdown-pandoc|
prettier..............................|ale-markdown-prettier|
remark-lint...........................|ale-markdown-remark-lint|
textlint..............................|ale-markdown-textlint|
diff --git a/supported-tools.md b/supported-tools.md
index 14c92dd9..b94a8084 100644
--- a/supported-tools.md
+++ b/supported-tools.md
@@ -310,6 +310,7 @@ formatting.
* [languagetool](https://languagetool.org/) :floppy_disk:
* [markdownlint](https://github.com/DavidAnson/markdownlint) :floppy_disk:
* [mdl](https://github.com/mivok/markdownlint)
+ * [pandoc](https://pandoc.org)
* [prettier](https://github.com/prettier/prettier)
* [proselint](http://proselint.com/)
* [redpen](http://redpen.cc/)
diff --git a/test/fixers/test_pandoc_fixer_callback.vader b/test/fixers/test_pandoc_fixer_callback.vader
new file mode 100644
index 00000000..a364ee56
--- /dev/null
+++ b/test/fixers/test_pandoc_fixer_callback.vader
@@ -0,0 +1,23 @@
+Before:
+ Save g:ale_markdown_pandoc_executable
+ Save g:ale_markdown_pandoc_options
+
+After:
+ Restore
+
+Execute(The pandoc callback should return 'pandoc' as default command):
+ setlocal noexpandtab
+ Assert
+ \ ale#fixers#pandoc#Fix(bufnr('')).command =~# '^' . ale#Escape('pandoc'),
+ \ "Default command name is expected to be 'pandoc'"
+
+Execute(The pandoc executable and options should be configurable):
+ let g:ale_markdown_pandoc_executable = 'foobar'
+ let g:ale_markdown_pandoc_options = '--some-option'
+
+ AssertEqual
+ \ {
+ \ 'command': ale#Escape('foobar')
+ \ . ' --some-option',
+ \ },
+ \ ale#fixers#pandoc#Fix(bufnr(''))