`
Classicning
  • 浏览: 250674 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

highlight.js

    博客分类:
  • WEB
阅读更多
highlight.js是一个JavaScript库,它用于在网页中高亮你的程序代码,它基于RegExp。

要使用highlight.js只需:

    <script type="text/javascript" src="highlight.js"></script>
    <script type="text/javascript">
      initHighlightingOnLoad();
    </script>


不过这样可能带来较慢的速度,你可以手动指定要高亮的语言。

    <script type="text/javascript">
      initHighlightingOnLoad('html', 'css');
    </script>

注意虽然这样写了,但是JavaScript并不支持重载。

在HTML中这样引用即可。

    <pre><code class="html">...</code></pre>


要想改变默认的显示样式,可以对一些关键字的class修改样式。

    .comment {
      color: gray;
    }

    .keyword {
      font-weight: bold;
    }

    .python .string {
      color: blue;
    }

    .html .atribute .value {
      color: green;
    }


每种语言有一些类型,分别用CSS的类选择器就可以访问和修改。

Python:
    
  keyword          keyword
  number           number
  string           string (of any type)
  comment          comment
  decorator        @-decorator for functions
  function         function header "def some_name(...):"
  class            class header "class SomeName(...):"
  title            name of a function or a class inside a header
  params           everything inside parentheses in a function's or class' header

Ruby:
    
  keyword          keyword
  string           string
  subst            in-string substitution (#{...})
  comment          comment
  function         function header "def some_name(...):"
  class            class header "class SomeName(...):"
  title            name of a function or a class inside a header
  symbol           symbol

Perl:
    
  keyword          keyword
  comment          comment
  number           number
  string           string
  regexp           regular expression
  sub              subroutine header (from "sub" till "{")
  variable         variable starting with "$", "%", "@"
  operator         operator
  pod              plain old doc

PHP:
    
  keyword          keyword
  number           number
  string           string (of any type)
  comment          comment
  phpdoc           phpdoc params in comments
  variable         variable starting with "$"

HTML:
    
  keyword          HTML tag
  tag              any tag from "<" till ">"
  comment          comment
  doctype          <!DOCTYPE ... > declaration
  attribute        tag's attribute with or withou value
  value            attribute's value

CSS:
    
  keyword          HTML tag when in selectors, CSS keyword when in rules
  id               #some_name in selectors
  class            .some_name in selectors
  attr_selector    attribute selector (square brackets in a[href^=http://])
  comment          comment
  rules            everything from "{" till "}"
  value            property's value inside a rule, from ":" till ";" or
                   till the end of rule block

Django:

  keyword          HTML tag in HTML, default tags and default filters in templates
  tag              any tag from "<" till ">"
  comment          comment
  doctype          <!DOCTYPE ... > declaration
  attribute        tag's attribute with or withou value
  value            attribute's value
  template_tag     template tag {% .. %}
  variable         template variable {{ .. }}
  template_comment template comment, both {# .. #} and {% comment %}
  filter           filter from "|" till the next filter or the end of tag
  argument         filter argument

Javascript:
    
  keyword          keyword
  comment          comment
  number           number
  literal          special literal: "true", "false" and "null"
  string           string
  regexp           regular expression
  function         header of a function
  title            name of a function inside a header
  params           everything inside parentheses in a function's header

VBScript:
    
  keyword          keyword
  number           number
  string           string
  comment          comment
  built_in         built-in function

Delphi:
    
  keyword          keyword
  comment          comment (of any type)
  number           number
  string           string
  function         header of a function, procedure, constructor and destructor
  title            name of a function, procedure, constructor or destructor
                   inside a header
  params           everything inside parentheses in a function's header
  class            class' body from "= class" till "end;"

Java:
    
  keyword          keyword
  number           number
  string           string
  comment          commment
  annotaion        annotation
  javadoc          javadoc comment
  class            class header from "class" till "{"
  title            class name inside a header
  params           everything in parentheses inside a class header
  inheritance      keywords "extends" and "implements" inside class header

C++:
    
  keyword          keyword
  number           number
  string           string and character
  comment          comment
  preprocessor     preprocessor directive

RenderMan (RSL):
    
  keyword          keyword
  number           number
  string           string
  comment          comment
  preprocessor     preprocessor directive
  shader           sahder keywords
  shading          shading keywords
  built_in         built-in function

RenderMan (RIB):
    
  keyword          keyword
  number           number
  string           string
  comment          comment
  commands         command

SQL:
    
  keyword          keyword (mostly SQL'92 and SQL'99)
  number           number
  string           string (of any type: "..", '..', `..`)
  comment          comment
  aggregate        aggregate function

Smalltalk:

  keyword          keyword
  number           number
  string           string
  comment          commment
  symbol           symbol
  array            array
  class            name of a class
  char             char
  localvars        block of local variables

Axapta:
    
  keyword          keyword
  number           number
  string           string
  comment          commment
  class            class header from "class" till "{"
  title            class name inside a header
  params           everything in parentheses inside a class header
  inheritance      keywords "extends" and "implements" inside class header
  preprocessor     preprocessor directive

1C:

  keyword          keyword
  number           number
  string           string
  comment          commment
  function         header of function or procudure
  title            function name inside a header
  params           everything in parentheses inside a function header
  preprocessor     preprocessor directive


也可以用下面的类选择器来禁用高亮

<pre><code class="no-highlight">...</code></pre>


highlight.js web site
http://softwaremaniacs.org/soft/highlight/en/
分享到:
评论
1 楼 onlydo 2008-11-06  
http://softwaremaniacs.org/soft/highlight/en/
这个地址现在打不开了。

相关推荐

Global site tag (gtag.js) - Google Analytics