Skip to content

Latest commit

 

History

History
34 lines (23 loc) · 1.9 KB

File metadata and controls

34 lines (23 loc) · 1.9 KB

Looking at the test files and HTML output, here's how Grip handles code block syntax highlighting:

When processing a markdown code block, Grip generates different HTML structures based on the language specification:

  1. For recognized languages, it generates a highlight div with language-specific class:
<div class="highlight highlight-source-python"><pre><span class="pl-en">print</span>(<span class="pl-s">'Hello!'</span>)</pre></div>
<div class="highlight highlight-source-js"><pre><span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'JavaScript!'</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
  1. For unmatched languages, it falls back to a simpler structure:
<pre lang="unmatched_language"><code>console.log('No matching language, but looks like JavaScript.');
</code></pre>

The key differences in handling are:

  1. Recognized languages:

    • Get wrapped in a div with highlight and highlight-source-{language} classes
    • Receive syntax-specific span elements with pl- prefixed classes for different code elements
    • Support proper coloring of syntax elements like strings, functions, and operators
  2. Unmatched languages:

    • Use a simpler pre and code structure
    • Include the unmatched language as a lang attribute
    • Don't receive any syntax-specific highlighting

This matches GitHub's own rendering behavior, ensuring that code blocks look the same whether viewed on GitHub or through Grip's local preview, while gracefully handling unsupported language specifications.

The syntax highlighting is particularly important for technical documentation, as it makes code examples more readable and helps distinguish different programming languages in the rendered output.