Format Markdown files with dprint on hotkey

Disclaimer

Is this project open source? Yes
Is this project completely free? Yes
Is this project vibe-coded beyond the author’s ability to comprehend how it works? No


You can format Markdown files with dprint or any other formatter on hotkey, with Templater:

  1. In Templater settings, define the user function dprintFmt with the following content:
    dprint fmt --log-level warn "<% tp.file.path() %>"
    
  2. Create the Templater template templaters/dprint_fmt.md calling the user function:
    <% tp.user.dprintFmt({}) _%>
    
  3. In Templater settings, assign hotkey for templaters/dprint_fmt.md.

It works fine on my Windows and Linux.

If you know a simpler way, please let me know.

Note:
Sometimes Obsidian seems to take few seconds to reflect modifications to the file, so you may see unexpected results when you run this immediately after a modification. If you want to avoid this, you can combine it with Linter’s on-save custom command. See: Templater Action on Save : r/ObsidianMD

References: