deno
deno copied to clipboard
fmt is not compatible with some front matters in markdown files
The front matter std library supports different formats of frontmatters, but these formats are not recognized by fmt. For example, let's say I have the following markdown file with a TOML front matter:
+++
title = 'First page'
+++
Hello world
After running deno fmt, the file is changed to:
+++ title = 'First page' +++
Hello world
Now the front matter is no longer detected by the std library.
Fmt relies on the package dprint-plugin-markdown which in turn uses pulldown-cmark. Right now metadata tags are not yet supported, but the required changes are already created, source here. As per the project specs it would get supported in pulldown-cmark in version 0.10 while the latest release is 0.9.3 which is the one supported in dprint-plugin-markdown.
Just ran into this problem while building out a site using Lume and it looks like pulldown-cmark has released 0.10+ now https://github.com/pulldown-cmark/pulldown-cmark/releases
Until this resolved, I'm using Prettier via deno eval, in case anyone wants a stop gap:
deno eval 'import "npm:prettier@3/bin/prettier.cjs";' -- --parser markdown
Also related to formatting markdown files. Deno fmt cannot format file that have pandoc syntax also.
For example, formatting fails to happen in such cases which work fine with pandoc.
{ width=80% }
This works now in 1.46 https://dprint.dev/playground/#code/NQiwCgBcEtIGwKYAIC8SDkAxaAnAzpEgA4CGA5guhCMBBABIJxwD2SA7iznACZA/plugin/markdown