Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Meta

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Comments on Is there a workaround to highlight code blocks if the language doesn't have syntax highlight enabled?

Post

Is there a workaround to highlight code blocks if the language doesn't have syntax highlight enabled?

+2
−0

I've seen that recently two requests to add syntax highlight to some languages were deferred (this and this).

According to the status-deferred tag description: "the requested feature will not be implemented in the near future".

From that description, my understanding is that there's not a timeline defined, and perhaps no guarantee that this will be made at all.

While we wait/hope for it, what's the workaround for highlighting code blocks with those languages? I can think of two alternatives:

  • leave the post as is, and when/if highlight for that language is added, no change will be needed. IMO, it's bad because the code won't be highlighted until support for the language is added (which can possibly mean "forever").
  • change the code block to use some language that has syntax highlight enabled and is "close enough" to the block's original language. IMO, it's "good" because at least the code will have some highlight (not-so-accurate may be better than nothing). I'm not sure if this affects the site's "semantics", as the blocks will have a CSS class with the wrong language in its name (not to mention the need to revert those if highlight for the original language is added).

While there are few posts containing code with the languages involved, option 2 seems to be the best alternative (not ideal, but good enough considering the circumstances). But as the site grows, this has the possibility to become a burden — for example, a mass edit might be required to revert the workaround.

Is there another alternative? Another pros and cons to the above?

History
Why does this post require attention from curators or moderators?
You might want to add some details to your flag.
Why should this post be closed?

1 comment thread

You could try doing it manually, I suppose.... (3 comments)
You could try doing it manually, I suppose....
Moshi‭ wrote over 3 years ago · edited over 3 years ago

This is an absolutely terrible idea, but you could theoretically do it manually (or install highlight.js locally)

I.e.

1 Take your code

2 Add in the spans either manually or by running highlight.js locally

3 Copy paste the result

4 ???

5 Profit.

Moshi‭ wrote over 3 years ago · edited over 3 years ago

E.g. you could do (code taken from https://software.codidact.com/posts/283059/283196#answer-283196)

<pre><code><span class="hljs-keyword">import</span> std.stdio;

<span class="hljs-keyword">void</span> main(<span class="hljs-built_in">string</span>[] args) {
        <span class="hljs-built_in">string</span> greeting1 = <span class="hljs-string">"Good"</span>;
        writefln(<span class="hljs-string">"Length of string greeting1 is %d"</span>,greeting1.length);
        <span class="hljs-built_in">char</span>[] greeting2 = <span class="hljs-string">"morning"</span>.dup;
        writefln(<span class="hljs-string">"Length of string greeting2 is %d"</span>,greeting2.length);
}
</code></pre>
Moshi‭ wrote over 3 years ago

and that would show up as

import std.stdio;

void main(string[] args) {
        string greeting1 = "Good";
        writefln("Length of string greeting1 is %d",greeting1.length);
        char[] greeting2 = "morning".dup;
        writefln("Length of string greeting2 is %d",greeting2.length);
}