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.
This commit is contained in:
Jesse Hathaway 2021-07-04 07:39:29 -05:00 committed by GitHub
parent e4ddd32c84
commit 36fcb01e05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 66 additions and 0 deletions

View File

@ -316,6 +316,11 @@ let s:default_registry = {
\ 'suggested_filetypes': ['reason'], \ 'suggested_filetypes': ['reason'],
\ 'description': 'Fix ReasonML files with refmt.', \ 'description': 'Fix ReasonML files with refmt.',
\ }, \ },
\ 'pandoc': {
\ 'function': 'ale#fixers#pandoc#Fix',
\ 'suggested_filetypes': ['markdown'],
\ 'description': 'Fix markdown files with pandoc.',
\ },
\ 'shfmt': { \ 'shfmt': {
\ 'function': 'ale#fixers#shfmt#Fix', \ 'function': 'ale#fixers#shfmt#Fix',
\ 'suggested_filetypes': ['sh'], \ 'suggested_filetypes': ['sh'],

View File

@ -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

View File

@ -33,6 +33,25 @@ g:ale_markdown_mdl_options *g:ale_markdown_mdl_options*
This variable can be set to pass additional options to mdl. This variable can be set to pass additional options to mdl.
===============================================================================
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* prettier *ale-markdown-prettier*

View File

@ -301,6 +301,7 @@ Notes:
* `languagetool`!! * `languagetool`!!
* `markdownlint`!! * `markdownlint`!!
* `mdl` * `mdl`
* `pandoc`
* `prettier` * `prettier`
* `proselint` * `proselint`
* `redpen` * `redpen`

View File

@ -2847,6 +2847,7 @@ documented in additional help files.
markdown................................|ale-markdown-options| markdown................................|ale-markdown-options|
markdownlint..........................|ale-markdown-markdownlint| markdownlint..........................|ale-markdown-markdownlint|
mdl...................................|ale-markdown-mdl| mdl...................................|ale-markdown-mdl|
pandoc................................|ale-markdown-pandoc|
prettier..............................|ale-markdown-prettier| prettier..............................|ale-markdown-prettier|
remark-lint...........................|ale-markdown-remark-lint| remark-lint...........................|ale-markdown-remark-lint|
textlint..............................|ale-markdown-textlint| textlint..............................|ale-markdown-textlint|

View File

@ -310,6 +310,7 @@ formatting.
* [languagetool](https://languagetool.org/) :floppy_disk: * [languagetool](https://languagetool.org/) :floppy_disk:
* [markdownlint](https://github.com/DavidAnson/markdownlint) :floppy_disk: * [markdownlint](https://github.com/DavidAnson/markdownlint) :floppy_disk:
* [mdl](https://github.com/mivok/markdownlint) * [mdl](https://github.com/mivok/markdownlint)
* [pandoc](https://pandoc.org)
* [prettier](https://github.com/prettier/prettier) * [prettier](https://github.com/prettier/prettier)
* [proselint](http://proselint.com/) * [proselint](http://proselint.com/)
* [redpen](http://redpen.cc/) * [redpen](http://redpen.cc/)

View File

@ -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(''))