Pandoc.kak – preview your markdown files

Hi!

I wrote a little pandoc plugin since I use it a lot to convert markdown / markdown+latex files to pdf and liked to have a preview of my current document.

It"s my first plugin, it’s very rudimentary and the result of a lot of try and error.

Every suggestion for improvement or features is highly welcome.

3 Likes

I don’t create PDFs all that often myself, but this looks to be pretty useful for people who do. Well done!

One thing I noticed - in your code, there’s a couple of places where you try to remove the file’s extension by splitting the filename on the first . character. That’s a bit unreliable, as you can imagine a filename might have many . in it, and even the directory path might have . in it.

Instead, a better way is to use the shell’s “remove smallest suffix” pattern:

without_extension=${kak_buffile%.*}
  • ${kak_buffile} and $kak_buffile are the same - they just mean the kak_buffile environment variable
  • % means “remove smallest suffix”, and is one of the “remove {smallest,largest} {prefix,suffix}” string-slicing operators the shell has
  • .* is a shell pattern (glob) that matches the suffix we want to remove: the . of the extension and everything that follows it

For example:

$ x="a.b.c.d"
$ echo ${x%.*}
a.b.c
4 Likes

Thanks a lot for the feedback!
I’ll change it – it already felt kind of off when I wrote it…

awesome ! I use it already, I hacked it to use --pdf-engine=wkhtmltopdf and it work like a charm :slight_smile:

1 Like

Happy to hear that!

1 Like