qpixel icon indicating copy to clipboard operation
qpixel copied to clipboard

Request for syntax highlighting for D

Open cellio opened this issue 3 years ago • 5 comments

https://software.codidact.com/posts/283059

I asked on Discord if this is a matter of configuration (i.e. support) or something that would have to change in QPixel, and somebody said the latter, pointing to this: https://github.com/codidact/qpixel/blob/c522daec251c5f67a97ca06a04dec9ffeef7f2d2/app/views/layouts/_head.html.erb#L36-L37 ("min" in particular, the comment said). I gather that the minified highlight.js doesn't include D but other versions do. I'm not sure what the cost of using a different version is.

I seem to recall we also had a request to support Cypher (I think that was the name); not sure if a change to support D would also cover that.

cellio avatar Aug 13 '21 03:08 cellio

We can absolutely do code highlights for a given coding language supported by the highlight scripts we use, with some big caveats.

  1. All or nothing approach currently - the highlight script blocks (that ask a user's browser to fetch a script) are an all or nothing approach. That is to say, if we flip the site setting to enable syntax highlighting on hypothetical Codidact site "A", all the highlight code would need to be downloaded and rendered for visitors to site "A" on every page visit. This means that if we add both the proposed languages to be enabled for syntax highlighting, every future site that may or may not need/want the proposed coding languages will require users to run the extra JS we implement and thus have slightly slower syntax renders/page loads, unless we implement further site settings to switch on or off specific highlighting languages. Which leads me onto ...
  2. Adding too much - while our users come first, would it be really worth it to implement multiple coding languages that our users suggest if only a relatively small amount of users use that code's syntax highlight, while the deluge of JS slows the post render time cumulatively and causes additional configuration work for admins (while at a smaller scale a "toggle on highlight for [Y] language" can work, in the long term if we keep on adding things we would need to build better ways to filter settings, or somehow load the highlights via a text setting)? We should need a reasonably popular demand before doing things like adding new syntax highlight. Appearance of a coding language on two questions only, and with a commentless, +2 voted feature request to add the syntax highlight would, by way of comparison to other feature requests, not prioritised for example.

To answer your comment queries:

("min" in particular, the comment said). I gather that the minified highlight.js doesn't include D but other versions do. I'm not sure what the cost of using a different version is.

Yeah, min means that the file has been run through a JS minifier (see Wikipedia to get an idea of what minification is). Basically, its net effect is to reduce the file size served to users. In this case, we can include a script tag to pull in a minified coding language.

I seem to recall we also had a request to support Cypher (I think that was the name); not sure if a change to support D would also cover that.

No, we would have to add an additional script tag for the Cypher coding language to make that happen.

If in light of this we still want to proceed, I'm fine with exploring this issue further or exploring the necessary changes.

sau226 avatar Aug 13 '21 13:08 sau226

I'd like to better understand the performance and maintenance costs before we proceed. If every page load means downloading a third-party library again, that sounds hefty. Is caching, either in the browser or at our end, not possible?

I thought a minified version was supposed to be the exact same JS, except compacted, as the non-minified version, but if that's the case then I don't understand why the supported languages would change between the two.

If there is something in between "all 200 languages" and the subset we have now, then we should discuss (on meta, with our users) how to decide when to add a language. If it's all-or-nothing and borderline expensive, we should discuss that more broadly too.

cellio avatar Aug 13 '21 13:08 cellio

This seems to involve a lot more than just enabling one language, and that language isn't used a lot so far, so I'm lowering the priority until we have time to think about the best solution for additional languages in general.

cellio avatar Aug 15 '21 19:08 cellio

We had a request on Discord for Clojure/clojurescript. (I'm a little surprised Clojure isn't in the default list.)

cellio avatar Nov 17 '21 00:11 cellio

@cellio clojure is in the "lisp" section here: https://highlightjs.org/static/demo/

razetime avatar Jan 28 '22 05:01 razetime