Javascript code prettifier
Javascript ´úÂëÃÀÈÝʦ
°²×°Ê¹ÓÃ
ÏÂÔØ Îļþ
ÔÚÄãµÄÎļþÖаüº¬Õâ¶ùµÄ½Å±¾ºÍÑùʽ±í(ÄãÒª±£Ö¤Õâ¶ùµÄ css ºÍ js Îļþ°´ÔÚÄãµÄ·þÎñÆ÷ÉÏ, ²¢ÇÒµ÷ÕûÔÚ script ºÍ link±êÇ©ÖеÄ·¾¶)
<link href="prettify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="prettify.js"></script>
Ìí¼Óonload="prettyPrint()" µ½ÄãµÄÎļþµÄ body ±êÇ©ÖÐ.
ÐÞ¸ÄÑùʽ±í,ʹÓÃÄã×Ô¼ºÏ²»¶µÄÑÕÉ«.
ʹÓ÷½·¨
ÔÚ <pre class="prettyprint">...</pre> »ò <code class="prettyprint">...</code> Öмä·ÅÉÏ´úÂëƬ¶Î,Ëü¾Í»á×Ô¶¯±»ÃÀ»¯ÁË.
The original Prettier
class Voila {
public:
// Voila
static const string VOILA = "Voila";
// will not interfere with embedded tags.
}
class Voila {
public:
// Voila
static const string VOILA = "Voila";
// will not interfere with embedded tags.
}
³£¼ûÎÊÌâ
ËüÊÇΪʲôÓïÑÔ¹¤×÷µÄ?
prettify.jsÖеÄ×¢ÊÍÊÇȨÍþµÄ,µ«ÊÇËüµÄÓï·¨·ÖÎö³ÌÐò¿ÉÒÔÔںܶàÓïÑÔÖÐʹÓÃ,°üÀ¨ C , Java, Python, Bash, SQL, HTML, XML, CSS, Javascript, ºÍ Makefiles. ËüÔÚ Ruby, PHP, VB, ºÍ Awk Öл¹Ëã¿ÉÒÔ,¶øÇÒÒ²¿ÉÒÔÔÚ Perl ºÍ RubyµÄºÏÊÊ×Ó¼¯ÖÐÆð×÷ÓÃ,µ«ÊÇ, ÒòΪעÊ͵ÄÔ¼¶¨,Ëü¶Ô Smalltalk, »ò CAMLÀàËƵÄÓïÑÔÆð×÷ÓÃ.
LISPϵÁеÄÓïÑÔ¿ÉÒÔʹÓÃÒ»¸öÍØÕ¹lang-lisp.js.
¶ÔÓÚ CSS, Haskell, Lua, OCAML, SML, F#, Visual Basic, SQL, Protocol Buffers, ºÍ WikiText..Ò²ÊÇÀàËƵÄ
Èç¹ûÄãÏë¸øÄãϲ»¶µÄÓïÑÔд¸öÍØÕ¹°æ±¾, Çë²ÎÔÄsrc/lang-lisp.js ,²¢Ð´Ò»¸ö°üÀ¨ÄãµÄÓïÑÔµÄÍØÕ¹µÄ ·¢²¼ ºÍÒ»¸ö²âÊÔÓÃÀý.
ÈçºÎÖ¸¶¨ÎҵĴúÂëÔÚÄÄÖÖÓïÑÔÀï?
Äã²»ÐèÒªÖ¸¶¨ÓïÑÔ»·¾³,ÒòΪ prettyprint() »á¶Ô´Ë½øÐв²â. Äã¿ÉÒÔʹÓà prettyprint Õâ¸öÀàͨ¹ýÖ¸¶¨ÓïÑÔµÄÍØÕ¹ÃûÀ´Ö¸¶¨ÓïÑÔ,¾ÍÏñÕâÑù:
<pre class="prettyprint lang-html">
The lang-* class specifies the language file extensions.
File extensions supported by default include
"bsh", "c", "cc", "cpp", "cs", "csh", "cyc", "cv", "htm", "html",
"java", "js", "m", "mxml", "perl", "pl", "pm", "py", "rb", "sh",
"xhtml", "xml", "xsl".
</pre>
ËüÔÚ»ìÏý´úÂëÀý×ÓÉϲ»Æð×÷ÓÃÂð?
ÊǵÄ. ÃÀ»¯»ìÏý´úÂë¾ÍÏñ¸øСÖíÍ¿¿Úºì,Ò²¾ÍÊDz»ÔÚÕâ¸