P粉1916105802023-08-23 14:40:07
There is a very good FAQ on meta.SE What is syntax highlighting and how does it work? .
It is very detailed. For convenience, I'll quote the parts most relevant to your question:
When creating or editing a post, syntax highlighting is assigned to the preview 5 seconds after you stop typing, based on the question's tag.
Stack Exchange does not have its own syntax highlighting engine. It uses highlight.js and may not necessarily use the latest version of that library. Therefore, any bugs and feature requests regarding syntax highlighting cannot be handled by Stack Exchange.
[ Continue reading original post... ]
P粉6048485882023-08-23 10:59:24
Stack Overflow uses Google’s prettify JS library for syntax highlighting. It is executed after the HTML is transmitted from the server to the client. That's why you don't see it in the original HTML source code. If you have a browser plugin like FireBug installed, you can inspect the DOM after prettify completes.
Update 2020-09-14: Stack Overflow switched from Google’s prettify to highlight.js.