7

I noticed a strange rendering of the question text.

Here is a screenshot. Note how the code block starts as expected until the underscore character and then turns into italic. I'm using Chrome on Windows 10.


SO render bug


Here is a link to the question: C# and T-SQL Insert User Defined Table into a another table not working

Let's see what happens if I copy-paste the code from that question here:

CREATE TYPE [dbo].[CSV_ADDProducts] AS TABLE(
    [Product Item] [nvarchar](max) NULL,
    [Product SKU] [bigint] NULL,
    [Product Name] [nvarchar](max) NULL,
    [Product Active] [nchar](10) NULL,
    [Product Selling Price] [money] NULL,
    [Product Description] [nvarchar](max) NULL,
    [Product Purchase Description] [nvarchar](max) NULL,
    [Product VAT Code ID] [bigint] NOT NULL,
    [Product Last Update] [datetime] NULL
)
GO

It renders correctly in the preview as I'm typing this question. Let's see how it looks when I post the question...

It rendered fine.

Now, I've added a language lang-tsql for the code block (as one of the tags in the original question) and I can see the same bug here on meta already in the preview of this question as I'm typing this.

My understanding is that lang-tsql is a valid language hint that is listed in https://github.com/highlightjs/highlight.js/blob/master/SUPPORTED_LANGUAGES.md

5
  • 1
    @JohnMontgomery, I think that similar question that you linked is not really a duplicate. In that question it boiled down to the highlighter choosing incorrect language. Here I'm telling the highlighter what language to use and it renders it incorrectly. I don't think that sql-server code should be rendered in italic ever, so it looks like a bug in the highlighter. I don't know if SO can fix how highlighter works. I don't know if this is something that they wrote themselves and can fix or they rely on third-party library that they can't change. Commented Nov 14, 2020 at 1:53
  • 5
    I don't think sql-server is a valid language tag, so it's trying to guess and making the same mistake as the other question. Yep, change it to lang-sql and it works fine. Commented Nov 14, 2020 at 1:56
  • Wow... We now have syntax highlighting that's adding italics? That shouldn't be happening. Those styles should be changed.
    – Cody Gray Mod
    Commented Nov 14, 2020 at 5:31
  • You didn’t pick a language that’s actually supported, the duplicate does apply.
    – Martijn Pieters Mod
    Commented Nov 14, 2020 at 8:57
  • @Cody I think the only code language to render italics is Markdown... the dupe says there are 3 highlight.js langs that do this, but when I went through all the languages I'm pretty sure Markdown was the only one that SE has installed that does this. I'm not really sure why we have Markdown installed as a language, I've only ever seen it used accidentally, like in this case lol
    – zcoop98
    Commented Nov 16, 2020 at 16:01

1 Answer 1

3

John Montgomery pointed to a similar question Code block containing asterisks displaying in italics

I did few tests and this is what I found.

lang-tsql looks like a valid language hint that is listed in https://github.com/highlightjs/highlight.js/blob/master/SUPPORTED_LANGUAGES.md , but it is a 3rd party language package.

So, maybe it is not included in SO code, so highlighter doesn't recognize it and in the end it tries to pick something automatically. If there is no _ symbol in the code, it determines that the code is SQL and colours it properly - in the same way as if I marked it with lang-sql. If I add the _ the highlighter gets confused and uses some different language, which interprets _ as italics (and __ as bold).

Here are few examples.

This block without _ is marked as lang-tsql:

CREATE TYPE [dbo].[CSVADDProducts] AS TABLE(
    [Product Item] [nvarchar](max) NULL,
    [Product Last Update] [datetime] NULL
)
GO

This block with _ is marked as lang-tsql:

CREATE TYPE [dbo].[CSV_ADDProducts] AS TABLE(
    [Product Item] [nvarchar](max) NULL,
    [Product Last Update] [datetime] NULL
)
GO

This block without _ is marked as lang-qlwkeuyhudhb:

CREATE TYPE [dbo].[CSVADDProducts] AS TABLE(
    [Product Item] [nvarchar](max) NULL,
    [Product Last Update] [datetime] NULL
)
GO

This block with _ is marked as lang-qlwkeuyhudhb:

CREATE TYPE [dbo].[CSV_ADDProducts] AS TABLE(
    [Product Item] [nvarchar](max) NULL,
    [Product Last Update] [datetime] NULL
)
GO

So, lang-tsql behaves the same as rubbish lang-qlwkeuyhudhb, which means that highlighter doesn't recognize lang-tsql.

If it is marked with lang-sql, it works fine:

This block without _ is marked as lang-sql:

CREATE TYPE [dbo].[CSVADDProducts] AS TABLE(
    [Product Item] [nvarchar](max) NULL,
    [Product Last Update] [datetime] NULL
)
GO

This block with _ is marked as lang-sql:

CREATE TYPE [dbo].[CSV_ADDProducts] AS TABLE(
    [Product Item] [nvarchar](max) NULL,
    [Product Last Update] [datetime] NULL
)
GO

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