1 # -*- coding: utf-8 -*-
3 import book_base
as BookBase
4 from book_snippets
import *
6 # Recognize special sequences in the input.
8 # (?P<name>regex) -- Assign result of REGEX to NAME.
9 # *? -- Match non-greedily.
10 # (?!...) -- Match if `...' doesn't match next (without consuming
13 # (?m) -- Multiline regex: Make ^ and $ match at each line.
14 # (?s) -- Make the dot match all characters including newline.
15 # (?x) -- Ignore whitespace in patterns.
17 # 'multiline_comment', 'verbatim', 'lilypond_block', 'singleline_comment',
18 # 'lilypond_file', 'include', 'lilypond', 'lilypondversion'
19 Docbook_snippet_res
= {
23 <(?P<inline>(inline)?)mediaobject>\s*
25 <programlisting\s+language="lilypond".*?(role="(?P<options>.*?)")?>
27 </programlisting\s*>\s*
29 </(inline)?mediaobject>)''',
34 <(?P<inline>(inline)?)mediaobject>\s*
36 <programlisting\s+language="lilypond".*?(role="(?P<options>.*?)")?>
38 </programlisting\s*>\s*
40 </(inline)?mediaobject>)''',
45 <(?P<inline>(inline)?)mediaobject>\s*
48 fileref="(?P<filename>.*?\.ly)"\s*
49 (role="(?P<options>.*?)")?\s*
50 (/>|>\s*</imagedata>)\s*
52 </(inline)?mediaobject>)''',
58 (?P<code><!--\s.*?!-->)
64 FILTER
: r
'''<mediaobject>
66 <programlisting language="lilypond"
73 OUTPUT
: r
'''<imageobject role="latex">
74 <imagedata fileref="%(base)s.pdf" format="PDF"/>
76 <imageobject role="html">
77 <imagedata fileref="%(base)s.png" format="PNG"/>
80 PRINTFILENAME
: r
'''<textobject>
82 <ulink url="%(base)s.ly">
90 VERBATIM
: r
'''<programlisting>
91 %(verb)s</programlisting>''',
93 VERSION
: r
'''%(program_version)s''',
99 class BookDocbookOutputFormat (BookBase
.BookOutputFormat
):
101 BookBase
.BookOutputFormat
.__init
__ (self
)
102 self
.format
= "docbook"
103 self
.default_extension
= ".xml"
104 self
.snippet_res
= Docbook_snippet_res
105 self
.output
= Docbook_output
106 self
.handled_extensions
= ['.lyxml']
107 self
.snippet_option_separator
= '\s*'
109 def adjust_snippet_command (self
, cmd
):
110 if '--formats' not in cmd
:
111 return cmd
+ ' --formats=png,pdf '
115 def snippet_output (self
, basename
, snippet
):
117 rep
= snippet
.get_replacements ();
118 for image
in snippet
.get_images ():
120 (rep
['base'], rep
['ext']) = os
.path
.splitext (image
)
121 str += self
.output
[OUTPUT
] % rep
122 str += self
.output_print_filename (basename
, snippet
)
123 if (snippet
.substring('inline') == 'inline'):
124 str = '<inlinemediaobject>' + str + '</inlinemediaobject>'
126 str = '<mediaobject>' + str + '</mediaobject>'
127 if VERBATIM
in snippet
.option_dict
:
128 rep
['verb'] = BookBase
.verbatim_html (snippet
.verb_ly ())
129 str = self
.output
[VERBATIM
] % rep
+ str
133 BookBase
.register_format (BookDocbookOutputFormat ());