summaryrefslogtreecommitdiff
path: root/doc/asciidoc/filters
diff options
context:
space:
mode:
authorChris Johns <chrisj@rtems.org>2014-02-17 18:04:46 +1100
committerChris Johns <chrisj@rtems.org>2014-02-17 18:04:46 +1100
commitf91e023fc4c68867e8ef9476ae28226feaa9929e (patch)
treec7daa4f99352fc45e27c5f5fa53d07b51292c14f /doc/asciidoc/filters
parent11d4b8976e9c5fa13c77faecc197cc9d1bc1ddfc (diff)
Add the documentation.
Diffstat (limited to 'doc/asciidoc/filters')
-rw-r--r--doc/asciidoc/filters/code/code-filter-readme.txt37
-rw-r--r--doc/asciidoc/filters/code/code-filter-test.txt15
-rw-r--r--doc/asciidoc/filters/code/code-filter.conf8
-rwxr-xr-xdoc/asciidoc/filters/code/code-filter.py239
-rw-r--r--doc/asciidoc/filters/graphviz/asciidoc-graphviz-sample.txt170
-rw-r--r--doc/asciidoc/filters/graphviz/graphviz-filter.conf53
-rwxr-xr-xdoc/asciidoc/filters/graphviz/graphviz2png.py169
-rw-r--r--doc/asciidoc/filters/latex/latex-filter.conf28
-rwxr-xr-xdoc/asciidoc/filters/latex/latex2png.py232
-rw-r--r--doc/asciidoc/filters/music/music-filter-test.txt40
-rw-r--r--doc/asciidoc/filters/music/music-filter.conf42
-rwxr-xr-xdoc/asciidoc/filters/music/music2png.py213
-rw-r--r--doc/asciidoc/filters/source/source-highlight-filter-test.txt19
-rw-r--r--doc/asciidoc/filters/source/source-highlight-filter.conf140
14 files changed, 1405 insertions, 0 deletions
diff --git a/doc/asciidoc/filters/code/code-filter-readme.txt b/doc/asciidoc/filters/code/code-filter-readme.txt
new file mode 100644
index 0000000..2a35f86
--- /dev/null
+++ b/doc/asciidoc/filters/code/code-filter-readme.txt
@@ -0,0 +1,37 @@
+AsciiDoc Code Filter
+====================
+
+This simple minded filter highlights source code keywords and
+comments.
+
+NOTE: The filter is to demonstrate how to write a filter -- it's much
+to simplistic to be passed off as a code syntax highlighter. If you
+want a full featured highlighter use the 'source highlighter filter.
+
+
+Files
+-----
+code-filter.py::
+ The filter Python script.
+code-filter.conf::
+ The AsciiDoc filter configuration file.
+code-filter-test.txt::
+ Short AsciiDoc document to test the filter.
+
+
+Installation
+------------
+The code filter is installed in the distribution `filters` directory
+as part of the standard AsciiDoc install.
+
+Test it on the `code-filter-test.txt` file:
+
+ $ asciidoc -v code-filter-test.txt
+ $ firefox code-filter-test.txt &
+
+
+Help
+----
+Execute the filter with the help option:
+
+ $ ./code-filter.py --help
diff --git a/doc/asciidoc/filters/code/code-filter-test.txt b/doc/asciidoc/filters/code/code-filter-test.txt
new file mode 100644
index 0000000..c9e8192
--- /dev/null
+++ b/doc/asciidoc/filters/code/code-filter-test.txt
@@ -0,0 +1,15 @@
+Code Filter Test
+================
+
+[python]
+code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+''' A multi-line
+ comment.'''
+def sub_word(mo):
+ ''' Single line comment.'''
+ word = mo.group('word') # Inline comment
+ if word in keywords[language]:
+ return quote + word + quote
+ else:
+ return word
+code~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/doc/asciidoc/filters/code/code-filter.conf b/doc/asciidoc/filters/code/code-filter.conf
new file mode 100644
index 0000000..5cdab96
--- /dev/null
+++ b/doc/asciidoc/filters/code/code-filter.conf
@@ -0,0 +1,8 @@
+#
+# AsciiDoc code filter configuration file.
+#
+# Documented in code-filter-readme.txt
+#
+
+[blockdef-listing]
+code-style=template="listingblock",presubs=(),postsubs=("callouts",),posattrs=("style","language"),filter="code-filter.py -b {basebackend} -l {language}"
diff --git a/doc/asciidoc/filters/code/code-filter.py b/doc/asciidoc/filters/code/code-filter.py
new file mode 100755
index 0000000..473fd6e
--- /dev/null
+++ b/doc/asciidoc/filters/code/code-filter.py
@@ -0,0 +1,239 @@
+#!/usr/bin/env python
+'''
+NAME
+ code-filter - AsciiDoc filter to highlight language keywords
+
+SYNOPSIS
+ code-filter -b backend -l language [ -t tabsize ]
+ [ --help | -h ] [ --version | -v ]
+
+DESCRIPTION
+ This filter reads source code from the standard input, highlights language
+ keywords and comments and writes to the standard output.
+
+ The purpose of this program is to demonstrate how to write an AsciiDoc
+ filter -- it's much to simplistic to be passed off as a code syntax
+ highlighter. Use the 'source-highlight-filter' instead.
+
+
+OPTIONS
+ --help, -h
+ Print this documentation.
+
+ -b
+ Backend output file format: 'docbook', 'linuxdoc', 'html', 'css'.
+
+ -l
+ The name of the source code language: 'python', 'ruby', 'c++', 'c'.
+
+ -t tabsize
+ Expand source tabs to tabsize spaces.
+
+ --version, -v
+ Print program version number.
+
+BUGS
+ - Code on the same line as a block comment is treated as comment.
+ Keywords inside literal strings are highlighted.
+ - There doesn't appear to be an easy way to accomodate linuxdoc so
+ just pass it through without markup.
+
+AUTHOR
+ Written by Stuart Rackham, <srackham@gmail.com>
+
+URLS
+ http://sourceforge.net/projects/asciidoc/
+ http://www.methods.co.nz/asciidoc/
+
+COPYING
+ Copyright (C) 2002-2006 Stuart Rackham. Free use of this software is
+ granted under the terms of the GNU General Public License (GPL).
+'''
+
+import os, sys, re, string
+
+VERSION = '1.1.2'
+
+# Globals.
+language = None
+backend = None
+tabsize = 8
+keywordtags = {
+ 'html':
+ ('<strong>','</strong>'),
+ 'css':
+ ('<strong>','</strong>'),
+ 'docbook':
+ ('<emphasis role="strong">','</emphasis>'),
+ 'linuxdoc':
+ ('','')
+}
+commenttags = {
+ 'html':
+ ('<i>','</i>'),
+ 'css':
+ ('<i>','</i>'),
+ 'docbook':
+ ('<emphasis>','</emphasis>'),
+ 'linuxdoc':
+ ('','')
+}
+keywords = {
+ 'python':
+ ('and', 'del', 'for', 'is', 'raise', 'assert', 'elif', 'from',
+ 'lambda', 'return', 'break', 'else', 'global', 'not', 'try', 'class',
+ 'except', 'if', 'or', 'while', 'continue', 'exec', 'import', 'pass',
+ 'yield', 'def', 'finally', 'in', 'print'),
+ 'ruby':
+ ('__FILE__', 'and', 'def', 'end', 'in', 'or', 'self', 'unless',
+ '__LINE__', 'begin', 'defined?' 'ensure', 'module', 'redo', 'super',
+ 'until', 'BEGIN', 'break', 'do', 'false', 'next', 'rescue', 'then',
+ 'when', 'END', 'case', 'else', 'for', 'nil', 'retry', 'true', 'while',
+ 'alias', 'class', 'elsif', 'if', 'not', 'return', 'undef', 'yield'),
+ 'c++':
+ ('asm', 'auto', 'bool', 'break', 'case', 'catch', 'char', 'class',
+ 'const', 'const_cast', 'continue', 'default', 'delete', 'do', 'double',
+ 'dynamic_cast', 'else', 'enum', 'explicit', 'export', 'extern',
+ 'false', 'float', 'for', 'friend', 'goto', 'if', 'inline', 'int',
+ 'long', 'mutable', 'namespace', 'new', 'operator', 'private',
+ 'protected', 'public', 'register', 'reinterpret_cast', 'return',
+ 'short', 'signed', 'sizeof', 'static', 'static_cast', 'struct',
+ 'switch', 'template', 'this', 'throw', 'true', 'try', 'typedef',
+ 'typeid', 'typename', 'union', 'unsigned', 'using', 'virtual', 'void',
+ 'volatile', 'wchar_t', 'while')
+}
+block_comments = {
+ 'python': ("'''","'''"),
+ 'ruby': None,
+ 'c++': ('/*','*/')
+}
+inline_comments = {
+ 'python': '#',
+ 'ruby': '#',
+ 'c++': '//'
+}
+
+def print_stderr(line):
+ sys.stderr.write(line+os.linesep)
+
+def sub_keyword(mo):
+ '''re.subs() argument to tag keywords.'''
+ word = mo.group('word')
+ if word in keywords[language]:
+ stag,etag = keywordtags[backend]
+ return stag+word+etag
+ else:
+ return word
+
+def code_filter():
+ '''This function does all the work.'''
+ global language, backend
+ inline_comment = inline_comments[language]
+ blk_comment = block_comments[language]
+ if blk_comment:
+ blk_comment = (re.escape(block_comments[language][0]),
+ re.escape(block_comments[language][1]))
+ stag,etag = commenttags[backend]
+ in_comment = 0 # True if we're inside a multi-line block comment.
+ tag_comment = 0 # True if we should tag the current line as a comment.
+ line = sys.stdin.readline()
+ while line:
+ line = string.rstrip(line)
+ line = string.expandtabs(line,tabsize)
+ # Escape special characters.
+ line = string.replace(line,'&','&amp;')
+ line = string.replace(line,'<','&lt;')
+ line = string.replace(line,'>','&gt;')
+ # Process block comment.
+ if blk_comment:
+ if in_comment:
+ if re.match(r'.*'+blk_comment[1]+r'$',line):
+ in_comment = 0
+ else:
+ if re.match(r'^\s*'+blk_comment[0]+r'.*'+blk_comment[1],line):
+ # Single line block comment.
+ tag_comment = 1
+ elif re.match(r'^\s*'+blk_comment[0],line):
+ # Start of multi-line block comment.
+ tag_comment = 1
+ in_comment = 1
+ else:
+ tag_comment = 0
+ if tag_comment:
+ if line: line = stag+line+etag
+ else:
+ if inline_comment:
+ pos = string.find(line,inline_comment)
+ else:
+ pos = -1
+ if pos >= 0:
+ # Process inline comment.
+ line = re.sub(r'\b(?P<word>\w+)\b',sub_keyword,line[:pos]) \
+ + stag + line[pos:] + etag
+ else:
+ line = re.sub(r'\b(?P<word>\w+)\b',sub_keyword,line)
+ sys.stdout.write(line + os.linesep)
+ line = sys.stdin.readline()
+
+def usage(msg=''):
+ if msg:
+ print_stderr(msg)
+ print_stderr('Usage: code-filter -b backend -l language [ -t tabsize ]')
+ print_stderr(' [ --help | -h ] [ --version | -v ]')
+
+def main():
+ global language, backend, tabsize
+ # Process command line options.
+ import getopt
+ opts,args = getopt.getopt(sys.argv[1:],
+ 'b:l:ht:v',
+ ['help','version'])
+ if len(args) > 0:
+ usage()
+ sys.exit(1)
+ for o,v in opts:
+ if o in ('--help','-h'):
+ print __doc__
+ sys.exit(0)
+ if o in ('--version','-v'):
+ print('code-filter version %s' % (VERSION,))
+ sys.exit(0)
+ if o == '-b': backend = v
+ if o == '-l':
+ v = string.lower(v)
+ if v == 'c': v = 'c++'
+ language = v
+ if o == '-t':
+ try:
+ tabsize = int(v)
+ except:
+ usage('illegal tabsize')
+ sys.exit(1)
+ if tabsize <= 0:
+ usage('illegal tabsize')
+ sys.exit(1)
+ if backend is None:
+ usage('backend option is mandatory')
+ sys.exit(1)
+ if not keywordtags.has_key(backend):
+ usage('illegal backend option')
+ sys.exit(1)
+ if language is None:
+ usage('language option is mandatory')
+ sys.exit(1)
+ if not keywords.has_key(language):
+ usage('illegal language option')
+ sys.exit(1)
+ # Do the work.
+ code_filter()
+
+if __name__ == "__main__":
+ try:
+ main()
+ except (KeyboardInterrupt, SystemExit):
+ pass
+ except:
+ print_stderr("%s: unexpected exit status: %s" %
+ (os.path.basename(sys.argv[0]), sys.exc_info()[1]))
+ # Exit with previous sys.exit() status or zero if no sys.exit().
+ sys.exit(sys.exc_info()[1])
diff --git a/doc/asciidoc/filters/graphviz/asciidoc-graphviz-sample.txt b/doc/asciidoc/filters/graphviz/asciidoc-graphviz-sample.txt
new file mode 100644
index 0000000..4be6ba9
--- /dev/null
+++ b/doc/asciidoc/filters/graphviz/asciidoc-graphviz-sample.txt
@@ -0,0 +1,170 @@
+= Graphviz filter for AsciiDoc =
+
+Author: Gouichi Iisaka
+
+Version: 1.1.3
+
+== Introduction ==
+
+The Graphviz(link:http://www.graphviz.org[]) is a way of representing structural information
+as diagrams of abstract graphs and networks.
+
+
+Automatic graph drawing has many important applications
+in software engineering, database and web design, networking,
+and in visual interfaces for many other domains.
+
+Graphviz take descriptions of graphs in a simple text language,
+And has many useful features for concrete diagrams,
+such as options for colors, fonts, tabular node layouts,
+line styles, hyperlinks, and custom shapes.
+
+AsciiDoc can external shell commands used to process Paragraph and
+DelimitedBlock content by Filter.
+
+So now, AsciiDoc can draw graphs via graphviz filter.
+
+== Examples ==
+
+=== Simple ===
+.....................................................................
+[graphviz]
+---------------------------------------------------------------------
+digraph G { rankdir=LR; Graphviz->AsciiDoc->HTML}
+---------------------------------------------------------------------
+.....................................................................
+
+[graphviz]
+---------------------------------------------------------------------
+digraph G { rankdir=LR; Graphviz->AsciiDoc->HTML}
+---------------------------------------------------------------------
+
+=== Using options ===
+.....................................................................
+["graphviz", "sample2.png"]
+---------------------------------------------------------------------
+digraph automata_0 {
+ size ="8.5, 11";
+ node [shape = circle];
+ 0 [ style = filled, color=lightgrey ];
+ 2 [ shape = doublecircle ];
+ 0 -> 2 [ label = "a " ];
+ 0 -> 1 [ label = "other " ];
+ 1 -> 2 [ label = "a " ];
+ 1 -> 1 [ label = "other " ];
+ 2 -> 2 [ label = "a " ];
+ 2 -> 1 [ label = "other " ];
+ "Machine: a" [ shape = plaintext ];
+}
+---------------------------------------------------------------------
+.....................................................................
+
+["graphviz", "sample2.png"]
+---------------------------------------------------------------------
+digraph automata_0 {
+ size ="8.5, 11";
+ node [shape = circle];
+ 0 [ style = filled, color=lightgrey ];
+ 2 [ shape = doublecircle ];
+ 0 -> 2 [ label = "a " ];
+ 0 -> 1 [ label = "other " ];
+ 1 -> 2 [ label = "a " ];
+ 1 -> 1 [ label = "other " ];
+ 2 -> 2 [ label = "a " ];
+ 2 -> 1 [ label = "other " ];
+ "Machine: a" [ shape = plaintext ];
+}
+---------------------------------------------------------------------
+
+=== Using Layout ===
+
+.....................................................................
+["graphviz", "sample3.png", "dot"]
+---------------------------------------------------------------------
+digraph finite_state_machine {
+ rankdir=LR;
+ size="8,5"
+ node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8;
+ node [shape = circle];
+ LR_0 -> LR_2 [ label = "SS(B)" ];
+ LR_0 -> LR_1 [ label = "SS(S)" ];
+ LR_1 -> LR_3 [ label = "S($end)" ];
+ LR_2 -> LR_6 [ label = "SS(b)" ];
+ LR_2 -> LR_5 [ label = "SS(a)" ];
+ LR_2 -> LR_4 [ label = "S(A)" ];
+ LR_5 -> LR_7 [ label = "S(b)" ];
+ LR_5 -> LR_5 [ label = "S(a)" ];
+ LR_6 -> LR_6 [ label = "S(b)" ];
+ LR_6 -> LR_5 [ label = "S(a)" ];
+ LR_7 -> LR_8 [ label = "S(b)" ];
+ LR_7 -> LR_5 [ label = "S(a)" ];
+ LR_8 -> LR_6 [ label = "S(b)" ];
+ LR_8 -> LR_5 [ label = "S(a)" ];
+}
+---------------------------------------------------------------------
+.....................................................................
+
+["graphviz", "sample3.png", "dot"]
+---------------------------------------------------------------------
+digraph finite_state_machine {
+ rankdir=LR;
+ size="8,5"
+ node [shape = doublecircle]; LR_0 LR_3 LR_4 LR_8;
+ node [shape = circle];
+ LR_0 -> LR_2 [ label = "SS(B)" ];
+ LR_0 -> LR_1 [ label = "SS(S)" ];
+ LR_1 -> LR_3 [ label = "S($end)" ];
+ LR_2 -> LR_6 [ label = "SS(b)" ];
+ LR_2 -> LR_5 [ label = "SS(a)" ];
+ LR_2 -> LR_4 [ label = "S(A)" ];
+ LR_5 -> LR_7 [ label = "S(b)" ];
+ LR_5 -> LR_5 [ label = "S(a)" ];
+ LR_6 -> LR_6 [ label = "S(b)" ];
+ LR_6 -> LR_5 [ label = "S(a)" ];
+ LR_7 -> LR_8 [ label = "S(b)" ];
+ LR_7 -> LR_5 [ label = "S(a)" ];
+ LR_8 -> LR_6 [ label = "S(b)" ];
+ LR_8 -> LR_5 [ label = "S(a)" ];
+ }
+---------------------------------------------------------------------
+
+
+== Layout ==
+
+Layout for graphviz as follows. The default is `dot'.
+
+ *dot;;
+ 'dot' draws directed graphs.
+ It works well on DAGs and other graphs that can be drawn as hierarchies.
+ It reads attributed graph files and writes drawings.
+
+ *neato;;
+ 'neato' draws undirected graphs using ‘‘spring'' models (see Kamada and
+ Kawai, Information Processing Letters 31:1, April 1989).
+ Input files must be formatted in the dot attributed graph language.
+
+ *twopi;;
+ 'twopi' draws graphs using a radial layout (see G. Wills, Symposium on
+ Graph Drawing GD'97, September, 1997).
+ Basically, one node is chosen as the center and put at the origin.
+ The remaining nodes are placed on a sequence of concentric circles
+ centered about the origin, each a fixed radial distance from
+ the previous circle.
+
+ *circro;;
+ 'circo' draws graphs using a circular layout (see Six and Tollis, GD '99
+ and ALENEX '99, and Kaufmann and Wiese, GD '02.)
+ The tool identifies biconnected components and draws the nodes
+ of the component on a circle.
+ The block‐cutpoint tree is then laid out using a recursive radial
+ algorithm.
+ Edge crossings within a circle are minimized by placing as
+ many edges on the circle's perimeter as possible.
+ In particular, if the component is outerplanar,
+ the component will have a planar layout.
+
+ *fdp;;
+ 'fdp' draws undirected graphs using a ‘‘spring'' model.
+ It relies on a force‐directed approach in the spirit of Fruchterman
+ and Reingold
+ (cf. Software‐Practice & Experience 21(11), 1991, pp. 1129‐1164).
diff --git a/doc/asciidoc/filters/graphviz/graphviz-filter.conf b/doc/asciidoc/filters/graphviz/graphviz-filter.conf
new file mode 100644
index 0000000..f1ca264
--- /dev/null
+++ b/doc/asciidoc/filters/graphviz/graphviz-filter.conf
@@ -0,0 +1,53 @@
+#
+# AsciiDoc Graphviz filter configuration file.
+#
+# Version: 1.0
+# Gouici Iisaka <iisaka51 at gmail dot com>
+
+[graphviz-filter-style]
+# When the filter output image is data-uri encoded write it to the indir
+# (instead of the outdir) so that encoder can find it.
+ifndef::data-uri[]
+graphviz-style=template="graphviz{format?-{format}}-block",subs=(),posattrs=("style","target","layout","format"),filter='graphviz2png.py {verbose?-v} -o "{outdir={indir}}/{imagesdir=}{imagesdir?/}{target}" -L {layout=dot} -F {format=png} -'
+endif::data-uri[]
+ifdef::data-uri[]
+graphviz-style=template="graphviz{format?-{format}}-block",subs=(),posattrs=("style","target","layout","format"),filter='graphviz2png.py {verbose?-v} -o "{indir={outdir}}/{imagesdir=}{imagesdir?/}{target}" -L {layout=dot} -F {format=png} -'
+endif::data-uri[]
+
+[blockdef-open]
+template::[graphviz-filter-style]
+
+[blockdef-listing]
+template::[graphviz-filter-style]
+
+[paradef-default]
+template::[graphviz-filter-style]
+
+[graphviz-block]
+template::[filter-image-blockmacro]
+
+# EXPERIMENTAL: xhtml11 backend SVG image block.
+ifdef::basebackend-xhtml11[]
+[graphviz-svg-block]
+<div class="imageblock"{id? id="{id}"}{align? style="text-align:{align};"}{float? style="float:{float};"}>
+<div class="content">
+<a class="image" href="{link}">
+<object data="{imagesdir=}{imagesdir?/}{target}" type="image/svg+xml" />
+{link#}</a>
+</div>
+<div class="title">{caption={figure-caption} {counter:figure-number}. }{title}</div>
+</div>
+endif::basebackend-xhtml11[]
+
+#
+# DEPRECATED: Pre 8.2.7 filter definition.
+#
+[blockdef-graphviz]
+delimiter=^graphviz~{4,}$
+template=graphviz-block
+presubs=none
+filter=graphviz2png.py {verbose?-v} -o "{outdir={indir}}/{target}" -L {layout=dot} -
+posattrs=target,format
+#
+# DEPRECATED: End
+#
diff --git a/doc/asciidoc/filters/graphviz/graphviz2png.py b/doc/asciidoc/filters/graphviz/graphviz2png.py
new file mode 100755
index 0000000..a3d43f5
--- /dev/null
+++ b/doc/asciidoc/filters/graphviz/graphviz2png.py
@@ -0,0 +1,169 @@
+#!/usr/bin/env python
+
+import os, sys, subprocess
+from optparse import *
+
+__AUTHOR__ = "Gouichi Iisaka <iisaka51@gmail.com>"
+__VERSION__ = '1.1.4'
+
+class EApp(Exception):
+ '''Application specific exception.'''
+ pass
+
+class Application():
+ '''
+NAME
+ graphviz2png - Converts textual graphviz notation to PNG file
+
+SYNOPSIS
+ graphviz2png [options] INFILE
+
+DESCRIPTION
+ This filter reads Graphviz notation text from the input file
+ INFILE (or stdin if INFILE is -), converts it to a PNG image file.
+
+
+OPTIONS
+ -o OUTFILE, --outfile=OUTFILE
+ The file name of the output file. If not specified the output file is
+ named like INFILE but with a .png file name extension.
+
+ -L LAYOUT, --layout=LAYOUT
+ Graphviz layout: dot, neato, twopi, circo, fdp
+ Default is 'dot'.
+
+ -F FORMAT, --format=FORMAT
+ Graphviz output format: png, svg, or any other format Graphviz
+ supports. Run dot -T? to get the full list.
+ Default is 'png'.
+
+ -v, --verbose
+ Verbosely print processing information to stderr.
+
+ -h, --help
+ Print this documentation.
+
+ -V, --version
+ Print program version number.
+
+SEE ALSO
+ graphviz(1)
+
+AUTHOR
+ Written by Gouichi Iisaka, <iisaka51@gmail.com>
+ Format support added by Elmo Todurov, <todurov@gmail.com>
+
+THANKS
+ Stuart Rackham, <srackham@gmail.com>
+ This script was inspired by his music2png.py and AsciiDoc
+
+LICENSE
+ Copyright (C) 2008-2009 Gouichi Iisaka.
+ Free use of this software is granted under the terms of
+ the GNU General Public License (GPL).
+ '''
+
+ def __init__(self, argv=None):
+ # Run dot, get the list of supported formats. It's prefixed by some junk.
+ format_output = subprocess.Popen(["dot", "-T?"], stderr=subprocess.PIPE, stdout=subprocess.PIPE).communicate()[1]
+ # The junk contains : and ends with :. So we split it, then strip the final endline, then split the list for future usage.
+ supported_formats = format_output.split(": ")[2][:-1].split(" ")
+
+ if not argv:
+ argv = sys.argv
+
+ self.usage = '%prog [options] inputfile'
+ self.version = 'Version: %s\n' % __VERSION__
+ self.version += 'Copyright(c) 2008-2009: %s\n' % __AUTHOR__
+
+ self.option_list = [
+ Option("-o", "--outfile", action="store",
+ dest="outfile",
+ help="Output file"),
+ Option("-L", "--layout", action="store",
+ dest="layout", default="dot", type="choice",
+ choices=['dot','neato','twopi','circo','fdp'],
+ help="Layout type. LAYOUT=<dot|neato|twopi|circo|fdp>"),
+ Option("-F", "--format", action="store",
+ dest="format", default="png", type="choice",
+ choices=supported_formats,
+ help="Format type. FORMAT=<" + "|".join(supported_formats) + ">"),
+ Option("--debug", action="store_true",
+ dest="do_debug",
+ help=SUPPRESS_HELP),
+ Option("-v", "--verbose", action="store_true",
+ dest="do_verbose", default=False,
+ help="verbose output"),
+ ]
+
+ self.parser = OptionParser( usage=self.usage, version=self.version,
+ option_list=self.option_list)
+ (self.options, self.args) = self.parser.parse_args()
+
+ if len(self.args) != 1:
+ self.parser.print_help()
+ sys.exit(1)
+
+ self.options.infile = self.args[0]
+
+ def systemcmd(self, cmd):
+ if self.options.do_verbose:
+ msg = 'Execute: %s' % cmd
+ sys.stderr.write(msg + os.linesep)
+ else:
+ cmd += ' 2>%s' % os.devnull
+ if os.system(cmd):
+ raise EApp, 'failed command: %s' % cmd
+
+ def graphviz2png(self, infile, outfile):
+ '''Convert Graphviz notation in file infile to
+ PNG file named outfile.'''
+
+ outfile = os.path.abspath(outfile)
+ outdir = os.path.dirname(outfile)
+
+ if not os.path.isdir(outdir):
+ raise EApp, 'directory does not exist: %s' % outdir
+
+ basefile = os.path.splitext(outfile)[0]
+ saved_cwd = os.getcwd()
+ os.chdir(outdir)
+ try:
+ cmd = '%s -T%s "%s" > "%s"' % (
+ self.options.layout, self.options.format, infile, outfile)
+ self.systemcmd(cmd)
+ finally:
+ os.chdir(saved_cwd)
+
+ if not self.options.do_debug:
+ os.unlink(infile)
+
+ def run(self):
+ if self.options.format == '':
+ self.options.format = 'png'
+
+ if self.options.infile == '-':
+ if self.options.outfile is None:
+ sys.stderr.write('OUTFILE must be specified')
+ sys.exit(1)
+ infile = os.path.splitext(self.options.outfile)[0] + '.txt'
+ lines = sys.stdin.readlines()
+ open(infile, 'w').writelines(lines)
+
+ if not os.path.isfile(infile):
+ raise EApp, 'input file does not exist: %s' % infile
+
+ if self.options.outfile is None:
+ outfile = os.path.splitext(infile)[0] + '.png'
+ else:
+ outfile = self.options.outfile
+
+ self.graphviz2png(infile, outfile)
+
+ # To suppress asciidoc 'no output from filter' warnings.
+ if self.options.infile == '-':
+ sys.stdout.write(' ')
+
+if __name__ == "__main__":
+ app = Application()
+ app.run()
diff --git a/doc/asciidoc/filters/latex/latex-filter.conf b/doc/asciidoc/filters/latex/latex-filter.conf
new file mode 100644
index 0000000..93c09e4
--- /dev/null
+++ b/doc/asciidoc/filters/latex/latex-filter.conf
@@ -0,0 +1,28 @@
+#
+# AsciiDoc latex filter configuration file.
+#
+# Documented in latex-filter.txt in AsciiDoc distribution
+# ./examples/website/ directory.
+#
+
+[latex-filter-style]
+# When the filter output image is data-uri encoded write it to the indir
+# (instead of the outdir) so that encoder can find it.
+ifndef::data-uri[]
+latex-style=template="latex-block",subs=(),posattrs=("style","target","dpi"),filter='latex2png.py -m{verbose? -v}{dpi? -D {dpi}} -o "{outdir={indir}}/{imagesdir=}{imagesdir?/}{target}" -'
+endif::data-uri[]
+ifdef::data-uri[]
+latex-style=template="latex-block",subs=(),posattrs=("style","target","dpi"),filter='latex2png.py -m{verbose? -v}{dpi? -D {dpi}} -o "{indir={outdir}}/{imagesdir=}{imagesdir?/}{target}" -'
+endif::data-uri[]
+
+[blockdef-open]
+template::[latex-filter-style]
+
+[blockdef-listing]
+template::[latex-filter-style]
+
+[paradef-default]
+template::[latex-filter-style]
+
+[latex-block]
+template::[filter-image-blockmacro]
diff --git a/doc/asciidoc/filters/latex/latex2png.py b/doc/asciidoc/filters/latex/latex2png.py
new file mode 100755
index 0000000..3cae7c9
--- /dev/null
+++ b/doc/asciidoc/filters/latex/latex2png.py
@@ -0,0 +1,232 @@
+#!/usr/bin/env python
+'''
+NAME
+ latex2png - Converts LaTeX source to PNG file
+
+SYNOPSIS
+ latex2png [options] INFILE
+
+DESCRIPTION
+ This filter reads LaTeX source text from the input file
+ INFILE (or stdin if INFILE is -) and renders it to PNG image file.
+ Typically used to render math equations.
+
+ Requires latex(1), dvipng(1) commands and LaTeX math packages.
+
+OPTIONS
+ -D DPI
+ Set the output resolution to DPI dots per inch. Use this option to
+ scale the output image size.
+
+ -o OUTFILE
+ The file name of the output file. If not specified the output file is
+ named like INFILE but with a .png file name extension.
+
+ -m
+ Skip if the PNG output file is newer that than the INFILE.
+ Compares timestamps on INFILE and OUTFILE. If
+ INFILE is - (stdin) then compares MD5 checksum stored in file
+ named like OUTFILE but with a .md5 file name extension.
+ The .md5 file is created if the -m option is used and the
+ INFILE is - (stdin).
+
+ -v
+ Verbosely print processing information to stderr.
+
+ --help, -h
+ Print this documentation.
+
+ --version
+ Print program version number.
+
+SEE ALSO
+ latex(1), dvipng(1)
+
+AUTHOR
+ Written by Stuart Rackham, <srackham@gmail.com>
+ The code was inspired by Kjell Magne Fauske's code:
+ http://fauskes.net/nb/htmleqII/
+
+ See also:
+ http://www.amk.ca/python/code/mt-math
+ http://code.google.com/p/latexmath2png/
+
+COPYING
+ Copyright (C) 2010 Stuart Rackham. Free use of this software is
+ granted under the terms of the MIT License.
+'''
+
+# Suppress warning: "the md5 module is deprecated; use hashlib instead"
+import warnings
+warnings.simplefilter('ignore',DeprecationWarning)
+
+import os, sys, tempfile, md5
+
+VERSION = '0.1.0'
+
+# Include LaTeX packages and commands here.
+TEX_HEADER = r'''\documentclass{article}
+\usepackage{amsmath}
+\usepackage{amsthm}
+\usepackage{amssymb}
+\usepackage{bm}
+\newcommand{\mx}[1]{\mathbf{\bm{#1}}} % Matrix command
+\newcommand{\vc}[1]{\mathbf{\bm{#1}}} % Vector command
+\newcommand{\T}{\text{T}} % Transpose
+\pagestyle{empty}
+\begin{document}'''
+
+TEX_FOOTER = r'''\end{document}'''
+
+# Globals.
+verbose = False
+
+class EApp(Exception): pass # Application specific exception.
+
+def print_stderr(line):
+ sys.stderr.write(line + os.linesep)
+
+def print_verbose(line):
+ if verbose:
+ print_stderr(line)
+
+def write_file(filename, data, mode='w'):
+ f = open(filename, mode)
+ try:
+ f.write(data)
+ finally:
+ f.close()
+
+def read_file(filename, mode='r'):
+ f = open(filename, mode)
+ try:
+ return f.read()
+ finally:
+ f.close()
+
+def run(cmd):
+ global verbose
+ if verbose:
+ cmd += ' 1>&2'
+ else:
+ cmd += ' 2>%s 1>&2' % os.devnull
+ print_verbose('executing: %s' % cmd)
+ if os.system(cmd):
+ raise EApp, 'failed command: %s' % cmd
+
+def latex2png(infile, outfile, dpi, modified):
+ '''Convert LaTeX input file infile to PNG file named outfile.'''
+ outfile = os.path.abspath(outfile)
+ outdir = os.path.dirname(outfile)
+ if not os.path.isdir(outdir):
+ raise EApp, 'directory does not exist: %s' % outdir
+ texfile = tempfile.mktemp(suffix='.tex', dir=os.path.dirname(outfile))
+ basefile = os.path.splitext(texfile)[0]
+ dvifile = basefile + '.dvi'
+ temps = [basefile + ext for ext in ('.tex','.dvi', '.aux', '.log')]
+ skip = False
+ if infile == '-':
+ tex = sys.stdin.read()
+ if modified:
+ checksum = md5.new(tex).digest()
+ md5_file = os.path.splitext(outfile)[0] + '.md5'
+ if os.path.isfile(md5_file) and os.path.isfile(outfile) and \
+ checksum == read_file(md5_file,'rb'):
+ skip = True
+ else:
+ if not os.path.isfile(infile):
+ raise EApp, 'input file does not exist: %s' % infile
+ tex = read_file(infile)
+ if modified and os.path.isfile(outfile) and \
+ os.path.getmtime(infile) <= os.path.getmtime(outfile):
+ skip = True
+ if skip:
+ print_verbose('skipped: no change: %s' % outfile)
+ return
+ tex = '%s\n%s\n%s\n' % (TEX_HEADER, tex.strip(), TEX_FOOTER)
+ print_verbose('tex:\n%s' % tex)
+ write_file(texfile, tex)
+ saved_pwd = os.getcwd()
+ os.chdir(outdir)
+ try:
+ # Compile LaTeX document to DVI file.
+ run('latex %s' % texfile)
+ # Convert DVI file to PNG.
+ cmd = 'dvipng'
+ if dpi:
+ cmd += ' -D %s' % dpi
+ cmd += ' -T tight -x 1000 -z 9 -bg Transparent --truecolor -o "%s" "%s" ' \
+ % (outfile,dvifile)
+ run(cmd)
+ finally:
+ os.chdir(saved_pwd)
+ for f in temps:
+ if os.path.isfile(f):
+ print_verbose('deleting: %s' % f)
+ os.remove(f)
+ if 'md5_file' in locals():
+ print_verbose('writing: %s' % md5_file)
+ write_file(md5_file, checksum, 'wb')
+
+def usage(msg=''):
+ if msg:
+ print_stderr(msg)
+ print_stderr('\n'
+ 'usage:\n'
+ ' latex2png [options] INFILE\n'
+ '\n'
+ 'options:\n'
+ ' -D DPI\n'
+ ' -o OUTFILE\n'
+ ' -m\n'
+ ' -v\n'
+ ' --help\n'
+ ' --version')
+
+def main():
+ # Process command line options.
+ global verbose
+ dpi = None
+ outfile = None
+ modified = False
+ import getopt
+ opts,args = getopt.getopt(sys.argv[1:], 'D:o:mhv', ['help','version'])
+ for o,v in opts:
+ if o in ('--help','-h'):
+ print __doc__
+ sys.exit(0)
+ if o =='--version':
+ print('latex2png version %s' % (VERSION,))
+ sys.exit(0)
+ if o == '-D': dpi = v
+ if o == '-o': outfile = v
+ if o == '-m': modified = True
+ if o == '-v': verbose = True
+ if len(args) != 1:
+ usage()
+ sys.exit(1)
+ infile = args[0]
+ if dpi and not dpi.isdigit():
+ usage('invalid DPI')
+ sys.exit(1)
+ if outfile is None:
+ if infile == '-':
+ usage('OUTFILE must be specified')
+ sys.exit(1)
+ outfile = os.path.splitext(infile)[0] + '.png'
+ # Do the work.
+ latex2png(infile, outfile, dpi, modified)
+ # Print something to suppress asciidoc 'no output from filter' warnings.
+ if infile == '-':
+ sys.stdout.write(' ')
+
+if __name__ == "__main__":
+ try:
+ main()
+ except SystemExit:
+ raise
+ except KeyboardInterrupt:
+ sys.exit(1)
+ except Exception, e:
+ print_stderr("%s: %s" % (os.path.basename(sys.argv[0]), str(e)))
+ sys.exit(1)
diff --git a/doc/asciidoc/filters/music/music-filter-test.txt b/doc/asciidoc/filters/music/music-filter-test.txt
new file mode 100644
index 0000000..c1886bd
--- /dev/null
+++ b/doc/asciidoc/filters/music/music-filter-test.txt
@@ -0,0 +1,40 @@
+Music Filter Test
+=================
+
+Details of the filter can be found in `./doc/music-filter.txt`.
+
+
+A tune generated from ABC notation
+----------------------------------
+
+[music,music1.png]
+---------------------------------------------------------------------
+T:The Butterfly
+R:slip jig
+C:Tommy Potts
+H:Fiddle player Tommy Potts made this tune from two older slip jigs,
+H:one of which is called "Skin the Peelers" in Roche's collection.
+D:Bothy Band: 1975.
+M:9/8
+K:Em
+vB2(E G2)(E F3)|B2(E G2)(E F)ED|vB2(E G2)(E F3)|(B2d) d2(uB A)FD:|
+|:(vB2c) (e2f) g3|(uB2d) (g2e) (dBA)|(B2c) (e2f) g2(ua|b2a) (g2e) (dBA):|
+|:~B3 (B2A) G2A|~B3 BA(uB d)BA|~B3 (B2A) G2(A|B2d) (g2e) (dBA):|
+---------------------------------------------------------------------
+
+
+A fragment generated from LilyPond source
+------------------------------------------
+
+["music", "music2.png", "ly", link="music2.ly"]
+---------------------------------------------------------------------
+\version "2.10.0"
+\paper {
+ ragged-right = ##t
+}
+{
+ \time 3/4
+ \clef bass
+ c2 e4 g2. f4 e d c2 r4
+}
+---------------------------------------------------------------------
diff --git a/doc/asciidoc/filters/music/music-filter.conf b/doc/asciidoc/filters/music/music-filter.conf
new file mode 100644
index 0000000..eaafe97
--- /dev/null
+++ b/doc/asciidoc/filters/music/music-filter.conf
@@ -0,0 +1,42 @@
+#
+# AsciiDoc music filter configuration file.
+#
+# Documented in music-filter.txt in AsciiDoc distribution
+# ./examples/website/ directory.
+#
+
+[music-filter-style]
+
+# When the filter output image is data-uri encoded write it to the indir
+# (instead of the outdir) so that encoder can find it.
+ifndef::data-uri[]
+music-style=template="music-block",subs=(),posattrs=("style","target","format"),filter='music2png.py -m{verbose? -v}{format? -f {format}} -o "{outdir={indir}}/{imagesdir=}{imagesdir?/}{target}" -'
+endif::data-uri[]
+ifdef::data-uri[]
+music-style=template="music-block",subs=(),posattrs=("style","target","format"),filter='music2png.py -m{verbose? -v}{format? -f {format}} -o "{indir={outdir}}/{imagesdir=}{imagesdir?/}{target}" -'
+endif::data-uri[]
+
+[blockdef-open]
+template::[music-filter-style]
+
+[blockdef-listing]
+template::[music-filter-style]
+
+[paradef-default]
+template::[music-filter-style]
+
+[music-block]
+template::[filter-image-blockmacro]
+
+#
+# DEPRECATED: Pre 8.2.7 filter definition.
+#
+[blockdef-music]
+delimiter=^music~{4,}$
+template=music-block
+presubs=none
+filter=music2png.py{verbose? -v} -f {format=abc} -o "{outdir={indir}}/{imagesdir=}{imagesdir?/}{target}" -
+posattrs=target,format
+#
+# DEPRECATED: End
+#
diff --git a/doc/asciidoc/filters/music/music2png.py b/doc/asciidoc/filters/music/music2png.py
new file mode 100755
index 0000000..a0224df
--- /dev/null
+++ b/doc/asciidoc/filters/music/music2png.py
@@ -0,0 +1,213 @@
+#!/usr/bin/env python
+'''
+NAME
+ music2png - Converts textual music notation to classically notated PNG file
+
+SYNOPSIS
+ music2png [options] INFILE
+
+DESCRIPTION
+ This filter reads LilyPond or ABC music notation text from the input file
+ INFILE (or stdin if INFILE is -), converts it to classical music notation
+ and writes it to a trimmed PNG image file.
+
+ This script is a wrapper for LilyPond and ImageMagick commands.
+
+OPTIONS
+ -f FORMAT
+ The INFILE music format. 'abc' for ABC notation, 'ly' for LilyPond
+ notation. Defaults to 'abc' unless source starts with backslash.
+
+ -o OUTFILE
+ The file name of the output file. If not specified the output file is
+ named like INFILE but with a .png file name extension.
+
+ -m
+ Skip if the PNG output file is newer that than the INFILE.
+ Compares timestamps on INFILE and OUTFILE. If
+ INFILE is - (stdin) then compares MD5 checksum stored in file
+ named like OUTFILE but with a .md5 file name extension.
+ The .md5 file is created if the -m option is used and the
+ INFILE is - (stdin).
+
+ -v
+ Verbosely print processing information to stderr.
+
+ --help, -h
+ Print this documentation.
+
+ --version
+ Print program version number.
+
+SEE ALSO
+ lilypond(1), abc2ly(1), convert(1)
+
+AUTHOR
+ Written by Stuart Rackham, <srackham@gmail.com>
+
+COPYING
+ Copyright (C) 2006 Stuart Rackham. Free use of this software is
+ granted under the terms of the GNU General Public License (GPL).
+'''
+
+# Suppress warning: "the md5 module is deprecated; use hashlib instead"
+import warnings
+warnings.simplefilter('ignore',DeprecationWarning)
+
+import os, sys, tempfile, md5
+
+VERSION = '0.1.2'
+
+# Globals.
+verbose = False
+
+class EApp(Exception): pass # Application specific exception.
+
+def print_stderr(line):
+ sys.stderr.write(line + os.linesep)
+
+def print_verbose(line):
+ if verbose:
+ print_stderr(line)
+
+def write_file(filename, data, mode='w'):
+ f = open(filename, mode)
+ try:
+ f.write(data)
+ finally:
+ f.close()
+
+def read_file(filename, mode='r'):
+ f = open(filename, mode)
+ try:
+ return f.read()
+ finally:
+ f.close()
+
+def run(cmd):
+ global verbose
+ if not verbose:
+ cmd += ' 2>%s' % os.devnull
+ print_verbose('executing: %s' % cmd)
+ if os.system(cmd):
+ raise EApp, 'failed command: %s' % cmd
+
+def music2png(format, infile, outfile, modified):
+ '''Convert ABC notation in file infile to cropped PNG file named outfile.'''
+ outfile = os.path.abspath(outfile)
+ outdir = os.path.dirname(outfile)
+ if not os.path.isdir(outdir):
+ raise EApp, 'directory does not exist: %s' % outdir
+ basefile = tempfile.mktemp(dir=os.path.dirname(outfile))
+ temps = [basefile + ext for ext in ('.abc', '.ly', '.ps', '.midi')]
+ skip = False
+ if infile == '-':
+ source = sys.stdin.read()
+ checksum = md5.new(source).digest()
+ filename = os.path.splitext(outfile)[0] + '.md5'
+ if modified:
+ if os.path.isfile(filename) and os.path.isfile(outfile) and \
+ checksum == read_file(filename,'rb'):
+ skip = True
+ else:
+ write_file(filename, checksum, 'wb')
+ else:
+ if not os.path.isfile(infile):
+ raise EApp, 'input file does not exist: %s' % infile
+ if modified and os.path.isfile(outfile) and \
+ os.path.getmtime(infile) <= os.path.getmtime(outfile):
+ skip = True
+ source = read_file(infile)
+ if skip:
+ print_verbose('skipped: no change: %s' % outfile)
+ return
+ if format is None:
+ if source and source.startswith('\\'): # Guess input format.
+ format = 'ly'
+ else:
+ format = 'abc'
+ # Write temporary source file.
+ write_file('%s.%s' % (basefile,format), source)
+ abc = basefile + '.abc'
+ ly = basefile + '.ly'
+ png = basefile + '.png'
+ saved_pwd = os.getcwd()
+ os.chdir(outdir)
+ try:
+ if format == 'abc':
+ run('abc2ly -o "%s" "%s"' % (ly,abc))
+ run('lilypond --png -o "%s" "%s"' % (basefile,ly))
+ os.rename(png, outfile)
+ finally:
+ os.chdir(saved_pwd)
+ # Chop the bottom 75 pixels off to get rid of the page footer then crop the
+ # music image. The -strip option necessary because FOP does not like the
+ # custom PNG color profile used by Lilypond.
+ run('convert "%s" -strip -gravity South -chop 0x75 -trim "%s"' % (outfile, outfile))
+ for f in temps:
+ if os.path.isfile(f):
+ print_verbose('deleting: %s' % f)
+ os.remove(f)
+
+def usage(msg=''):
+ if msg:
+ print_stderr(msg)
+ print_stderr('\n'
+ 'usage:\n'
+ ' music2png [options] INFILE\n'
+ '\n'
+ 'options:\n'
+ ' -f FORMAT\n'
+ ' -o OUTFILE\n'
+ ' -m\n'
+ ' -v\n'
+ ' --help\n'
+ ' --version')
+
+def main():
+ # Process command line options.
+ global verbose
+ format = None
+ outfile = None
+ modified = False
+ import getopt
+ opts,args = getopt.getopt(sys.argv[1:], 'f:o:mhv', ['help','version'])
+ for o,v in opts:
+ if o in ('--help','-h'):
+ print __doc__
+ sys.exit(0)
+ if o =='--version':
+ print('music2png version %s' % (VERSION,))
+ sys.exit(0)
+ if o == '-f': format = v
+ if o == '-o': outfile = v
+ if o == '-m': modified = True
+ if o == '-v': verbose = True
+ if len(args) != 1:
+ usage()
+ sys.exit(1)
+ infile = args[0]
+ if format not in (None, 'abc', 'ly'):
+ usage('invalid FORMAT')
+ sys.exit(1)
+ if outfile is None:
+ if infile == '-':
+ usage('OUTFILE must be specified')
+ sys.exit(1)
+ outfile = os.path.splitext(infile)[0] + '.png'
+ # Do the work.
+ music2png(format, infile, outfile, modified)
+ # Print something to suppress asciidoc 'no output from filter' warnings.
+ if infile == '-':
+ sys.stdout.write(' ')
+
+if __name__ == "__main__":
+ try:
+ main()
+ except SystemExit:
+ raise
+ except KeyboardInterrupt:
+ sys.exit(1)
+ except Exception, e:
+ print_stderr("%s: %s" % (os.path.basename(sys.argv[0]), str(e)))
+ sys.exit(1)
diff --git a/doc/asciidoc/filters/source/source-highlight-filter-test.txt b/doc/asciidoc/filters/source/source-highlight-filter-test.txt
new file mode 100644
index 0000000..cd2390c
--- /dev/null
+++ b/doc/asciidoc/filters/source/source-highlight-filter-test.txt
@@ -0,0 +1,19 @@
+Source Hightlight Filter Test
+=============================
+
+Details of the filter can be found in
+`./doc/source-highlight-filter.txt`.
+
+[source,python]
+---------------------------------------------------------------------
+''' A multi-line
+ comment.'''
+def sub_word(mo):
+ ''' Single line comment.'''
+ word = mo.group('word') # Inline comment
+ if word in keywords[language]:
+ return quote + word + quote
+ else:
+ return word
+---------------------------------------------------------------------
+
diff --git a/doc/asciidoc/filters/source/source-highlight-filter.conf b/doc/asciidoc/filters/source/source-highlight-filter.conf
new file mode 100644
index 0000000..efe4dbe
--- /dev/null
+++ b/doc/asciidoc/filters/source/source-highlight-filter.conf
@@ -0,0 +1,140 @@
+#
+# AsciiDoc source code highlight filter configuration file.
+#
+# Documented in source-hightlight-filter.txt in AsciiDoc distribution
+# ./examples/website/ directory.
+#
+# 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
+########################
+[source-highlight-block]
+template::[listingblock]
+
+ifdef::basebackend-html[]
+[source-highlight-block]
+<a name="{id}"></a>
+<p><b>{title}</b></p>
+<table{role? class="{role}"} border="0" bgcolor="#e8e8e8" width="100%" cellpadding="10"><tr><td>
+{source-highlighter$highlight:}<pre><code>
+|
+{source-highlighter$highlight:}</code></pre>
+</td></tr></table>
+endif::basebackend-html[]
+
+ifdef::basebackend-xhtml11,basebackend-html5[]
+[source-highlight-block]
+<div class="listingblock{role? {role}}">
+<a id="{id}"></a>
+<div class="title">{caption=}{title}</div>
+<div class="content">
+{source-highlighter$highlight:}<pre><code>
+|
+{source-highlighter$highlight:}</code></pre>
+</div></div>
+endif::basebackend-xhtml11,basebackend-html5[]
+
+# Use DocBook programlisting element.
+ifdef::basebackend-docbook[]
+[source-highlight-block]
+<formalpara{id? id="{id}"}{role? role="{role}"}{reftext? xreflabel="{reftext}"}><title>{title}</title><para>
+{title#}<programlisting language="{language}" linenumbering="{src_numbered=unnumbered}"{args? {args}}>
+{title%}<programlisting language="{language}"{role? role="{role}"} linenumbering="{src_numbered=unnumbered}"{args? {args}}>
+|
+</programlisting>
+{title#}</para></formalpara>
+endif::basebackend-docbook[]
+
+# Source styles template.
+ifdef::basebackend-html[]
+[source-filter-style]
+ifeval::["{source-highlighter}"=="source-highlight"]
+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}} {args=}"
+endif::[]
+ifeval::["{source-highlighter}"=="highlight"]
+source-style=template="source-highlight-block",presubs=(),postsubs=("callouts",),posattrs=("style","language","src_numbered","src_tab"),filter="highlight --no-doc --inline-css --out-format=xhtml --syntax={language@python:py:{language}} {src_numbered?--line-number} {src_tab?--tab={src_tab}} --encoding={encoding} {args=}"
+endif::[]
+ifeval::["{source-highlighter}"=="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} {encoding?-O encoding={encoding}} {args=}"
+endif::[]
+# DEPRECATED: 'pygments' attribute.
+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} {encoding?-O encoding={encoding}} {args=}"
+endif::[]
+endif::basebackend-html[]
+
+ifdef::basebackend-html4[]
+[source-filter-style]
+# html4 does not use pygments.
+ifeval::["{source-highlighter}"=="source-highlight"]
+source-style=template="source-highlight-block",presubs=(),postsubs=("callouts",),posattrs=("style","language","src_numbered","src_tab"),filter="source-highlight -f html -s {language} {src_numbered?--line-number=' '} {src_tab?--tab={src_tab}} {args=}"
+endif::[]
+ifeval::["{source-highlighter}"=="highlight"]
+source-style=template="source-highlight-block",presubs=(),postsubs=("callouts",),posattrs=("style","language","src_numbered","src_tab"),filter="highlight --no-doc --inline-css --out-format=html --syntax={language@python:py:{language}} {src_numbered?--line-number} {src_tab?--tab={src_tab}} {args=}"
+endif::[]
+endif::basebackend-html4[]
+
+ifdef::basebackend-docbook[]
+[source-filter-style]
+source-style=template="source-highlight-block",presubs=(),postsubs=("specialcharacters","callouts"),posattrs=("style","language","src_numbered","src_tab")
+endif::basebackend-docbook[]
+
+#########################
+# Source paragraph styles
+#########################
+[paradef-default]
+template::[source-filter-style]
+
+[paradef-literal]
+template::[source-filter-style]
+
+#########################
+# Source block styles
+#########################
+[blockdef-open]
+template::[source-filter-style]
+
+[blockdef-listing]
+template::[source-filter-style]
+
+
+#
+# DEPRECATED: Pre 8.2.7 filter definition.
+#
+
+#########################
+# Source block definition
+#########################
+[blockdef-source-highlight]
+# The old ^ delimiter is for backward compatibility, may be removed from
+# in future versions.
+delimiter=(^source~{4,}$)|(^\^{4,}$)
+template=source-highlight-block
+presubs=none
+posattrs=language,src_numbered,src_tab
+
+ifndef::basebackend-docbook[]
+postsubs=callouts
+# GNU Source Highlight filter.
+filter=source-highlight -f {basebackend-xhtml11?xhtml}{basebackend-html4?html} -s {language} {src_numbered?--line-number} {src_tab?--tab={src_tab}}
+endif::basebackend-docbook[]
+
+ifdef::basebackend-docbook[]
+postsubs=specialcharacters,callouts
+# In the case of DocBook just pass the listing through and let the DocBook
+# toolchain handle it.
+filter=
+endif::basebackend-docbook[]
+
+#
+# DEPRECATED: End
+#