5

For some days I have been noticing that on Stack Overflow the Markdown content is rendered as black text only.

And this is how I actually see this page:

Enter image description here

4
  • 2
    that tag stackoverflow.com/tags/laravel-7/info doesn't have a syntax highlighter set, so it does lang-none
    – rene
    Feb 7, 2021 at 18:07
  • @rene before it worked well. This is happening for some days. This is an another example stackoverflow.com/q/64351570/4575350
    – STA
    Feb 7, 2021 at 18:08
  • 1
    That is probably because that post had the laravel tag: stackoverflow.com/tags/laravel/info that uses lang-php as the highlighter.
    – rene
    Feb 7, 2021 at 18:11
  • 1
    For the highlighter to activate and highlight code blocks automatically, at least one tag on a question must have a highlight language set - even if the language is default (example). If no tags on the question have a "Code Language", no highlighting will occur automatically. Feb 7, 2021 at 18:16

1 Answer 1

9

It works as designed.

I've hand-picked lang-php in your two example posts and syntax highlighting came to life. Both posts only had the tag

The laravel-7 tag doesn't have a syntax highlighter configured. That leads to no attempt to do any syntax highlighting

The laravel tag does have the lang-php highlighter selected. On posts with that tag the highlighter does attempt to bring some color to PHP.

Ask a mod to set the syntax highlighter to lang-php on to prevent future confusion.

Note that has lang-default as highlighter and and have no highlighter set either. Maybe that is on purpose. Before choosing the correct highlighter maybe consult in the PHP or Laravel chatroom first or open a feature/support request here on Meta to reach consensus.

The default for how Stack Exchange leverages Highlight.js is so utterly useless that by no means it should be the default. If no highlighter is selected, lang-none is intended. If you want the auto-detect of highlight.js to screw up due to it not having a suitable grammar (SE limits heavily what is avaialable) then ask for lang-default on your favorite tag. If there is a sane by Stack Exchange supported language highlighter in its highlight.js package, have a mod add that language hint to the tag.

Please support:

14
  • 3
    I would consider the fact that no highlighting occurs automatically to be a definite bug. Even with no language set, SE should at least try to highlight blocks, it'll probably get close most of the time. Semi-related Feb 7, 2021 at 18:21
  • 3
    @CertainPerformance I whole heartedly disagree.
    – rene
    Feb 7, 2021 at 18:27
  • It would have worked in this case. Run: StackExchange.using("highlightjs", function () { $("pre").each(function () { this.classList.add('s-code-block'); StackExchange.highlightjs.instance.highlightBlock(this); }); }); on this page and it gets properly auto-detected as PHP. Feb 7, 2021 at 18:48
  • 6
    I've changed the highlighter language on all of the larvel-[4567] tags to lang-php. If there's a general desire to have them be lang-default, they can all be changed to that, but my impression is that having them all consistent is desirable. Another reasonable possibility is to have the larvel-[4567] tags all set to lang-default. How SE has the new highlighter set up is...frustrating.
    – Makyen Mod
    Feb 7, 2021 at 19:53
  • 1
    Worth adding here that per the Meta.SE syntax highlighting post, tags without a highlighter set are supposed to defer to lang-default. I have no idea whether that actually matches reality, however.
    – zcoop98
    Feb 8, 2021 at 18:00
  • 2
    This is why, whenever you use a version-specific tag, you should also always tag with the "main" (non-version-specific) tag. So, this question should have never been tagged only [laravel-7], but should have also been tagged [laravel].
    – Cody Gray Mod
    Feb 9, 2021 at 4:53
  • @rene [Maintainer of Highlight.js here] Highlight.js does not have a "default" per se. That is a SE concept. We can attempt to auto-detect the language, and I think that's what SE does when it's set to default, but auto-detection is not great when we don't actually have a grammar for the language in question. We have no "Larvel" grammar... so perhaps it picks HTML, perhaps it picks PHP, perhaps it picks something else... Setting the larvel tag language to php is probably a reasonable thing to do for now. Feb 15, 2021 at 2:32
  • @JoshGoebel Thanks for that clarification. I have reworded that last paragraph a bit based om your feedback.
    – rene
    Feb 15, 2021 at 9:02
  • I do agree "default" is very broken and will often lead to erratic/unpredictable behavior as when one posts different code with different keywords, it's possible to get an entirely different highlighting experience from one post to the next. Pinning tags to a specific default (as in the case of Laravel to PHP) at least guarantees predictable behavior - so people can learn what to expect from one post to the next, etc. Feb 15, 2021 at 13:49
  • @JoshGoebel true that. It also doesn't help that SE does a fall-back to lang-default if it finds multiple tags with different language-hints configured. I'm not 100% sure if in those cases selecting the language-hint from the most used tag but it is worth revisiting that default logic at the end of SE. Maybe if Ben Kelly has a few dev cycles to spare he could fiddle with that.
    – rene
    Feb 15, 2021 at 14:07
  • There is a whole post I've written on that (or did I contribute? can't recall). If multiple tags have languages hints then SE should ask us to use EITHER language and let us pick which (auto-detect) - which we can do quite easily. This change alone would be a 200% improvement. Feb 15, 2021 at 14:17
  • @JoshGoebel yeah, I found it. I already had upvoted it but just started a bounty on it to get it to the front-page again.
    – rene
    Feb 15, 2021 at 14:38
  • The other post I was thinking of: meta.stackexchange.com/questions/354793/… Feb 15, 2021 at 15:05
  • @JoshGoebel I started a bounty on that one as well.
    – rene
    Feb 15, 2021 at 15:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .