OFFERINGS

by Steve Dondley

⬅ Notes listing

Author's note: The note below is part of a digital garden. Therefore, it is likely incomplete, inaccurate or both. In other words, it's just like other information sources but perhaps to a higher degree. That said, it may still be worth exploring.

markdown_to_note perl script

   Updated:

Source code

markdown_to_note source code

What is it?

This is bit of perl “glue” script I wrote which is run whenever I save a note in my wiki. It is located in my bin path.

What does it do?

It converts an md file in my vimwiki directory to an md file in my jekyll site’s _notes directory

What triggers it?

Er, it’s a bit complicated. But here’s a rather cryptic explanation you can puzzle through:

The script gets run whenever a wiki note is updated in my ~/vimwiki/webnotes folder. It is triggered by an autocmd found in my vim configuration:

autocmd BufWritePost *.md call vimwiki#vars#set_wikilocal('custom_wiki2html_args', '', 0) | execute ':silent Vimwiki2HTML' | call vimwiki#vars#set_wikilocal('custom_wiki2html_args', '', 0) | execute ':redraw!'

When I want to generate all the files at once, which is necessary to get accurate bidirectional links, the script gets run for every file. I have a map in my vim configuration to trigger this process:

nnoremap <leader>wha :CvimwikiAll2HTML<cr>
command! CvimwikiAll2HTML call vimwiki#vars#set_wikilocal('custom_wiki2html_args', 'no_update', 0) | execute ':silent! VimwikiAll2HTML' | call vimwiki#vars#set_wikilocal('custom_wiki2html_args', 'hi', 0) | execute ':redraw!'

As you can see, it’s basically the same as the autocmd except it calls VimwikiAll2HTML instead of Vimwiki2HTML command for a single file. Since updating the markdown_to_note script, it is no longer necessary to run this command.

The map and autocmd does not tell the whole vim configuration story, however. The key to getting the markdown_to_note script to be called called is to set the custom_wiki2html key for for the wiki in g:vimwiki_list with something like this in your vimrc file:

let wiki_1                          = {}
let wiki_1.path                     = '~/vimwiki/webnotes/'
let wiki_1.ext                      = '.md'
let wiki_1.path_html                = '~/git_repos/sdondley.github.io/_notes/'
let wiki_1.auto_export              = 1
let wiki_1.syntax                   = 'markdown'
let wiki_1.custom_wiki2html         = '/Users/me/bin/markdown_to_note'
let wiki_1.custom_wiki2html_args    = ''
let g:vimwiki_list                  = [wiki_1]

Note the custom_wiki2html key. It tells vimwiki to the use the markdown_to_note script to generate the markdown files used by Jekyll.


Other notes linking here:

Diary entry for 2020-07-18

How This Site Works

Diary entry for 2020-07-22

Diary entry for 2020-07-13

Diary entry for 2020-07-14

Diary entry for 2020-07-20

Diary entry for 2020-07-21

Diary entry for 2020-07-23

Perl


View the edit history