-def output_verbatim (body, small):
- global format
- if format == 'html':
- body = re.sub ('&', '&', body)
- body = re.sub ('>', '>', body)
- body = re.sub ('<', '<', body)
- elif format == 'texi':
- # clumsy workaround for python 2.2 pre bug.
- body = re.sub ('@', '@@', body)
- body = re.sub ('{', '@{', body)
- body = re.sub ('}', '@}', body)
-
- if small:
- key = 'output-small-verbatim'
- else:
- key = 'output-verbatim'
- return get_output (key) % body
-
-
-################################################################
-# Recognize special sequences in the input
-
-
-# Warning: This uses extended regular expressions. Tread with care.
-#
-# legenda
-#
-# (?P<name>regex) -- assign result of REGEX to NAME
-# *? -- match non-greedily.
-# (?m) -- multiline regex: make ^ and $ match at each line
-# (?s) -- make the dot match all characters including newline
-re_dict = {
- 'html': {
- 'include': no_match,
- 'input': no_match,
- 'header': no_match,
- 'preamble-end': no_match,
- 'landscape': no_match,
- 'verbatim': r'''(?s)(?P<code><pre>\s.*?</pre>\s)''',
- 'verb': r'''(?P<code><pre>.*?</pre>)''',
- 'lilypond-file': r'(?m)(?P<match><lilypondfile(?P<options>[^>]+)?>\s*(?P<filename>[^<]+)\s*</lilypondfile>)',
- 'lilypond' : '(?m)(?P<match><lilypond((?P<options>[^:]*):)(?P<code>.*?)/>)',
- 'lilypond-block': r'''(?ms)(?P<match><lilypond(?P<options>[^>]+)?>(?P<code>.*?)</lilypond>)''',
- 'option-sep' : '\s*',
- 'intertext': r',?\s*intertext=\".*?\"',
- 'multiline-comment': r"(?sm)\s*(?!@c\s+)(?P<code><!--\s.*?!-->)\s",
- 'singleline-comment': no_match,
- 'numcols': no_match,
- 'multicols': no_match,
- 'ly2dvi': r'(?m)(?P<match><ly2dvifile(?P<options>[^>]+)?>\s*(?P<filename>[^<]+)\s*</ly2dvifile>)',
- },
-
- 'latex': {
- 'input': r'(?m)^[^%\n]*?(?P<match>\\mbinput{?([^}\t \n}]*))',
- 'include': r'(?m)^[^%\n]*?(?P<match>\\mbinclude{(?P<filename>[^}]+)})',
- 'option-sep' : ',\s*',
- 'header': r"\n*\\documentclass\s*(\[.*?\])?",
- 'preamble-end': r'(?P<code>\\begin\s*{document})',
- 'verbatim': r"(?s)(?P<code>\\begin\s*{verbatim}.*?\\end{verbatim})",
- 'verb': r"(?P<code>\\verb(?P<del>.).*?(?P=del))",
- 'lilypond-file': r'(?m)^[^%\n]*?(?P<match>\\lilypondfile\s*(\[(?P<options>.*?)\])?\s*\{(?P<filename>.+)})',
- 'lilypond' : r'(?m)^[^%\n]*?(?P<match>\\lilypond\s*(\[(?P<options>.*?)\])?\s*{(?P<code>.*?)})',
- 'lilypond-block': r"(?sm)^[^%\n]*?(?P<match>\\begin\s*(\[(?P<options>.*?)\])?\s*{lilypond}(?P<code>.*?)\\end{lilypond})",
- 'def-post-re': r"\\def\\postLilyPondExample",
- 'def-pre-re': r"\\def\\preLilyPondExample",
- 'usepackage-graphics': r"\usepackage\s*{graphics}",
- 'intertext': r',?\s*intertext=\".*?\"',
- 'multiline-comment': no_match,
- 'singleline-comment': r"(?m)^.*?(?P<match>(?P<code>^%.*$\n+))",
- 'numcols': r"(?P<code>\\(?P<num>one|two)column)",
- 'multicols': r"(?P<code>\\(?P<be>begin|end)\s*{multicols}({(?P<num>\d+)?})?)",
- 'ly2dvi': no_match,
-
- },
-
- # why do we have distinction between @mbinclude and @include?
-
- 'texi': {
- 'include': '(?m)^[^%\n]*?(?P<match>@mbinclude\s+(?P<filename>\S*))',
- 'input': no_match,
- 'header': no_match,
- 'preamble-end': no_match,
- 'landscape': no_match,
- 'verbatim': r'''(?s)(?P<code>@example\s.*?@end example\s)''',
- 'verb': r'''(?P<code>@code{.*?})''',
- 'lilypond-file': '(?m)^(?P<match>@lilypondfile(\[(?P<options>[^]]*)\])?{(?P<filename>[^}]+)})',
- 'lilypond' : '(?m)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?{(?P<code>.*?)})',
- 'lilypond-block': r'''(?ms)^(?P<match>@lilypond(\[(?P<options>[^]]*)\])?\s(?P<code>.*?)@end lilypond)\s''',
- 'option-sep' : ',\s*',
- 'intertext': r',?\s*intertext=\".*?\"',
- 'multiline-comment': r"(?sm)^\s*(?!@c\s+)(?P<code>@ignore\s.*?@end ignore)\s",
- 'singleline-comment': r"(?m)^.*?(?P<match>(?P<code>@c.*$\n+))",
- 'numcols': no_match,
- 'multicols': no_match,
- 'ly2dvi': no_match,
- }