Skip to content

Add support for highlighting code blocks using highlight.js.#54

Open
markcho wants to merge 1 commit intojfernandez:mainfrom
markcho:AddCodeHighlighting
Open

Add support for highlighting code blocks using highlight.js.#54
markcho wants to merge 1 commit intojfernandez:mainfrom
markcho:AddCodeHighlighting

Conversation

@markcho
Copy link
Copy Markdown

@markcho markcho commented Dec 18, 2025

Add support for highlighting code blocks using highlight.js.

Copy link
Copy Markdown
Owner

@jfernandez jfernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.

Copy link
Copy Markdown
Owner

@jfernandez jfernandez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition - syntax highlighting is one of the most useful things for agent-produced content. A few things to address before merging.

Comment thread templates/main.html
<link rel="stylesheet" id="hljs-theme" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/github.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/highlight.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/languages/scala.min.js"></script>
<script>
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The highlight.js core already includes ~40 common languages (Python, JS, Rust, Bash, etc.). This line loads only Scala, which seems like a personal addition. Remove it, or if there's a specific reason for it, add the languages agents commonly produce instead.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working in the data space, Scala is still quite common. That being said, I understand why you wouldn't want every language listed here.

How about a parameter that controls which languages are included? Something like: --highlightjs=scala,foo,bar if you want to include support for languages that are not in the main pack.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rendered HTML already contains class="language-scale" or whatever the language used. In the server-side logic, you can extract the language names from the HTML and then pass them to the template.

Then you can do something like this in the template:

<script src=".../highlight.min.js"></script>
{% for lang in languages %}
<script src=".../languages/{{ lang }}.min.js"></script>
{% endfor %}

Comment thread templates/main.html
{% endif %}

<!-- Highlight.js for syntax highlighting -->
<link rel="stylesheet" id="hljs-theme" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/github.min.css">
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mermaid is gated behind {% if mermaid_enabled %} so it only loads when the markdown actually contains diagrams. Consider doing the same here. The server already checks for class="language-mermaid" in the rendered HTML to set that flag; a similar check for any class="language- that isn't mermaid would let you conditionally load highlight.js only when code blocks are present.

Comment thread templates/main.html
const themeLink = document.getElementById('hljs-theme');
if (themeLink) {
themeLink.href = `https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.11.1/styles/${themeName}.min.css`;
}
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CDN base URL and version 11.11.1 appear in 4 places. Minor, but worth extracting to a variable to make future version bumps easier.

@jfernandez
Copy link
Copy Markdown
Owner

@markcho do you want to continue working on this PR? If not, I can take over too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants