# Pandoc.kak – preview your markdown files

**URL:** <https://discuss.kakoune.com/t/pandoc-kak-preview-your-markdown-files/1394>\
**Category:** Plugins\
**Tags:** language, plugins\
**Created:** [November 25, 2020, 12:54pm UTC](https://discuss.kakoune.com/t/pandoc-kak-preview-your-markdown-files/1394 "2020-11-25T12:54:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![basbebe](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@basbebe](https://discuss.kakoune.com/u/basbebe)\
**Post date:** [November 25, 2020, 12:54pm UTC](https://discuss.kakoune.com/t/pandoc-kak-preview-your-markdown-files/1394/1 "2020-11-25T12:54:08Z")

</div>

Hi!

I wrote a little [pandoc](https://pandoc.org/index.html) 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.

> **[GitHub - basbebe/pandoc.kak: pandoc plugin for kakoune text editor](https://github.com/basbebe/pandoc.kak)**
>
> pandoc plugin for kakoune text editor. Contribute to basbebe/pandoc.kak development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![Screwtapello](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/screwtapello/32/12_2.png) [@Screwtapello](https://discuss.kakoune.com/u/Screwtapello)\
**Post date:** [November 25, 2020, 8:54pm UTC](https://discuss.kakoune.com/t/pandoc-kak-preview-your-markdown-files/1394/2 "2020-11-25T20:54:34Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![basbebe](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@basbebe](https://discuss.kakoune.com/u/basbebe)\
**Post date:** [November 26, 2020, 7:39am UTC](https://discuss.kakoune.com/t/pandoc-kak-preview-your-markdown-files/1394/3 "2020-11-26T07:39:54Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![scr](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/scr/32/486_2.png) [@scr](https://discuss.kakoune.com/u/scr)\
**Post date:** [November 26, 2020, 9:04pm UTC](https://discuss.kakoune.com/t/pandoc-kak-preview-your-markdown-files/1394/4 "2020-11-26T21:04:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![basbebe](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@basbebe](https://discuss.kakoune.com/u/basbebe)\
**Post date:** [November 26, 2020, 9:34pm UTC](https://discuss.kakoune.com/t/pandoc-kak-preview-your-markdown-files/1394/5 "2020-11-26T21:34:22Z")

</div>

Happy to hear that!

---

<div class="post-metadata">

**Author:** ![basbebe](https://discuss.kakoune.com/letter_avatar_proxy/v4/letter/b/8edcca/32.png) [@basbebe](https://discuss.kakoune.com/u/basbebe)\
**Post date:** [June 29, 2021, 2:45pm UTC](https://discuss.kakoune.com/t/pandoc-kak-preview-your-markdown-files/1394/6 "2021-06-29T14:45:10Z")

</div>

btw this is now a module and also brings latex highlighting and indenting to markdown files
