إضافة وحدة rpm إلى highlightjs؟

Apparently highlightjs, due to lack of core maintainers, is asking for new language support to be added via separate repositories. (See https://github.com/highlightjs/highlight.js/issues/2149).

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

إعجاب واحد (1)

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

3 إعجابات

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

إعجابَين (2)

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

5 إعجابات

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

3 إعجابات

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)

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/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)

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 theme-component, so the capabilities of it are still the original ones.

إعجاب واحد (1)

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)

@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)

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 إعجابات

Yep, works now. Thank you!

إعجاب واحد (1)

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