Hi David

Thank you for your Pygments filter patch, I've installed it and it works perfectly (apologies for taking so long to reply).

What we are getting with the Pygments filter is more languages (64 in GNU source hightlight vs. 92 in Pygments) for xhtml11 highlighting. The downside is duplication (2 source highlight filters) and having to adding a page of additional CSS to every xhtml11 document. Also the source highlight filter works with both xhtml11 and html4 backends.

The callouts issue is because Pygments splits the callout markers into separate span elements so asciidoc cannot recognize them (not really Pygments fault since the language syntax is rendered invalid by the callouts).

To avoid duplication I think the pygments filter should be part of the existing source filter, this also simplifies the patch. If you want to use the Pygments for xhtml11 source highlighting all you need to do is define the 'pygments' attribute. I've also made the CSS (./stylesheets/pygments.css) inclusion conditional in the xhtml11 header so there's no unnecessary overhead in the output files.

I've committed the changes (http://code.google.com/p/asciidoc/source/detail?r=eaa5653fe5e17d0fdf16f78b0e503f788aebd4e6), is there anything I've missed?


Cheers, Stuart


On 21/07/10 08:07, David Hajage wrote:
Hello,

I am working on a patch to add a pygments filter to asciidoc
(www.pygments.org/ <http://pygments.org/>).

The patch is based on GNU source-highlight filter, and use pygments
command line interface ('pygmentize'). Pygmentize only generate xhtml
output, so the filter is inactive with html4 backend. I have also
modified xhtml stylesheets.

There is an issue with callouts:

asciidoc -v  pygmentize-filter.txt
asciidoc: reading: /home/david/bin/Asciidoc/asciidoc.conf
asciidoc: reading: /home/david/bin/Asciidoc/xhtml11.conf
asciidoc: reading: /home/david/bin/Asciidoc/xhtml11-quirks.conf
asciidoc: reading: /home/david/bin/Asciidoc/filters/code/code-filter.conf
asciidoc: reading:
/home/david/bin/Asciidoc/filters/pigmentize/pygmentize-filter.conf
asciidoc: reading: /home/david/bin/Asciidoc/filters/music/music-filter.conf
asciidoc: reading:
/home/david/bin/Asciidoc/filters/graphviz/graphviz-filter.conf
asciidoc: reading: /home/david/bin/Asciidoc/filters/latex/latex-filter.conf
asciidoc: reading:
/home/david/bin/Asciidoc/filters/source/source-highlight-filter.conf
asciidoc: reading: /home/david/bin/pygmentize-filter.txt
asciidoc: writing: /home/david/bin/pygmentize-filter.html
asciidoc: reading: /home/david/bin/Asciidoc/lang-en.conf
asciidoc: pygmentize-filter.txt: line 39: filtering: pygmentize -f html
-l python
asciidoc: pygmentize-filter.txt: line 44: filtering: pygmentize -f html
-l python
asciidoc: pygmentize-filter.txt: line 48: filtering: pygmentize -f html
-l ruby -O linenos=table
asciidoc: pygmentize-filter.txt: line 82: filtering: pygmentize -f html
-l python
asciidoc: pygmentize-filter.txt: line 162: filtering: pygmentize -f html
-l ruby -O linenos=table
*asciidoc: WARNING: pygmentize-filter.txt: line 165: no callouts refer
to list item 1*
*asciidoc: WARNING: pygmentize-filter.txt: line 166: no callouts refer
to list item 2*

I don't know what is going on here, so the patch could not be included
as it is. Does anyone have an advice? Unfortunately, I'm a very poor
programmer...

I am hoping you will accept this into the next version of asciidoc.

Thanks,

David Hajage

--
You received this message because you are subscribed to the Google
Groups "asciidoc" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/asciidoc?hl=en.


--
You received this message because you are subscribed to the Google Groups 
"asciidoc" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/asciidoc?hl=en.

diff -r f1cfaebbe6ca filters/source/source-highlight-filter.conf
--- a/filters/source/source-highlight-filter.conf       Sun Aug 01 22:21:49 
2010 +1200
+++ b/filters/source/source-highlight-filter.conf       Mon Aug 02 11:23:10 
2010 +1200
@@ -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 @@
 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 @@
 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 -r f1cfaebbe6ca stylesheets/pygments.css
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/stylesheets/pygments.css  Mon Aug 02 11:23:10 2010 +1200
@@ -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 -r f1cfaebbe6ca xhtml11.conf
--- a/xhtml11.conf      Sun Aug 01 22:21:49 2010 +1200
+++ b/xhtml11.conf      Mon Aug 02 11:23:10 2010 +1200
@@ -496,6 +496,7 @@
 <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 @@
 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[]

Reply via email to