Generate syntax-highlighted PNG images from Markdown fenced code blocks in pure Node.js.
Built-in font fallback covers Latin code text and Simplified Chinese comments/strings.
The published package vendors the runtime fonts it needs. Font license notices are included in LICENSES/.
- Node.js 18+
npm installFrom npm:
npm install -g md-code-image-clinpm run buildnode dist/cli/index.js input.mdInstalled globally:
md-code-image input.mdOr in development:
npm run dev -- input.md--out <path>: output directory, default./output--theme <theme>: Shiki theme, defaultgithub-dark--line-numbers: render line numbers--window <mac|none>: window chrome style, defaultnone--background <solid|gradient|transparent>: outer background, defaultsolid--padding <number>: card padding, default24--radius <number>: card radius, default12--scale <1|2|3>: PNG export scale, default2--max-width <number>: maximum card width, default800
Each fenced code block is exported as a separate PNG:
output/
code-01-js.png
code-02-ts.png
code-03-bash.png
Unnamed or unsupported languages fall back to txt for filenames and plaintext highlighting for rendering.
npm testLocal manual publish:
npm test
npm run build
npm publishprepublishOnly already runs test and build automatically.
Automated publish:
- Every push or merge into
mainbumps the patch version automatically - The workflow commits the updated
package.jsonandpackage-lock.json - The same workflow tags the release as
v<version>and publishes to npm
- Project code:
MIT, seeLICENSE - Bundled fonts:
SIL Open Font License 1.1, seeLICENSES/