In a code fragment like the following ...
class Foo { internal Foo() { for (int i = 0; i < 42; ++i); } }
... its various keywords and so on are color-coded when they're displayed in my browsers.
When I do "View source", I don't see anything special in the HTML that would implement this color-coding.
How and/or where is this syntax-specific color-highlighting implemented, then? For example is it built-in to the browsers, or is it implemented by site-specific JavaScript editing the DOM within the browsers?
I find this a difficult question to Google for.
The HTML <mark> tag is used to mark or highlight text that is of special interest or relevance in an HTML document. Browsers traditionally render the text found within the <mark> tag as text with a yellow background color.
HTML <mark> Tag The <mark> tag in HTML is used to define the marked text. It is used to highlight the part of the text in a paragraph. The <mark> tag is new in HTML 5.
How Do I Highlight Text In CSS? To Highlight text in HTML you have to use an inline element such as the <span> element and apply a specific background style on it. This will create the highlighting effect, which you can tweak in many different ways to create different looks.
Syntax is the arrangement of elements and attributes to create well-formed documents. Semantics is concerned with meaning. In HTML, this is the purpose of elements and attributes, and the logical (sense and reference) relationship between elements and the attributes of those elements.
Stack Overflow uses Google's prettify JS library for doing syntax highlighting. It executes on the client side after the HTML has been delivered by the server. That's why you don't see it in the raw HTML source. If you have a browser plugin such as FireBug, you'll be able to inspect the DOM after prettify has done its magic.
Update 2020-09-14: Stack Overflow switched from Google's prettify to highlight.js.
There is an excellent FAQ What is syntax highlighting and how does it work? over on meta.SE.
It’s pretty extensive. For your convenience, i’ll quote the part most related to your question:
When creating or editing posts, syntax highlighting is assigned to the preview based on question's tags as soon as you stop typing for 5 seconds.
Stack Exchange does not have its own syntax highlighting engine. It uses highlight.js, and may not necessarily be using the latest release of that library. Therefore, any bugs and feature requests regarding syntax highlighting cannot be handled by Stack Exchange.
[ Continue reading the original post … ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With