$ show timlrx/rehype-prism-plus
rehype-prism-plus is a rehype plugin that enhances code block syntax highlighting in HTML with line numbers and line highlighting capabilities. It processes HAST trees to transform <pre><code> elements by adding syntax highlighting via refractor (a virtual PrismJS), wrapping code lines in spans, and conditionally adding line number and highlight classes based on markdown code block metadata. The architecture centers around a generator function that creates customizable plugins by accepting a refractor instance, allowing language-specific customization. Key entry points include the default export (all languages), common.js (subset of languages), and generator.js (custom language sets). Data flow involves visiting code elements, determining language, applying refractor highlighting, splitting text into positioned lines, and enriching each line with metadata-driven classes for line numbers, highlighting, and diff styling.
The LLM identified 1 files worth highlighting for reuse:
The core plugin generator that creates a rehype unified plugin from a refractor instance. It implements sophisticated HAST tree traversal to process code blocks: extracts language from class names, applies refractor syntax highlighting, splits code into positioned lines, wraps each line in spans with conditional classes for line numbers (from meta or options), line highlighting (via {1,3-5} meta syntax), and diff styling (+/- prefixes). Demonstrates expertise in unified plugin architecture, text node positioning for accurate line mapping, and handling edge cases like diff languages and missing language fallbacks. Highly reusable as it depends only on unified ecosystem utilities and accepts any refractor configuration for custom language sets.