Ömer Kara31 downloadsFormat fenced code blocks in your notes using clang-format.
Obsidian plugin. Formats fenced code blocks in your notes using clang-format.
child_process, not available on mobile).clang-format installed and reachable (on PATH, or point directly at the binary in settings).Scans the active note for fenced code blocks tagged with one of the languages clang-format supports, pipes each block's contents to clang-format, and replaces the block in place with the formatted output. Other languages and nested fences are left untouched.
Recognized fence tags: c, h, cpp/c++/cc/cxx, hpp/hh/h++/hxx, objc/objective-c/m, objc++/objective-c++/mm, cs/csharp, java, js/javascript/jsx/mjs/cjs, ts/typescript/tsx, json/jsonc, proto/protobuf, textproto/textpb/txtpb, tablegen/td, verilog/v, systemverilog/sv.
Assign hotkeys to these in Settings -> Hotkeys.
Enabled by default. Formatting only runs on an explicit save (Ctrl/Cmd+S) — never while you're still typing — so it won't rewrite a block out from under you mid-edit. Failures still show a notice; successful auto-formats are silent. Toggle off in plugin settings if you don't want this.
This works by wrapping Obsidian's internal editor:save-file command (the same approach the Linter plugin uses), since there is no public "before save" hook. It's guarded so a future change to that internal shape just makes format-on-save a no-op rather than breaking saves, and the wrap is undone if you disable the plugin.
clang-format.File (use a .clang-format config) or a built-in style name (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU).File. Optional absolute path, or path relative to the vault root, to a specific config file. If set, that exact file is used for every note. If left blank, clang-format searches upward from the current note's folder for a .clang-format file.clang-format --version and, if a custom style file is set, checks it exists.Create <your-vault>/.obsidian/plugins/clang-format-code-blocks/ and copy main.js and manifest.json from a release (or from a local build, see below) into it. Then enable the plugin in Settings -> Community plugins.
npm install
cp deploy.config.example.json deploy.config.local.json # then edit vaultPluginDir
npm run dev # watch build
npm run build # production build
npm run deploy # copy main.js + manifest.json into vaultPluginDir
npm run build:vault # build + deploy in one step
main.ts is the source, bundled to main.js via esbuild. deploy.config.local.json is gitignored — it points npm run deploy at your own vault's plugin folder. Reload Obsidian (or disable/re-enable the plugin) after deploying.
MIT.