]> git.donarmstrong.com Git - lilypond.git/blob - scripts/build/html-to-texi.py
Add '-dcrop' option to ps and svg backends
[lilypond.git] / scripts / build / html-to-texi.py
1 #! @PYTHON@
2
3 import re
4 import sys
5
6 header = '''
7 '''
8
9 print header
10
11 body = sys.stdin.read ()
12 body = re.sub ('(?ms)<!--\s*\n*(.*?)FILL-IN(.*?)\s*\n*!?-->', '', body)
13 body = re.sub ('(?ms)\n*\s*<!--\s*\n*(.*?)\s*\n*!?-->', r'@ignore\n\1\n@end ignore', body)
14 body = re.sub ('(?ms)<a(?:\s|\n)*href="([^"]*)"\s*>(.*?)</a>', r'@ref{\1,\2}', body)
15
16 body = re.sub ('(?ms)<a(?:\s|\n)*name="([^"]*)"\s*> *</a>', r'@node \1 ', body)
17 body = re.sub ('(?ms)<h1>(.*?)</h1>', r'@chapheading \1', body)
18 body = re.sub ('(?ms)<h2>(.*?)</h2>', r'@unnumberedsec \1', body)
19 #body = re.sub ('(?ms)<a(?:\s|\n)*name="([^"]*)"\s*> *</a>', '', body)
20 #body = re.sub ('(?ms)<h2>(.*?)</h2>', r'@node \1\n@unnumberedsec \1', body)
21
22 body = re.sub ('(?ms)<img(?:\s|\n)*[^>]*src="*([^">]*)(.png|.jpeg)"*.*?>', r'@image{\1,,,\2}', body)
23 body = re.sub ('\n*<br>\s*\n*', r'@*\n', body)
24 body = re.sub ('\n*<br[^>]*>\s*\n*', r'@*\n', body)
25 body = re.sub ('(?ms)<em>(.*?)</em>', r'@emph{\1}', body)
26 body = re.sub ('(?ms)<blockquote>(.*?)</blockquote>', r'@quote{\1}', body)
27 body = re.sub ('(?ms)<tt>(.*?)</tt>', r'@code{\1}', body)
28 body = re.sub ('(?ms)<li>(.*?)(</li>)', r'@item\n\1\n', body)
29 body = re.sub ('(?ms)<li>(.*?)(<li>)', r'@item\n\1\n\2', body)
30 body = re.sub ('(?ms)<li>(.*?)(<li>)', r'@item\n\1\n\2', body)
31 body = re.sub ('(?ms)<li>(.*?)(<li>)', r'@item\n\1\n\2', body)
32 body = re.sub ('(?ms)<li>(.*?)(<li>)', r'@item\n\1\n\2', body)
33 body = re.sub ('(?ms)<li>(.*?)(<li>)', r'@item\n\1\n\2', body)
34 body = re.sub ('(?ms)<li>(.*?)(</(?:u|o)l>)', r'@item\n\1\n\2', body)
35 body = re.sub ('(?ms)<ul>', r'@itemize', body)
36 body = re.sub ('(?ms)</ul>', r'@end itemize', body)
37
38 # added for the bib => bib2html => html2texinfo chain.  -gp
39 body = re.sub ('(?ms)<HTML>', r'', body)
40 body = re.sub ('(?ms)<HEAD>(.*?)(</HEAD>)', r'', body)
41 body = re.sub ('(?ms)<BODY(.*?)>', r'', body)
42 body = re.sub ('(?ms)</BODY>', r'', body)
43 body = re.sub ('(?ms)</HTML>', r'', body)
44
45 body = re.sub ('(?ms)<DL>', r'@table @emph', body)
46 body = re.sub ('(?ms)</DL>', r'@end table', body)
47
48 body = re.sub ('(?ms)<DT> <A NAME="(.*?)">(.*?)(</DT>)', r'@item \1', body)
49 body = re.sub ('(?ms)<A(.*?)>', r'', body)
50 body = re.sub ('(?ms):</A>', r'', body)
51 body = re.sub ('(?ms)<DD>(.*?)(</DD>)', r'\1', body)
52
53 body = re.sub ('(?ms)<STRONG>(.*?)(</STRONG>)', r'@strong{\1}', body)
54 body = re.sub ('(?ms)<EM>(.*?)(</EM>)', r'@emph{\1}', body)
55
56 body = re.sub ('(?ms)&nbsp;', r'@tie{}', body)
57
58 body = re.sub ('(?ms)\cite{(.*?)}', r'[\1]', body)
59 body = re.sub ('(?ms)\cite{(.*?)}', r'[\1]', body)
60
61 # dangerous rule, but with the spaces should be ok
62 body = re.sub ('(?ms) {(.*?)} ', r' @q{\1} ', body)
63
64 # end stuff added for the bib => bib2html => html2texinfo chain -gp
65 # the other lines in the file can _probably_ be trimmed.
66
67
68 body = re.sub ('(?ms)<ol>', r'@enumerate POSITIVE-INTEGER', body)
69 body = re.sub ('(?ms)<ol\s+start="*(.*?)"*>', r'@enumerate \1', body)
70 body = re.sub ('(?ms)</ol>', r'@end enumerate', body)
71
72 body = re.sub ('&ldquo;(.*?)&rdquo;', r'@qq{\1}', body)
73 body = re.sub ('&auml;', '@"a', body)
74 body = re.sub ('(?ms)\s*<p>\s*', '\n\n', body)
75 body = re.sub ('\n*\s*</p>\s*\n*', '\n\n', body)
76 body = re.sub ('(?ms)</?font\s*.*?>', '', body)
77 body = re.sub ('(?ms)<code>(.*?)</code>', r'@code{\1}', body)
78 body = re.sub ('(?ms)<em>(.*?)</em>', r'@emph{\1}', body)
79 body = re.sub ('(?ms)<b>(.*?)</b>', r'@strong{\1}', body)
80 body = re.sub ('(?ms)<pre>(.*?)</pre>', r'@verbatim\n\1\n@end verbatim', body)
81 body = re.sub ('(?ms)<PRE>(.*?)</PRE>', r'@verbatim\n\1\n@end verbatim', body)
82
83 body = re.sub ('(?ms)<table>', r'@table asis', body)
84 body = re.sub ('(?ms)<table [^>]*>', r'@table asis', body)
85 body = re.sub ('(?ms)</table>', r'@end table', body)
86 body = re.sub ('(?ms)<tr>(.*?)</tr>', r'@item\n\1\n', body)
87 body = re.sub ('(?ms)<th>(.*?)</th>', r'@item\n\1\n', body)
88 body = re.sub ('(?ms)<td[^>]*>(.*?)</td>', r'@tab\n\1\n', body)
89
90 #body = re.sub ('(?ms)\s*<p align="(center|left|right)">\s*((?:.|\n)*)\n\n', '@divClass{float-\\1}\n\\2\n@divEnd', body)
91 body = re.sub ('(?ms)\s*<p align="(center|left|right)"\s*>\s*', '\n\n@divClass{float-\\1}\n@divEnd\n', body)
92
93 print body
94