diff options
author | Stuart Rackham <srackham@methods.co.nz> | 2010-08-02 17:13:50 +1200 |
---|---|---|
committer | Stuart Rackham <srackham@methods.co.nz> | 2010-08-02 17:13:50 +1200 |
commit | 9f6a0d1ee07fd2e9151dab03bf8f477c34fc56c4 (patch) | |
tree | 0e6a9f6385c2b7a40781a53e08c3f0b4ddb8bf6a | |
parent | 3d4a94c6e72f89bff1919cb1e0bbe8d619c2920d (diff) | |
download | asciidoc-9f6a0d1ee07fd2e9151dab03bf8f477c34fc56c4.tar.gz |
Pygments (http://pygments.org/) option added to source code highlight filter.
Based on Pygments source code filter written by David Hajage (http://groups.google.com/group/asciidoc/browse_thread/thread/d8d042f5a3021369/8934ebbb8cb7144b).
Define the 'pygments' attribute use Pygments instead of GNU Source Highlight.
-rw-r--r-- | doc/source-highlight-filter.txt | 12 | ||||
-rw-r--r-- | filters/source/source-highlight-filter.conf | 14 | ||||
-rw-r--r-- | stylesheets/pygments.css | 66 | ||||
-rw-r--r-- | xhtml11.conf | 4 |
4 files changed, 90 insertions, 6 deletions
diff --git a/doc/source-highlight-filter.txt b/doc/source-highlight-filter.txt index aded42e..7a0ab0d 100644 --- a/doc/source-highlight-filter.txt +++ b/doc/source-highlight-filter.txt @@ -4,9 +4,15 @@ Source Code Highlight Filter The AsciiDoc distribution includes a source code syntax highlight filter (`source-highlight-filter.conf`). It uses http://www.gnu.org/software/src-highlite/[GNU source-highlight] to -highlight HTML outputs; DocBook outputs are highlighted by toolchains -that have `programlisting` element highlight support, for example -'dblatex'. +highlight HTML outputs. You also have the option of using the +http://pygments.org/[Pygments] syntax highlighter for 'xhtm11' outputs +-- define an AsciiDoc attribute named 'pygments' to switch to Pygments +(you will also need to have Pygments installed and the 'pygmentize' +command in your PATH. You can customize Pygments CSS styles by +editing `./stylesheets/pygments.css`. + +DocBook outputs are highlighted by toolchains that have +`programlisting` element highlight support, for example 'dblatex'. TIP: If the source 'language' attribute has been set (using an 'AttributeEntry' or from the command-line) you don't have to specify diff --git a/filters/source/source-highlight-filter.conf b/filters/source/source-highlight-filter.conf index 0d4da7e..f1d92e4 100644 --- a/filters/source/source-highlight-filter.conf +++ b/filters/source/source-highlight-filter.conf @@ -4,9 +4,15 @@ # Documented in source-hightlight-filter.txt in AsciiDoc distribution # ./examples/website/ directory. # -# HTML outputs require GNU source-highlight +# HTML outputs require GNU source-highlight (xhtml11, html4 outputs) # http://www.gnu.org/software/src-highlite/source-highlight.html # +# or Pygments (xhtml11 outputs): +# http://pygments.org/ +# +# GNU source-hightlight is default, define the 'pygments' attribute to use +# Pygments. +# ######################## # Source block templates @@ -53,7 +59,8 @@ source-style=template="source-highlight-block",presubs=(),postsubs=("callouts",) endif::basebackend-html[] ifdef::backend-xhtml11[] -source-style=template="source-highlight-block",presubs=(),postsubs=("callouts",),posattrs=("style","language","src_numbered","src_tab"),filter="source-highlight -f xhtml -s {language} {src_numbered?--line-number} {src_tab?--tab={src_tab}}" +ifndef::pygments[source-style=template="source-highlight-block",presubs=(),postsubs=("callouts",),posattrs=("style","language","src_numbered","src_tab"),filter="source-highlight -f xhtml -s {language} {src_numbered?--line-number} {src_tab?--tab={src_tab}}"] +ifdef::pygments[source-style=template="source-highlight-block",presubs=(),postsubs=("callouts",),posattrs=("style","language","src_numbered"),filter="pygmentize -f html -l {language} {src_numbered?-O linenos=table}"] endif::backend-xhtml11[] ifdef::backend-docbook[] @@ -69,7 +76,8 @@ source-style=template="source-highlight-block",presubs=(),postsubs=("callouts",) endif::basebackend-html[] ifdef::backend-xhtml11[] -source-style=template="source-highlight-block",presubs=(),postsubs=("callouts",),posattrs=("style","language","src_numbered","src_tab"),filter="source-highlight -f xhtml -s {language} {src_numbered?--line-number} {src_tab?--tab={src_tab}}" +ifndef::pygments[source-style=template="source-highlight-block",presubs=(),postsubs=("callouts",),posattrs=("style","language","src_numbered","src_tab"),filter="source-highlight -f xhtml -s {language} {src_numbered?--line-number} {src_tab?--tab={src_tab}}"] +ifdef::pygments[source-style=template="source-highlight-block",presubs=(),postsubs=("callouts",),posattrs=("style","language","src_numbered"),filter="pygmentize -f html -l {language} {src_numbered?-O linenos=table}"] endif::backend-xhtml11[] ifdef::backend-docbook[] diff --git a/stylesheets/pygments.css b/stylesheets/pygments.css new file mode 100644 index 0000000..9ca3659 --- /dev/null +++ b/stylesheets/pygments.css @@ -0,0 +1,66 @@ +/* + pygmentize filter +*/ +.highlight .hll { background-color: #ffffcc } +.highlight { background: #f4f4f4; } +.highlight .c { color: #008800; font-style: italic } /* Comment */ +.highlight .err { border: 1px solid #FF0000 } /* Error */ +.highlight .k { color: #AA22FF; font-weight: bold } /* Keyword */ +.highlight .o { color: #666666 } /* Operator */ +.highlight .cm { color: #008800; font-style: italic } /* Comment.Multiline */ +.highlight .cp { color: #008800 } /* Comment.Preproc */ +.highlight .c1 { color: #008800; font-style: italic } /* Comment.Single */ +.highlight .cs { color: #008800; font-weight: bold } /* Comment.Special */ +.highlight .gd { color: #A00000 } /* Generic.Deleted */ +.highlight .ge { font-style: italic } /* Generic.Emph */ +.highlight .gr { color: #FF0000 } /* Generic.Error */ +.highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ +.highlight .gi { color: #00A000 } /* Generic.Inserted */ +.highlight .go { color: #808080 } /* Generic.Output */ +.highlight .gp { color: #000080; font-weight: bold } /* Generic.Prompt */ +.highlight .gs { font-weight: bold } /* Generic.Strong */ +.highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ +.highlight .gt { color: #0040D0 } /* Generic.Traceback */ +.highlight .kc { color: #AA22FF; font-weight: bold } /* Keyword.Constant */ +.highlight .kd { color: #AA22FF; font-weight: bold } /* Keyword.Declaration */ +.highlight .kn { color: #AA22FF; font-weight: bold } /* Keyword.Namespace */ +.highlight .kp { color: #AA22FF } /* Keyword.Pseudo */ +.highlight .kr { color: #AA22FF; font-weight: bold } /* Keyword.Reserved */ +.highlight .kt { color: #00BB00; font-weight: bold } /* Keyword.Type */ +.highlight .m { color: #666666 } /* Literal.Number */ +.highlight .s { color: #BB4444 } /* Literal.String */ +.highlight .na { color: #BB4444 } /* Name.Attribute */ +.highlight .nb { color: #AA22FF } /* Name.Builtin */ +.highlight .nc { color: #0000FF } /* Name.Class */ +.highlight .no { color: #880000 } /* Name.Constant */ +.highlight .nd { color: #AA22FF } /* Name.Decorator */ +.highlight .ni { color: #999999; font-weight: bold } /* Name.Entity */ +.highlight .ne { color: #D2413A; font-weight: bold } /* Name.Exception */ +.highlight .nf { color: #00A000 } /* Name.Function */ +.highlight .nl { color: #A0A000 } /* Name.Label */ +.highlight .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */ +.highlight .nt { color: #008000; font-weight: bold } /* Name.Tag */ +.highlight .nv { color: #B8860B } /* Name.Variable */ +.highlight .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */ +.highlight .w { color: #bbbbbb } /* Text.Whitespace */ +.highlight .mf { color: #666666 } /* Literal.Number.Float */ +.highlight .mh { color: #666666 } /* Literal.Number.Hex */ +.highlight .mi { color: #666666 } /* Literal.Number.Integer */ +.highlight .mo { color: #666666 } /* Literal.Number.Oct */ +.highlight .sb { color: #BB4444 } /* Literal.String.Backtick */ +.highlight .sc { color: #BB4444 } /* Literal.String.Char */ +.highlight .sd { color: #BB4444; font-style: italic } /* Literal.String.Doc */ +.highlight .s2 { color: #BB4444 } /* Literal.String.Double */ +.highlight .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */ +.highlight .sh { color: #BB4444 } /* Literal.String.Heredoc */ +.highlight .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */ +.highlight .sx { color: #008000 } /* Literal.String.Other */ +.highlight .sr { color: #BB6688 } /* Literal.String.Regex */ +.highlight .s1 { color: #BB4444 } /* Literal.String.Single */ +.highlight .ss { color: #B8860B } /* Literal.String.Symbol */ +.highlight .bp { color: #AA22FF } /* Name.Builtin.Pseudo */ +.highlight .vc { color: #B8860B } /* Name.Variable.Class */ +.highlight .vg { color: #B8860B } /* Name.Variable.Global */ +.highlight .vi { color: #B8860B } /* Name.Variable.Instance */ +.highlight .il { color: #666666 } /* Literal.Number.Integer.Long */ + diff --git a/xhtml11.conf b/xhtml11.conf index cd4acfa..2b29aa3 100644 --- a/xhtml11.conf +++ b/xhtml11.conf @@ -496,6 +496,7 @@ ifdef::quirks[] <link rel="stylesheet" href="{stylesdir=.}/{theme={backend}}-quirks.css" type="text/css" />
endif::quirks[]
<link rel="stylesheet" href="{stylesdir=.}/{stylesheet}" type="text/css" />
+ifdef::pygments[<link rel="stylesheet" href="{stylesdir=.}/pygments.css" type="text/css" />]
endif::linkcss[]
ifndef::linkcss[]
<style type="text/css">
@@ -507,6 +508,9 @@ ifdef::quirks[] include1::{stylesdir=./stylesheets}/{theme={backend}}-quirks.css[]
endif::quirks[]
include1::{stylesheet}[]
+ifdef::pygments[]
+include1::{stylesdir=./stylesheets}/pygments.css[]
+endif::pygments[]
</style>
endif::linkcss[]
ifndef::disable-javascript[]
|