5

Came across a post recently where it was vb.net heavy but the sql-server tag was relevant because the problem could have been solved in either the DB or the front end

All the vb.net code (there was only vb.net code) in the post was being highlighted using sql-server implied syntax

If I removed the sql-server tag, the post highlighted with VB. If I added the sql-server tag back, I was hoping that maybe it would "add the tag at the end of the tag list" and "the syntax highligher works from left to right when looking for a tag to pull highlight settings from"

This latter part may be true, but adding the sql-server tag back put it in its original place (the full tag set was .net sql-server vb.net gridview so they don't seem to be in e.g. alphabetical order) and the post went back to highlighting the VB with SQLS syntax

Can anyone tell me what the logic is for choosing when a post contains multiple tags with a highlight?

Is there a way we can edit the tag order to make the site pick a different one to highlight on, rather than editing the post and manually editing every code block to have a forced tag/lang command, and also highlight all the answers the same?

7
  • Is this MSE answer helpful? Commented Sep 14, 2020 at 6:31
  • And if there isn't a way to edit tags to change the syntax highlight, would it make sense to have e.g. some clickable thing appear next to a hovered tag, to "change the highlighting in this post to be based on this tag"?
    – Caius Jard
    Commented Sep 14, 2020 at 6:32
  • @JeanneDark I don't think the FAQ mentions how conflicts are resolved, perhaps this/rene's advice could be a sensible addition to the FAQ..
    – Caius Jard
    Commented Sep 14, 2020 at 6:35
  • 2
    The section "How do I use syntax highlighting?" doesn't contain relevant info? Commented Sep 14, 2020 at 6:40
  • @JeanneDark the FAQ does not appear to answer the question I lead with: Syntax highlighting on posts with multiple tags; how is it resolved? unless I missed it (I was aware of the FAQ, and I re-read it at your first recommendation)
    – Caius Jard
    Commented Sep 14, 2020 at 6:57
  • @Caius Jard: There is some information, but it is not very clear (and may be out of date): "Each tag has a highlighting language specified in its properties, or no language. If there's more than one tag that has a highlighting language specified, or if none of the tags have one specified, it uses a default and lets Prettify infer what's the best language to use." Commented Sep 14, 2020 at 16:25
  • @PeterMortensen thanks for the update. I saw it but it seems a bit handwavy (and I don't think we use Prettify now..). I guess the FAQ will be overhauled at some point and that aspect will be cleared up
    – Caius Jard
    Commented Sep 14, 2020 at 17:04

1 Answer 1

4

Tags are ordered by the number of questions on that tag at the time the revision was saved.

To determine the syntax highlight language to use the system looks for a sigle tag that has a syntax highlight hint set.

In your example it will fallback to lang-default (because there are multiple tags with language hints). (.net has lang-default, sql-server has lang-sql, vb.net has lang-vb). In a lot (I mean a many lots) of cases this is a choice that will do.

When it isn't overrule the choice made by the system by adding

<!-- language-all: vb -->

near the top of the post on a single line all by itself. That will tell the highlighter to ignore what ever the tags tell it and use your language hint for all code blocks. Despite popular belief this specific feature should/will continue to work in Common Mark. If not, that is a bug.

Alternatively you mix-and-match by adding the correct language hint to each code block. You need to use code-fences in that case and specify the language hint directly after the three opening backticks on the same line:

```vb
Dim strSql As String = "Awesome"
```

I don't think we need fancy features, UX or other functionality for this. What is there works for the few cases this needs human intervention. No need to clutter the UI with more bells and whistles.

15
  • It does also require every answerer to use language-all too, though.. right?
    – Caius Jard
    Commented Sep 14, 2020 at 6:54
  • @CaiusJard yes, that is correct. A language hint is supposed to be per post.
    – rene
    Commented Sep 14, 2020 at 6:59
  • Any comments on Zoe's note that lang-all no longer works (it appears true from what I've tested)?
    – Caius Jard
    Commented Sep 14, 2020 at 7:05
  • @CaiusJard show me an example where it doesn't work because it should. See my recent edit.
    – rene
    Commented Sep 14, 2020 at 7:44
  • I added a lang-all to this (the question that sparked this question) stackoverflow.com/questions/63854086/… but (for me) the syntax highlighting is wonky
    – Caius Jard
    Commented Sep 14, 2020 at 7:54
  • @CaiusJard that is a bug in the highlighter, it doesn't like the single quote ... see my edit to your answer for a 'fix'
    – rene
    Commented Sep 14, 2020 at 8:06
  • No, it wasn't my answer I was complaining about (I never added any syntax highlighting to my answer - i've only ever been talking about the question; it was the question that was showing the error but Andrew Morton has edited the question to remove the lang-all VB that I put in and put per code block lang specifiers. Sigh. I'm going to revert Andrew's edit and explain why; it can be re-done later once this is investigated more
    – Caius Jard
    Commented Sep 14, 2020 at 9:41
  • @CaiusJard I know it wasn't your answer that was the problem, I only used it to demonstrate the problem / issue to not bother the OP of the question with inbox messages of their post being edited.
    – rene
    Commented Sep 14, 2020 at 9:51
  • If "it's a bug in the highlighter" then why does ```lang-vb work and lang-all: vb not? Looks to me more like it's the lang-all that doesn't work because if the sql-server tag is removed, the VB highlighter works with the 'comments and if the lang is specified per code block, the highlighter also works OK..
    – Caius Jard
    Commented Sep 14, 2020 at 9:53
  • @CaiusJard it needs to be language-all. not lang-all. I've made the edit
    – rene
    Commented Sep 14, 2020 at 10:08
  • That's very bizarre: my first attempt was with language-all and it didn't work.. I changed it to lang-all based on this answer
    – Caius Jard
    Commented Sep 14, 2020 at 10:10
  • @CaiusJard yeah, sorry. I went back-and-forth a few times as I struggled to remember what allowed shorthand notation and language couldn't be shortened where I presumed it did.
    – rene
    Commented Sep 14, 2020 at 10:14
  • I can only assume that my first attempt had a typo perhaps, as language-all does seem to work now (my first edit seems to have been coalesced in the history).. All good, cheers for the help!
    – Caius Jard
    Commented Sep 14, 2020 at 10:15
  • @CaiusJard The language-all did not extend from the question to your answer. Commented Sep 14, 2020 at 12:19
  • @AndrewMorton indeed, and I knew it wouldn't. I was never talking about my answer when querying how multiple tag syntax highlights were resolved.. It was always about the question, but there was some misunderstanding along the way as to whether language-all was still a thing (and most of the evidence that it was/wasn't has now been edited away for consistency, but it leaves an incomplete picture of the true sequence of events)
    – Caius Jard
    Commented Sep 14, 2020 at 12:23

You must log in to answer this question.

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