The DSH ecosystem emphasizes that “everything is a plugin.” When writing technical reports or documentation, code blocks are often core content, but default Markdown syntax highlighting cannot directly produce vector or raster artifacts usable in Word, PPT, or PDF.
The scientificmaniac/dsh-code-highlight plugin registers a highlight_code tool. It uses a built-in lexer and renderer to convert code snippets into HTML, SVG, PNG, or LaTeX code with real syntax coloring.
Core Capabilities¶
This plugin mainly serves report-style documentation scenarios and provides the following capabilities:
- Language support: Built-in lexical definitions for 68 programming languages and configuration files. It can be specified by language name, alias, or file extension; if not specified, it is auto-detected.
- Multi-format output: Provides 10 output formats. These include HTML for direct embedding, SVG for vector illustrations, PNG for raster previews, and the
listingsandmintedenvironments for LaTeX documents. - Theme system: Built-in 7 themes, such as
github-darkandpaper-light(suitable for document layout). - Offline capable: The tokenizer and renderer are both built in, do not depend on runtime npm packages, and can be used offline.
- Document layout: Supports controlling output size through parameters such as
width_in(inches),dpi, andfont_size_pt, ensuring generated images fit the document column width exactly.
Installation and Enablement¶
Before installing, make sure the DSH Desktop application has been fully quit. The installation command is:
dsh plugin --profile desktop add github:scientificmaniac/dsh-code-highlight
After installation, the highlight_code tool will be active in all sessions in the current profile. If the plugin source code is modified, DSH must be restarted to load the new modules.
Typical Usage¶
When calling the highlight_code tool, you must provide the code (required) and format parameters. Other parameters are optional.
Basic Rendering¶
{
"action": "highlight_code",
"code": "const a = 1;",
"language": "javascript",
"format": "html",
"theme": "github-dark"
}
Generating Word/PPT Illustrations¶
Generate a vector image and save it directly to disk:
{
"action": "highlight_code",
"code": "print('Hello')",
"language": "python",
"format": "svg",
"theme": "paper-light",
"width_in": 6.3,
"output_file": "./code_snippet.svg"
}
Generating Raster Bitmaps for PDF¶
{
"action": "highlight_code",
"code": "package main",
"language": "go",
"format": "png",
"theme": "github-dark",
"dpi": 300,
"output_file": "./code_snippet.png"
}
LaTeX Output¶
Generate LaTeX source code that can be placed directly in a .tex file for compilation:
{
"action": "highlight_code",
"code": "return true;",
"language": "javascript",
"format": "latex",
"theme": "solarized-light"
}
Rasterization and Limitations¶
This plugin uses the Pillow library in Python 3 for bitmap rasterization. Its core mechanism is a fixed-step grid that maps ASCII characters to monospaced font cells and maps wide characters (such as Chinese) to monospaced font cells, ensuring the layout remains stable during scaling.
Known limitations:
- Single snippet at a time: Only one code snippet can be processed at a time.
- Width limit:
width_inonly limits the output width; it does not stretch a short snippet to fill a page. - HTML special content: In the generated HTML, content inside
<script>and<style>tags is not highlighted separately. - Markdown format:
format: markdownoutputs a colorless fenced code block; highlighting is completed by the downstream Markdown renderer. - Wide character calculation: Wide characters (such as Chinese) are calculated as two cells during rasterization.
- Source code changes: After modifying plugin source code, DSH must be restarted for the changes to take effect.
Summary¶
dsh-code-highlight is a syntax highlighting tool specifically designed for document generation scenarios. It addresses the problem of inconsistent code block styling and difficulty directly embedding code blocks into Office or LaTeX documents when AI agents generate reports. With built-in support for 68 languages and offline operation, it provides reliable syntax highlighting for the automated production of technical reports.