Closed jfernandz closed 4 years ago
Have you considered to add a kind of option to produce the output file when you are saving with
:w
Not really. It should be easy to set up in your settings instead using autocommands.
or even a live preview similar to this one for markdown?
This one is interesting, but not as an option, it should be a separate plugin to manage all the complexity and external deps.
What you can have now is just a browser extension (asciidoctorjs?) that autoreloads after you have saved your file. The only big missing part from markdown link you provided is following the cursor/change.
Not really. It should be easy to set up in your settings instead using autocommands.
Could you provide me a clue on how to do that? Is it like a sort of macro? I guess I'd need a conditional structure to chain :w
and :Asciidoctor2HTML
if the saved file has an asciidoc extension like .adoc
or .asc
... but what about if the file is a .txt
?
Could you provide me a clue on how to do that?
augroup ON_ASCIIDOCTOR_SAVE | au!
au BufWritePost *.adoc :Asciidoctor2HTML
augroup end
If you want it to be silent and in background, consider installing vim-dispatch
and
augroup ON_ASCIIDOCTOR_SAVE | au!
au BufWritePost *.adoc :compiler asciidoctor2html | Make!
augroup end
but what about if the file is a
.txt
?
Well, if you are sure it could be translated with asciidoctor then add *.txt
augroup ON_ASCIIDOCTOR_SAVE | au!
au BufWritePost *.adoc,*.txt :compiler asciidoctor2html | Make!
augroup end
For a txt file you can try to analyze first line and if it is = Title
then do conversion:
func! ConvertAsciidoctorToHTML()
" Text file with asciidoctor contents?
if &filetype == 'text' && getline(1) =~ '^= .*$'
" text files have no asciidoctor commands
set filetype=asciidoctor
Asciidoctor2HTML
set filetype=text
elseif &filetype == 'asciidoctor'
Asciidoctor2HTML
endif
endfunc
augroup ON_ASCIIDOCTOR_SAVE | au!
au BufWritePost *.adoc,*.txt call ConvertAsciidoctorToHTML()
augroup end
I have added this info to readme, closing
This is only a suggestion, but ... Have you considered to add a kind of option to produce the output file when you are saving with
:w
or even a live preview similar to this one for markdown?