SilverBullet library that cleans up markdown in an opinionated (and SilverBullet optimized) way. It adds a Markdown: Prettify command (default Ctrl-Alt-p / Cmd-Alt-p) to clean up the current page (or selection) using an ordered pipeline of ParseTree-based rules.
See Prettify.md for a full description of the rules, configuration schema, and install instructions.
In SilverBullet, run Library: Install and paste the URL to Prettify.md in this repo.
npm install
npm run buildThis produces markdown-prettify.plug.js next to the source files, which the SilverBullet client will pick up automatically (watch the browser console, then run Plugs: Reload).
npm testThe suite covers individual rules, complete pipeline output and idempotence, and editor selection behavior. Integration tests use committed trees produced by SilverBullet 2.6.1's real markdown parser; CI does not need its internal parser sources.
To add parser-backed cases, edit tests/fixtures/cases.json with hand-checked input and expected output, then regenerate both sets of trees:
npm run fixtures -- /path/to/silverbullet-2.6.1-checkout
npm testThe checkout must have its dependencies installed. Fixture provenance: SilverBullet tag 2.6.1, commit 9f54b3a719dc986844dbed11547d56f7f42e9656. tests/fixtures/trees.json is generated; do not edit it by hand.
Rules share configuration types in config.ts and protected-tree traversal in tree.ts. Keep inline syntax nodes intact until final rendering so later rules can still recognize emphasis, links, tags, and table cells.
- In your SilverBullet space, create a namespace folder, e.g.
Library/zefhemel/. - Symlink this repo into it:
ln -s "$PWD" ~/myspace/Library/silverbulletmd/markdown-prettify
- Run
npm run buildwhenever you change source files; SilverBullet reloads the plug automatically (or runPlugs: Reloadto force).
MIT