When using SO's code blocks, can you control how syntax highlighting is performed? Many times, I've pasted (for example) some shell output into an SO answer, and the syntax highlighting has been completely unrelated. Is there any way to turn it off, or to change the language used?
-
See also: meta.stackexchange.com/questions/981/syntax-highlighting-hintsRowland Shaw– Rowland Shaw2010年06月29日 14:17:07 +00:00Commented Jun 29, 2010 at 14:17
2 Answers 2
There is a way to completely turn off code highlighting: use (削除) tags (I often do this for OCaml/Lisp/Haskell code where unmatched <code>
(削除ここまで)'
s cause problems). EDIT: As random pointed out, <pre>
will work better than <code>
.
Normal highlighting:
return 'a' "x" void
With <pre>
it looks like this:
return 'a' "x" void
Keep in mind that with <pre>
, you don't need to indent your code by four spaces. For example, the code in this answer is formatted like this:
Normal highlighting with four spaces:
return 'a' "x" void
or with ```language:
```js
return 'a' "x" void
```
With `<pre>` it looks like this:
<pre>
return 'a' "x" void
</pre>
(Sorry about the highlighting but I can't do this in <pre>
...)
-
If you want the nice background, use
PRE
random– random2009年08月10日 14:48:00 +00:00Commented Aug 10, 2009 at 14:48 -
9Note that it appears that
<!-- language: none -->
is now the preferred mechanism to disable syntax highlighting for a preformatted block of text.Phrogz– Phrogz2011年03月31日 22:32:00 +00:00Commented Mar 31, 2011 at 22:32 -
I hope, my proposed edit enriches the post.Cadoiz– Cadoiz2021年09月20日 06:31:57 +00:00Commented Sep 20, 2021 at 6:31
-
1There is also the newer code fence, ```lang-none.This_is_NOT_a_forum– This_is_NOT_a_forum2021年09月20日 11:59:35 +00:00Commented Sep 20, 2021 at 11:59
You cannot control how the syntax is highlighted.
SO, uses Google's prettify to do the syntax coloring. Prettify uses common language patterns to determine syntax coloring.
For example:
Comments:
// comment
#comment
Strings:
'This is a string'
"So is this"
Key words:
void
return
int
bool
As Zifre says. You can turn off the syntax highlighting in code by using the <pre>
tags around your desired block of code.
-
1So this is a problem upstream?SingleNegationElimination– SingleNegationElimination2009年09月10日 23:20:48 +00:00Commented Sep 10, 2009 at 23:20
-
Hmm... it looks like prettify has the ability to specify a language using a lang-* css class.SingleNegationElimination– SingleNegationElimination2009年09月10日 23:26:38 +00:00Commented Sep 10, 2009 at 23:26
-
Didn't work for me....
<pre class="prettyprint lang-html">
made the code a complete mess.Joe Casadonte– Joe Casadonte2010年03月06日 13:51:00 +00:00Commented Mar 6, 2010 at 13:51
Explore related questions
See similar questions with these tags.