Overview
repo2pdf uses highlight.js to automatically detect and highlight code syntax in your PDFs. This feature makes code more readable by applying colors to keywords, strings, comments, and other language elements.How It Works
When syntax highlighting is enabled, repo2pdf:- Detects the language based on file extension
- Applies highlight.js to parse and tokenize the code
- Maps HTML classes to PDF color values
- Renders colored text in the final PDF
clone.ts:263-276:
Enabling Syntax Highlighting
When running repo2pdf, you’ll be prompted to select features:Color Mappings
repo2pdf uses a carefully selected color palette optimized for readability in PDF format. The colors are mapped from highlight.js token types to specific hex values.Complete Color Reference
Complete Color Reference
Here are all the syntax element colors used by repo2pdf (from
syntax.ts:8-41):| Token Type | Color | Hex Value | Use Case |
|---|---|---|---|
| comment | SlateGray | #708090 | Code comments |
| punctuation | DarkSlateGray | #2F4F4F | Brackets, semicolons |
| tag | Teal | #008080 | HTML/XML tags |
| attribute | SeaGreen | #2E8B57 | HTML attributes |
| doctag | SeaGreen | #2E8B57 | Documentation tags |
| keyword | Navy | #000080 | Language keywords |
| meta | SteelBlue | #4682B4 | Meta information |
| name | DarkOliveGreen | #556B2F | Function/class names |
| selector-tag | DarkCyan | #008B8B | CSS selectors |
| deletion | DarkRed | #8B0000 | Deleted code |
| number | OrangeRed | #FF4500 | Numeric literals |
| quote | SlateBlue | #6A5ACD | Quoted text |
| selector-class | DarkSlateBlue | #483D8B | CSS class selectors |
| selector-id | DarkViolet | #9400D3 | CSS ID selectors |
| string | DarkGreen | #006400 | String literals |
| template-tag | LightSlateGray | #778899 | Template tags |
| type | DimGray | #696969 | Type annotations |
| section | LightSeaGreen | #20B2AA | Section headings |
| title | MediumPurple | #9370DB | Titles |
| link | BlueViolet | #8A2BE2 | Links |
| operator | Brown | #A52A2A | Operators (+, -, etc) |
| regexp | FireBrick | #B22222 | Regular expressions |
| selector-attr | CadetBlue | #5F9EA0 | Attribute selectors |
| selector-pseudo | Chartreuse | #7FFF00 | Pseudo selectors |
| symbol | Crimson | #DC143C | Symbols |
| template-variable | DarkMagenta | #8B008B | Template variables |
| variable | Gold | #FFD700 | Variables |
| literal | LimeGreen | #32CD32 | Literal values |
| addition | ForestGreen | #228B22 | Added code |
| built_in | GreenYellow | #ADFF2F | Built-in functions |
| bullet | LawnGreen | #7CFC00 | List bullets |
| code | Gray | #7F8C8D | Inline code |
Supported Languages
repo2pdf supports all languages recognized by highlight.js, including:JavaScript/TypeScript
.js, .jsx, .ts, .tsx
Python
.py, .pyw
Java/Kotlin
.java, .kt, .kts
C/C++
.c, .h, .cpp, .hpp
Ruby
.rb, .rake
Go
.go
Rust
.rs
PHP
.php
Swift
.swift
If a language is not recognized, repo2pdf will fall back to plaintext rendering without colors.
HTML to PDF Conversion
The conversion process works by:- Parsing HTML output from highlight.js
- Extracting class names (e.g.,
hljs-keyword) - Looking up colors from the color map
- Applying colors to PDF text segments
syntax.ts:45-50: