I'm the maintainer for Google Code Prettify.
Markup authors can specify the language for source code, but not markdown authors. Are the SO admins interested in a way of doing this?
If so, might the following work
- If the first line is "#!" followed by one or more word characters, then make the first line invisible (using CSS hidden:visible) and use those word characters as the file extension.
- Otherwise, use the current scheme.
So
#!css
tag.class#id { color: red }
would be recognized as CSS.
In markdown, should any indicator of line numbers survive copy-paste in markdown?
Does any scheme like this need to do work to handle quoting of responses in markdown? Is it common for inline responders to split code sections?
Do users also want to number lines ( http://google-code-prettify.googlecode.com/svn/trunk/README.html#linenums ), so that others can respond with reference to particular lines?
-
11It's a pity that the shebang with an interpreter name isn't counted as a hint about the language. (An example -- a bash script that could be highlighted accordingly if the shebang line would be taken into account: stackoverflow.com/questions/6748083/… .) I'm used to that Emacs does this...imz -- Ivan Zakharyaschev– imz -- Ivan Zakharyaschev2011年07月19日 14:52:52 +00:00Commented Jul 19, 2011 at 14:52
-
@imz: yeah, given the way prettify is supposed to be able to guess languages in easy cases, you'd think that'd be an excellent cue for it...SamB– SamB2012年01月31日 06:04:16 +00:00Commented Jan 31, 2012 at 6:04
-
3@Mike, can you please point me to some documentation on how to contribute a new language to Prettify? I'm pascal fan and really would love to see the pascal syntax highlighted here and there. Thanks. :)jachguate– jachguate2012年11月06日 07:23:04 +00:00Commented Nov 6, 2012 at 7:23
1 Answer 1
Syntax Highlighting with "Code Prettify"
This is now implemented. See Stack Overflow’s help on Syntax Highlighting.
Specifying a language for syntax highlighting
Besides tag inferences (a recent change), you can manually specify a language as a hint to Google Code Prettify.
Here’s how:
<!-- language: «lang-or-tag-here» -->
«code goes here»
«more text»
<!-- language: «lang-or-tag-here» -->
«code goes here»
You may use either a tag or a prettify language code. Prettify language codes are guaranteed to work, regardless of what language the tag happens to be set to.
Available Language Hints Moved
Due to several lists of available hints existing throughout Meta, the entire list has been consolidated and moved to the following FAQ:
-
1@kevin, as there are no tags for "none" and "default": are those still somehow supported? (I also copied your edit to one of Jeff's other posts.)Arjan– Arjan2011年03月07日 19:54:00 +00:00Commented Mar 7, 2011 at 19:54
-
10What is the recommended language tag for 'make' or 'makefile'? I guess 'lang-sh' is a reasonable approximation.Jonathan Leffler– Jonathan Leffler2011年05月16日 22:26:24 +00:00Commented May 16, 2011 at 22:26
-
@Jeff, I guess my question is, do I need to bother on my vba questions using the prettify language code
lang-vb
, or should I just let myvba
tag take care of it. And then if the tag does take care of it, does it function better (or more smoother) if I use the prettify code?Lance Roberts– Lance Roberts2011年05月26日 06:14:36 +00:00Commented May 26, 2011 at 6:14 -
@lance let the tags carry whenever possible, it's much simpler (and it fixes it for "everyone" when the tags "just work" as much as possible). Use Google Chrome inspector to view the CSS classes on the rendered
<pre>
to see what is actually finally happening in the post. That's what I do anyway.2011年05月26日 06:18:26 +00:00Commented May 26, 2011 at 6:18 -
1I don't understand what's the difference between c and lang-c.user unknown– user unknown2012年03月26日 09:02:02 +00:00Commented Mar 26, 2012 at 9:02
-
5@User,
c
is a tag;lang-c
is a Prettify language code. When a question is taggedc
, any code in the question automatically gets highlighted with thelang-c
language code because the tag is configured (somewhere) to be associated with that language code. The distinction is important for tags that don't have a specific language. For example, thepascal
tag is configured withlang-default
; there is nolang-pas
language code. Manually marking code aslang-pas
will leave it unhighlighted, but marking itpascal
will invoke the default highlighting rules.Rob Kennedy– Rob Kennedy2012年05月25日 21:53:13 +00:00Commented May 25, 2012 at 21:53 -
@RobKennedy: In Code-golf, nearly all questions are language agnostic. So there I mark my scala solutions
<-- language: lang-scala -->
. This shall always work, since there is a prettify tag for scala. Below the bullet list which ends inlang-xml
there are more tags,"bsh", "c", "cc", ...
- some of them are listed above, some are not. I still don't get the distinction.user unknown– user unknown2012年05月25日 22:13:44 +00:00Commented May 25, 2012 at 22:13 -
1That's right, @User. There are some Stack Overflow tags that don't have corresponding Prettify language codes. I mentioned Pascal. If I mark Pascal code with
lang-pas
, it won't get highlighted; Prettify doesn't currently support that language. If I mark it withpascal
, it will get highlighted; Stack Overflow currently associates thelang-default
code with that tag. It doesn't get highlighted well, but at least there's something. When Prettify eventually supports Pascal, the we'll re-associated that tag withlang-pas
, and all existing Pascal code will get highlighted correctly.Rob Kennedy– Rob Kennedy2012年05月26日 04:01:17 +00:00Commented May 26, 2012 at 4:01 -
1From my experience the segment to be highlighted needs to be formatted as code or no highlighting will occur. If that's the case it should be stated here.Th 00 mÄ s– Th 00 mÄ s2012年07月03日 08:53:16 +00:00Commented Jul 3, 2012 at 8:53
-
Latest release of prettify now looks for comments/processing-instructions of the form
<?prettify lang=...>
to better interoperate with translators that produce HTML like markdown. (HTML5 specifies that<?...?>
is equivalent to<!--?...?-->
).Mike Samuel– Mike Samuel2013年02月25日 18:50:48 +00:00Commented Feb 25, 2013 at 18:50 -
ok @MikeSamuel I will make sure the devs know! (I am no longer at Stack Exchange)2013年02月25日 22:42:28 +00:00Commented Feb 25, 2013 at 22:42
-
7Any chance of adding syntax highlighting for more languages, such as Windows command line for batch files or Windows PowerShell?Zarepheth– Zarepheth2013年07月18日 20:51:09 +00:00Commented Jul 18, 2013 at 20:51
-
1Why doesn't YAML have a tag? It's in Google Prettify...CommaToast– CommaToast2013年07月22日 03:36:58 +00:00Commented Jul 22, 2013 at 3:36
-
1The prettify language code for
c#
islang-csharp
but notlang-cs
. Usinglang-cs
causes to turn on the default highlighting and doesn't highlight theusing
namespace
andvirtual
keywords.Sri Harsha Chilakapati– Sri Harsha Chilakapati2013年07月22日 04:29:04 +00:00Commented Jul 22, 2013 at 4:29 -
1I've created the tag tag-syntax-association for requesting association be made between tags and their corresponding language name (something only moderators can do)Eric– Eric2013年08月16日 10:53:17 +00:00Commented Aug 16, 2013 at 10:53
Explore related questions
See similar questions with these tags.