<-- back to the mailing list

Syntax highlighting

Oliver Simmons oliversimmo at gmail.com

Wed Sep 15 16:21:08 BST 2021

- - - - - - - - - - - - - - - - - - - 

On Mon, 13 Sept 2021 at 16:18, mntn <mntn at mntn.xyz> wrote:

I am confident that the best option is just to use the name of the language as the alt text. Alt text of "javascript" is fairly clear as to what follows in the preformatted text block--so it still works as alt text--and a syntax highlighter could use that hint for parsing the text and highlighting the code. A properly designed syntax highlighter will give up and fail quietly/safely if it can't parse the code for whatever reason, say if it's actually a poem titled "javascript" instead of code.

Personally I think using the MIME type would be most sensible, it'swhat's already done when a page is received, so it'd make developmenteasier for clients.(I'm including non-""official"" MIME types. The ""official"" coverageof source code files is a bit lacking)

Clients may want to ignore anything following a space or punctuation, so alt text could be even more descriptive, such as "javascript: excerpt from example.js" or "HTML example."

Big +1 to this :)

These two examples given here don't seem to be useful, if the clientis adding syntax highlighting then it can probably generate analt-text saying "HTML source code" by itself.Stating that it's an example or something is highly likely to be donein the normal text anyways.

However, I imagine making a screen-reader read code would be absolute hell!So it would be extremely useful for this to be a thing, so the codecan be roughly described in a screen-reader safe way.

-Oliver Simmons (GoodClover)