Code auto formatting in code blocks

I have no idea if it is possible, but it would be great if there was an option to auto format the syntax in the code blocks. Something similar to what prettier does in Visual Code Studio.

Use case or problem

In many of my notes I’m just copy and pasting code already formatted by prettier but that format is lost in Obsidian.

Proposed solution

Integrate obsidian with prettier?

2 Likes
1 Like

This is something that I was looking for as well. My workaround is to open the md file in question with my code editor (Vim, in my case) and just paste it into the code block there.

Alternatively, you may also try this: GitHub - rposborne/prettier-markdown-codeblocks: Autoformat markdown code blocks.

1 Like

A post was merged into an existing topic: AI Powered Snippet Curation

Shift + Command (Ctrl) + V instead of Command (Ctrl) + V will help.

2 Likes

You hero! :slight_smile:

I had a similar issue, how to keep code block style consistent across a large amount of markdown files, and ended up writing a tool, mdsf, that allows you to run “ordinary” code formatters like Black, Rustfmt and (Plus 100+ more) on markdown files.

It can currently only be run as a CLI or using a VSCode extension, but I am working on an Obsidian plugin.