[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Patch proposal: DocBook support for lilypond-book
From: |
Bertalan Fodor |
Subject: |
Re: Patch proposal: DocBook support for lilypond-book |
Date: |
Wed, 18 Oct 2006 10:57:36 +0200 |
User-agent: |
Thunderbird 1.5.0.7 (Windows/20060909) |
Attached.
Bert
Han-Wen Nienhuys írta:
Bertalan Fodor schreef:
Hello,
I've created an enhancement for lilypond-book allowing us to use it
with DocBook documents.
Specification and examples can be read at
http://www.organum.hu/fileadmin/lilypondtool/lily-docbook.pdf
The enhanced script is at
http://www.organum.hu/fileadmin/lilypondtool/lilypond-book.py
I created the docbook document with XmlMind xml editor. The pdf
rendering has been made with dblatex under cygwin (thanks Jan we have
a tetex there :-) )
Anyone interested?
Should I create a patch? Against which version? Any suggestions?
yes please, against 2.9 CVS
--- lilypond-book.py 2006-10-18 10:39:17.233367000 +0200
+++ lilypond-book-docbook.py 2006-10-18 10:51:04.409618000 +0200
@@ -67,7 +67,7 @@
backend = 'ps'
help_summary = _ (
-'''Process LilyPond snippets in hybrid HTML, LaTeX, or texinfo document.
+'''Process LilyPond snippets in hybrid HTML, LaTeX, texinfo or DocBook
document.
Example usage:
@@ -132,7 +132,7 @@
help=_ ("pipe snippets through FILTER [convert-ly -n -]"),
default=None)
p.add_option ('-f', '--format',
- help=_('''use output format FORMAT (texi [default],
texi-html, latex, html)'''),
+ help=_('''use output format FORMAT (texi [default],
texi-html, latex, html, docbook)'''),
action='store')
p.add_option ("-I", '--include', help=_('add DIR to include path'),
@@ -191,6 +191,7 @@
#
AFTER = 'after'
BEFORE = 'before'
+DOCBOOK = 'docbook'
EXAMPLEINDENT = 'exampleindent'
FILTER = 'filter'
FRAGMENT = 'fragment'
@@ -239,6 +240,43 @@
# (?x) -- Ignore whitespace in patterns.
no_match = 'a\ba'
snippet_res = {
+ ##
+ DOCBOOK: {
+ 'include':
+ no_match,
+
+ 'lilypond':
+ r'''(?smx)
+ (?P<match>
+
<(?P<inline>(inline)?)mediaobject>\s*<textobject.*?>\s*<programlisting\s+language="lilypond".*?(role="(?P<options>.*?)")?>(?P<code>.*?)</programlisting\s*>\s*</textobject\s*>\s*</(inline)?mediaobject>)''',
+
+ 'lilypond_block':
+ r'''(?smx)
+ (?P<match>
+
<(?P<inline>(inline)?)mediaobject>\s*<textobject.*?>\s*<programlisting\s+language="lilypond".*?(role="(?P<options>.*?)")?>(?P<code>.*?)</programlisting\s*>\s*</textobject\s*>\s*</(inline)?mediaobject>)''',
+
+ 'lilypond_file':
+ r'''(?smx)
+ (?P<match>
+
<(?P<inline>(inline)?)mediaobject>\s*<imageobject.*?>\s*<imagedata\s+fileref="(?P<filename>.*?\.ly)"\s*(role="(?P<options>.*?)")?\s*(/>|>\s*</imagedata>)\s*</imageobject>\s*</(inline)?mediaobject>)''',
+
+ 'multiline_comment':
+ r'''(?smx)
+ (?P<match>
+ \s*(address@hidden)
+ (?P<code><!--\s.*?!-->)
+ \s)''',
+
+ 'singleline_comment':
+ no_match,
+
+ 'verb':
+ no_match,
+
+ 'verbatim':
+ no_match,
+
+ },
##
HTML: {
'include':
@@ -436,6 +474,10 @@
format_res = {
+ DOCBOOK: {
+ 'intertext': r',?\s*intertext=\".*?\"',
+ 'option_sep': '\s*',
+ },
HTML: {
'intertext': r',?\s*intertext=\".*?\"',
'option_sep': '\s*',
@@ -506,6 +548,21 @@
output = {
##
+ DOCBOOK: {
+ FILTER: r'''<mediaobject><textobject><programlisting
language="lilypond"
role="%(options)s">%(code)s</programlisting></textobject></mediaobject>''',
+
+ OUTPUT: r'''
+ <imageobject role="latex">
+ <imagedata fileref="%(base)s.pdf" format="PDF"/>
+ </imageobject>
+ <imageobject role="html">
+ <imagedata fileref="%(base)s.png"
format="PNG"/></imageobject>''',
+
+ VERBATIM: r'''<programlisting>%(verb)s</programlisting>''',
+
+ PRINTFILENAME: '<textobject><simpara><ulink
url="%(base)s.ly"><filename>%(filename)s</filename></ulink></simpara></textobject>'
+ },
+ ##
HTML: {
FILTER: r'''<lilypond %(options)s>
%(code)s
@@ -1104,6 +1161,22 @@
images = tuple (images)
return images
+ def output_docbook (self):
+ str = ''
+ base = self.basename ()
+ for image in self.get_images ():
+ (base, ext) = os.path.splitext (image)
+ str += output[DOCBOOK][OUTPUT] % vars ()
+ str += self.output_print_filename (DOCBOOK)
+ if (self.substring('inline') == 'inline'):
+ str = '<inlinemediaobject>' + str + '</inlinemediaobject>'
+ else:
+ str = '<mediaobject>' + str + '</mediaobject>'
+ if VERBATIM in self.option_dict:
+ verb = verbatim_html (self.substring ('code'))
+ str = output[DOCBOOK][VERBATIM] % vars () + str
+ return str
+
def output_html (self):
str = ''
base = self.basename ()
@@ -1371,7 +1444,8 @@
if global_options.format in (HTML, TEXINFO):
cmd += ' --formats=png '
-
+ if global_options.format in (DOCBOOK):
+ cmd += ' --formats=png,pdf '
# UGH
# the --process=CMD switch is a bad idea
# it is too generic for lilypond-book.
@@ -1465,6 +1539,7 @@
'.texi': TEXINFO,
'.texinfo': TEXINFO,
'.xml': HTML,
+ '.lyxml': DOCBOOK
}
format2ext = {
@@ -1472,6 +1547,7 @@
# TEXINFO: '.texinfo',
TEXINFO: '.texi',
LATEX: '.tex',
+ DOCBOOK: '.xml'
}
class Compile_error:
@@ -1701,7 +1777,7 @@
global_options.format = guess_format (files[0])
formats = 'ps'
- if global_options.format in (TEXINFO, HTML):
+ if global_options.format in (TEXINFO, HTML, DOCBOOK):
formats += ',png'