I'm trying to make a function in vimscript that converts markdown to html files using pandoc and putting that converted file in a specified directory.
Currently i am putting the file in a directory relative to the original markdown file's path using
expand('%:p:h') and appending a new directory
So if my markdown file is in
/home/user/notes/subjects/science the converted html file will be in
Since having an extra directory for my converted files in each and every subdirectory of my markdown notes can be inconvenient, i want to have a 'convertedfile_dir' in my outermost 'notes' directory, like this
So basically how do i manipulate the output of
expand() function, so that i can add
convertedfile_dir in the middle of the outputted path, like this:
converted file output
Here is the function that i currently use to convert markdown to html using pandoc to a directory (named _html) that resides in the same directory as the original markdown file
function! ConvertHTMLPandoc() let realfile = expand('%:p') let filedir = expand('%:p:h') . '/_html/' let file = expand('%:t:r') let convertedfile = filedir . file . '.html' redraw echo 'deleting old file '. convertedfile execute "!rm -f " . convertedfile echo 'converting to html' execute "!pandoc " . realfile . " -o " . convertedfile . " --template=uikit.html --toc" endfunction
Making the 'convertedfile_dir' to have the exact same directory structure as my main notes directory is really important since i'm going to be working with images that are going to be placed in a directory of it's own in the main 'notes' directory, so that the images can still be loaded in the converted file. Really trying to write only once, and never have to re-edit the files after it is converted. (especially messed up paths).
Thank you in advance for helping me.