Add rpm module to highlightjs?

AI-generated summary

The discussion revolves around adding RPM specfile syntax highlighting to Discourse via Highlight.js. mattdm notes that Highlight.js now encourages external repositories for new languages and requests integration of highlightjs-rpm-specfile. Falco responds that Discourse supports this via theme components and quickly packages a solution: discourse-highlightjs-rpm. mattdm confirms it works, but notes some syntax elements like Name:, Release:, %if, and %endif aren’t highlighted as expected. After investigation, mattdm discovers the issue isn’t with the highlighter or theme component, but with missing CSS classes in Discourse core — specifically .hljs-type. david fixes this in a PR (#24827), adding the missing styles. mattdm confirms the fix works and thanks the team. The feature is now functional, with syntax highlighting dependent on the active theme’s styling.

Apparently highlightjs, due to lack of core maintainers, is asking for new language support to be added via separate repositories. (See Policy: Discuss extras repository for additional languages · Issue #2149 · highlightjs/highlight.js · GitHub).

One such separate repo is GitHub - highlightjs/highlightjs-rpm-specfile · GitHub, for highlighting the RPM specfile syntax. Could you please add that to Discourse? It would be hugely helpful for Fedora!

1 Like

We’ve been adding non default languages as Customization > Theme component, even added a dedicated API hook for this.

3 Likes

Okay, cool — is there an example I can crib from?

2 Likes

I packaged one quickly for you, can you try it out?

https://github.com/discourse/discourse-highlightjs-rpm

5 Likes

Thank you!!! And, yep — right after lunch. :slight_smile:

3 Likes

Yes, seems to work!

From what I can see, it seems to auto-detect and work. If I want

```rpm-specfile

to work, I seem to need to put rpm-specfile in the “highlighted languages” site setting. Is that correct?

Also, if I put rpm there, that also works. Is this expected, or is it one of those things where I want to happen is happening for the wrong reason? :slight_smile:

1 Like

Hmm, but it doesn’t seem to be complete… I’m getting bold for sections like %description and %prep, purple for macros like %{?dist}, and # comments get grey italics. So far so good.

But looking at discourse-highlightjs-rpm/javascripts/discourse/lib/rpm-highlightjs.js at main · discourse/discourse-highlightjs-rpm · GitHub, I would expect Name:, Release: etc, to be highlighted in some way too, as well as %if and %endif — but those aren’t.

1 Like

Are those comments directed to the Discourse integration or to the quality of the highlighter itself?

I only copy and pasted the definition from the link you provided in the OP into a Discourse-compatible Customization > Theme component, so the capabilities of it are still the original ones.

1 Like

I’m seeing those things in the code in your[1] repo, so I expect that they’d work, but they do not appear to be highlighted in DIscourse. I don’t know if that’s a problem with the highlighter module, the Discourse implementation of that, or the theme component.


  1. this is not meant to be a blame statement, like “it’s your repo”… just to be clear :slight_smile: ↩︎

(For the record have bookmarked this to check what should work when I get a chance.)

1 Like

@falco — I had some time to look at this. Using Firefox’s built-in inspector, I can see that it properly add spans with classes hljs-type, hljs-keyword, etc. But if I look over on the styles side, I see a .hljs but not .hljs-type — only .hljs-keyword and .hljs-comment (the ones that work) seem to be there.

Oh, and .hljs-string also works. But I see some of the others in css … any idea what’s going on?

FWIW, this still does not work. (Sad face emoji)

1 Like

Looks like core was missing styling for the .hljs-type class. I’ve cleaned things up in this PR.

Exact colours will depend on your theme, but here’s an example RPM file:

3 Likes

Yep, works now. Thank you!

1 Like

This topic was automatically closed after 3 days. New replies are no longer allowed.