mirror of
https://github.com/dense-analysis/ale.git
synced 2026-07-29 19:26:46 +08:00
5151 add mdformat support (#5152)
* fix(tests): fix ale_c_build_dir_names being unset in tests (#5109) - Use ale#Set() to set the ale_c_build_dir_names variable. - Ensure SetUpLinterTest() is called before any Save commands in tests. - Add c.vim to runtime before non-linter tests are executed. - Remove workarounds in c.vim. * feat: Load Prettier from cjs also * Add support for mdformat --------- Co-authored-by: w0rp <devw0rp@gmail.com>
This commit is contained in:
@@ -462,6 +462,11 @@ let s:default_registry = {
|
||||
\ 'suggested_filetypes': ['markdown'],
|
||||
\ 'description': 'Fix markdown files with pandoc.',
|
||||
\ },
|
||||
\ 'mdformat': {
|
||||
\ 'function': 'ale#fixers#mdformat#Fix',
|
||||
\ 'suggested_filetypes': ['markdown'],
|
||||
\ 'description': 'Fix Markdown files with mdformat.',
|
||||
\ },
|
||||
\ 'pymarkdown': {
|
||||
\ 'function': 'ale#fixers#pymarkdown#Fix',
|
||||
\ 'suggested_filetypes': ['markdown'],
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
" Author: Horacio
|
||||
" Description: Fix Markdown files with mdformat.
|
||||
|
||||
call ale#Set('markdown_mdformat_executable', 'mdformat')
|
||||
call ale#Set('markdown_mdformat_options', '')
|
||||
call ale#Set('markdown_mdformat_use_global', get(g:, 'ale_use_global_executables', 0))
|
||||
call ale#Set('markdown_mdformat_auto_pipenv', 0)
|
||||
call ale#Set('markdown_mdformat_auto_poetry', 0)
|
||||
call ale#Set('markdown_mdformat_auto_uv', 0)
|
||||
|
||||
function! ale#fixers#mdformat#GetExecutable(buffer) abort
|
||||
if (ale#Var(a:buffer, 'python_auto_pipenv') || ale#Var(a:buffer, 'markdown_mdformat_auto_pipenv'))
|
||||
\ && ale#python#PipenvPresent(a:buffer)
|
||||
return 'pipenv'
|
||||
endif
|
||||
|
||||
if (ale#Var(a:buffer, 'python_auto_poetry') || ale#Var(a:buffer, 'markdown_mdformat_auto_poetry'))
|
||||
\ && ale#python#PoetryPresent(a:buffer)
|
||||
return 'poetry'
|
||||
endif
|
||||
|
||||
if (ale#Var(a:buffer, 'python_auto_uv') || ale#Var(a:buffer, 'markdown_mdformat_auto_uv'))
|
||||
\ && ale#python#UvPresent(a:buffer)
|
||||
return 'uv'
|
||||
endif
|
||||
|
||||
return ale#python#FindExecutable(a:buffer, 'markdown_mdformat', ['mdformat'])
|
||||
endfunction
|
||||
|
||||
function! ale#fixers#mdformat#Fix(buffer) abort
|
||||
let l:executable = ale#fixers#mdformat#GetExecutable(a:buffer)
|
||||
let l:command = ale#Escape(l:executable)
|
||||
|
||||
if l:executable =~? '\(pipenv\|poetry\|uv\)$'
|
||||
let l:command .= ' run mdformat'
|
||||
endif
|
||||
|
||||
return {
|
||||
\ 'command': l:command
|
||||
\ . ale#Pad(ale#Var(a:buffer, 'markdown_mdformat_options'))
|
||||
\ . ' -',
|
||||
\}
|
||||
endfunction
|
||||
Reference in New Issue
Block a user