如何在StackOverflow中设置代码颜色? [英] How Code Color is Set in StackOverflow?

查看:101
本文介绍了如何在StackOverflow中设置代码颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

StackOverflow最受欢迎的功能是它可以自动检测帖子中的代码并为代码设置合适的颜色。

The most favorite feature of StackOverflow for me is that it can automatically detect code in post and set appropriate color to the code.

我想知道颜色如何已设定。当我在页面上执行 Ctrl + F5 时,代码似乎首先是黑色文本,然后变为丰富多彩。它是由jQuery完成的吗?

I'm wondering how the color is set. When I do a Ctrl+F5 on a page, the code seems first be black text, then change to be colorful. Is it done by jQuery?

推荐答案

回复..


Spolsky:他们怎么知道,他们怎么知道你写的是哪种语言?

Spolsky: How do they know, how do they even know what language you're writing in?

它没有。荧光笔是非常愚蠢的,但由于大多数编程语言都非常相似,因此设法摆脱它。几乎所有东西都使用语法足够接近..

It doesn't. The highlighter is very dumb, but manages to gets away with it because most programming languages are so similar. Nearly everything uses syntax close-enough to..

AFunction("a string")
1 + 4 # <- numbers
      #     /\ a comment
      // also a comment..

..大多数东西都突出了。以上不是一种实用的编程语言,但它完美地突出显示。

..that most stuff highlights properly. The above isn't an actuall programming language, but it highlights perfectly.

有例外,例如,它有时可以处理 / 作为正则表达式的开头(如在Perl / Ruby中)。当它不是:

There are exceptions, for example, it can sometimes treat a / as the start of a regex (as in Perl/Ruby). when it is not:

this [^\s>/] # is highlighted as a regex, not a comment

..但这些是相当罕见的,它可以很好地解决大多数问题,比如..

..but these are fairly rare, and it does a good job of working out most stuff, like..

/*
this is a multi-line comment
"with a string" =~ /and a regex/
*/
but =~ /this is a regex with a [/*] multiline comment
markers in it! */

这篇关于如何在StackOverflow中设置代码颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆