FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
cpython/Tools/scripts/texi2html.py at v3.6.15 · python/cpython · GitHub
python
cpython
Repository navigation
Code
Issues
5k+
(5k+)
Pull requests
2.7k
(2.7k)
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
cpython
/
Tools
/
scripts
/
texi2html.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
2075 lines (1779 loc) · 68.5 KB
Breadcrumbs
cpython
/
Tools
/
scripts
/
texi2html.py
Copy path
File metadata and controls
executable file
·
2075 lines (1779 loc) · 68.5 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#! /usr/bin/env python3
# Convert GNU texinfo files into HTML, one file per node.
# Based on Texinfo 2.14.
# Usage: texi2html [-d] [-d] [-c] inputfile outputdirectory
# The input file must be a complete texinfo file, e.g. emacs.texi.
# This creates many files (one per info node) in the output directory,
# overwriting existing files of the same name. All files created have
# ".html" as their extension.
# XXX To do:
# - handle @comment*** correctly
# - handle @xref {some words} correctly
# - handle @ftable correctly (items aren't indexed?)
# - handle @itemx properly
# - handle @exdent properly
# - add links directly to the proper line from indices
# - check against the definitive list of @-cmds; we still miss (among others):
# - @defindex (hard)
# - @c(omment) in the middle of a line (rarely used)
# - @this* (not really needed, only used in headers anyway)
# - @today{} (ever used outside title page?)
# More consistent handling of chapters/sections/etc.
# Lots of documentation
# Many more options:
# -top designate top node
# -links customize which types of links are included
# -split split at chapters or sections instead of nodes
# -name Allow different types of filename handling. Non unix systems
# will have problems with long node names
# ...
# Support the most recent texinfo version and take a good look at HTML 3.0
# More debugging output (customizable) and more flexible error handling
# How about icons ?
# rpyron 2002-05-07
# Robert Pyron <rpyron@alum.mit.edu>
# 1. BUGFIX: In function makefile(), strip blanks from the nodename.
# This is necessary to match the behavior of parser.makeref() and
# parser.do_node().
# 2. BUGFIX fixed KeyError in end_ifset (well, I may have just made
# it go away, rather than fix it)
# 3. BUGFIX allow @menu and menu items inside @ifset or @ifclear
# 4. Support added for:
# @uref URL reference
# @image image file reference (see note below)
# @multitable output an HTML table
# @vtable
# 5. Partial support for accents, to match MAKEINFO output
# 6. I added a new command-line option, '-H basename', to specify
# HTML Help output. This will cause three files to be created
# in the current directory:
# `basename`.hhp HTML Help Workshop project file
# `basename`.hhc Contents file for the project
# `basename`.hhk Index file for the project
# When fed into HTML Help Workshop, the resulting file will be
# named `basename`.chm.
# 7. A new class, HTMLHelp, to accomplish item 6.
# 8. Various calls to HTMLHelp functions.
# A NOTE ON IMAGES: Just as 'outputdirectory' must exist before
# running this program, all referenced images must already exist
# in outputdirectory.
import
os
import
sys
import
string
import
re
MAGIC
=
'
\\
input texinfo'
cmprog
=
re
.
compile
(
'^@([a-z]+)([
\t
]|$)'
)
# Command (line-oriented)
blprog
=
re
.
compile
(
'^[
\t
]*$'
)
# Blank line
kwprog
=
re
.
compile
(
'@[a-z]+'
)
# Keyword (embedded, usually
# with {} args)
spprog
=
re
.
compile
(
'[
\n
@{}&<>]'
)
# Special characters in
# running text
#
# menu item (Yuck!)
miprog
=
re
.
compile
(
r'^\* ([^:]*):(:|[ \t]*([^\t,\n.]+)([^ \t\n]*))[ \t\n]*'
)
# 0 1 1 2 3 34 42 0
# ----- ---------- ---------
# -|-----------------------------
# -----------------------------------------------------
class
HTMLNode
:
"""Some of the parser's functionality is separated into this class.
A Node accumulates its contents, takes care of links to other Nodes
and saves itself when it is finished and all links are resolved.
"""
DOCTYPE
=
'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">'
type
=
0
cont
=
''
epilogue
=
'</BODY></HTML>
\n
'
def
__init__
(
self
,
dir
,
name
,
topname
,
title
,
next
,
prev
,
up
):
self
.
dirname
=
dir
self
.
name
=
name
if
topname
:
self
.
topname
=
topname
else
:
self
.
topname
=
name
self
.
title
=
title
self
.
next
=
next
self
.
prev
=
prev
self
.
up
=
up
self
.
lines
=
[]
def
write
(
self
,
*
lines
):
for
line
in
lines
:
self
.
lines
.
append
(
line
)
def
flush
(
self
):
fp
=
open
(
self
.
dirname
+
'/'
+
makefile
(
self
.
name
),
'w'
)
fp
.
write
(
self
.
prologue
)
fp
.
write
(
self
.
text
)
fp
.
write
(
self
.
epilogue
)
fp
.
close
()
def
link
(
self
,
label
,
nodename
,
rel
=
None
,
rev
=
None
):
if
nodename
:
if
nodename
.
lower
()
==
'(dir)'
:
addr
=
'../dir.html'
title
=
''
else
:
addr
=
makefile
(
nodename
)
title
=
' TITLE="%s"'
%
nodename
self
.
write
(
label
,
': <A HREF="'
,
addr
,
'"'
, \
rel
and
(
' REL='
+
rel
)
or
""
, \
rev
and
(
' REV='
+
rev
)
or
""
, \
title
,
'>'
,
nodename
,
'</A>
\n
'
)
def
finalize
(
self
):
length
=
len
(
self
.
lines
)
self
.
text
=
''
.
join
(
self
.
lines
)
self
.
lines
=
[]
self
.
open_links
()
self
.
output_links
()
self
.
close_links
()
links
=
''
.
join
(
self
.
lines
)
self
.
lines
=
[]
self
.
prologue
=
(
self
.
DOCTYPE
+
'
\n
<HTML><HEAD>
\n
'
' <!-- Converted with texi2html and Python -->
\n
'
' <TITLE>'
+
self
.
title
+
'</TITLE>
\n
'
' <LINK REL=Next HREF="'
+
makefile
(
self
.
next
)
+
'" TITLE="'
+
self
.
next
+
'">
\n
'
' <LINK REL=Previous HREF="'
+
makefile
(
self
.
prev
)
+
'" TITLE="'
+
self
.
prev
+
'">
\n
'
' <LINK REL=Up HREF="'
+
makefile
(
self
.
up
)
+
'" TITLE="'
+
self
.
up
+
'">
\n
'
'</HEAD><BODY>
\n
'
+
links
)
if
length
>
20
:
self
.
epilogue
=
'<P>
\n
%s</BODY></HTML>
\n
'
%
links
def
open_links
(
self
):
self
.
write
(
'<HR>
\n
'
)
def
close_links
(
self
):
self
.
write
(
'<HR>
\n
'
)
def
output_links
(
self
):
if
self
.
cont
!=
self
.
next
:
self
.
link
(
' Cont'
,
self
.
cont
)
self
.
link
(
' Next'
,
self
.
next
,
rel
=
'Next'
)
self
.
link
(
' Prev'
,
self
.
prev
,
rel
=
'Previous'
)
self
.
link
(
' Up'
,
self
.
up
,
rel
=
'Up'
)
if
self
.
name
!=
self
.
topname
:
self
.
link
(
' Top'
,
self
.
topname
)
class
HTML3Node
(
HTMLNode
):
DOCTYPE
=
'<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML Level 3//EN//3.0">'
def
open_links
(
self
):
self
.
write
(
'<DIV CLASS=Navigation>
\n
<HR>
\n
'
)
def
close_links
(
self
):
self
.
write
(
' <HR>
\n
</DIV>
\n
'
)
class
TexinfoParser
:
COPYRIGHT_SYMBOL
=
"©"
FN_ID_PATTERN
=
"(%(id)s)"
FN_SOURCE_PATTERN
=
'<A NAME=footnoteref%(id)s'
\
' HREF="#footnotetext%(id)s">'
\
+
FN_ID_PATTERN
+
'</A>'
FN_TARGET_PATTERN
=
'<A NAME=footnotetext%(id)s'
\
' HREF="#footnoteref%(id)s">'
\
+
FN_ID_PATTERN
+
'</A>
\n
%(text)s<P>
\n
'
FN_HEADER
=
'
\n
<P>
\n
<HR NOSHADE SIZE=1 WIDTH=200>
\n
'
\
'<STRONG><EM>Footnotes</EM></STRONG>
\n
<P>'
Node
=
HTMLNode
# Initialize an instance
def
__init__
(
self
):
self
.
unknown
=
{}
# statistics about unknown @-commands
self
.
filenames
=
{}
# Check for identical filenames
self
.
debugging
=
0
# larger values produce more output
self
.
print_headers
=
0
# always print headers?
self
.
nodefp
=
None
# open file we're writing to
self
.
nodelineno
=
0
# Linenumber relative to node
self
.
links
=
None
# Links from current node
self
.
savetext
=
None
# If not None, save text head instead
self
.
savestack
=
[]
# If not None, save text head instead
self
.
htmlhelp
=
None
# html help data
self
.
dirname
=
'tmp'
# directory where files are created
self
.
includedir
=
'.'
# directory to search @include files
self
.
nodename
=
''
# name of current node
self
.
topname
=
''
# name of top node (first node seen)
self
.
title
=
''
# title of this whole Texinfo tree
self
.
resetindex
()
# Reset all indices
self
.
contents
=
[]
# Reset table of contents
self
.
numbering
=
[]
# Reset section numbering counters
self
.
nofill
=
0
# Normal operation: fill paragraphs
self
.
values
=
{
'html'
:
1
}
# Names that should be parsed in ifset
self
.
stackinfo
=
{}
# Keep track of state in the stack
# XXX The following should be reset per node?!
self
.
footnotes
=
[]
# Reset list of footnotes
self
.
itemarg
=
None
# Reset command used by @item
self
.
itemnumber
=
None
# Reset number for @item in @enumerate
self
.
itemindex
=
None
# Reset item index name
self
.
node
=
None
self
.
nodestack
=
[]
self
.
cont
=
0
self
.
includedepth
=
0
# Set htmlhelp helper class
def
sethtmlhelp
(
self
,
htmlhelp
):
self
.
htmlhelp
=
htmlhelp
# Set (output) directory name
def
setdirname
(
self
,
dirname
):
self
.
dirname
=
dirname
# Set include directory name
def
setincludedir
(
self
,
includedir
):
self
.
includedir
=
includedir
# Parse the contents of an entire file
def
parse
(
self
,
fp
):
line
=
fp
.
readline
()
lineno
=
1
while
line
and
(
line
[
0
]
==
'%'
or
blprog
.
match
(
line
)):
line
=
fp
.
readline
()
lineno
=
lineno
+
1
if
line
[:
len
(
MAGIC
)]
!=
MAGIC
:
raise
SyntaxError
(
'file does not begin with %r'
%
(
MAGIC
,))
self
.
parserest
(
fp
,
lineno
)
# Parse the contents of a file, not expecting a MAGIC header
def
parserest
(
self
,
fp
,
initial_lineno
):
lineno
=
initial_lineno
self
.
done
=
0
self
.
skip
=
0
self
.
stack
=
[]
accu
=
[]
while
not
self
.
done
:
line
=
fp
.
readline
()
self
.
nodelineno
=
self
.
nodelineno
+
1
if
not
line
:
if
accu
:
if
not
self
.
skip
:
self
.
process
(
accu
)
accu
=
[]
if
initial_lineno
>
0
:
print
(
'*** EOF before @bye'
)
break
lineno
=
lineno
+
1
mo
=
cmprog
.
match
(
line
)
if
mo
:
a
,
b
=
mo
.
span
(
1
)
cmd
=
line
[
a
:
b
]
if
cmd
in
(
'noindent'
,
'refill'
):
accu
.
append
(
line
)
else
:
if
accu
:
if
not
self
.
skip
:
self
.
process
(
accu
)
accu
=
[]
self
.
command
(
line
,
mo
)
elif
blprog
.
match
(
line
)
and
\
'format'
not
in
self
.
stack
and
\
'example'
not
in
self
.
stack
:
if
accu
:
if
not
self
.
skip
:
self
.
process
(
accu
)
if
self
.
nofill
:
self
.
write
(
'
\n
'
)
else
:
self
.
write
(
'<P>
\n
'
)
accu
=
[]
else
:
# Append the line including trailing \n!
accu
.
append
(
line
)
#
if
self
.
skip
:
print
(
'*** Still skipping at the end'
)
if
self
.
stack
:
print
(
'*** Stack not empty at the end'
)
print
(
'***'
,
self
.
stack
)
if
self
.
includedepth
==
0
:
while
self
.
nodestack
:
self
.
nodestack
[
-
1
].
finalize
()
self
.
nodestack
[
-
1
].
flush
()
del
self
.
nodestack
[
-
1
]
# Start saving text in a buffer instead of writing it to a file
def
startsaving
(
self
):
if
self
.
savetext
is
not
None
:
self
.
savestack
.
append
(
self
.
savetext
)
# print '*** Recursively saving text, expect trouble'
self
.
savetext
=
''
# Return the text saved so far and start writing to file again
def
collectsavings
(
self
):
savetext
=
self
.
savetext
if
len
(
self
.
savestack
)
>
0
:
self
.
savetext
=
self
.
savestack
[
-
1
]
del
self
.
savestack
[
-
1
]
else
:
self
.
savetext
=
None
return
savetext
or
''
# Write text to file, or save it in a buffer, or ignore it
def
write
(
self
,
*
args
):
try
:
text
=
''
.
join
(
args
)
except
:
print
(
args
)
raise
TypeError
if
self
.
savetext
is
not
None
:
self
.
savetext
=
self
.
savetext
+
text
elif
self
.
nodefp
:
self
.
nodefp
.
write
(
text
)
elif
self
.
node
:
self
.
node
.
write
(
text
)
# Complete the current node -- write footnotes and close file
def
endnode
(
self
):
if
self
.
savetext
is
not
None
:
print
(
'*** Still saving text at end of node'
)
dummy
=
self
.
collectsavings
()
if
self
.
footnotes
:
self
.
writefootnotes
()
if
self
.
nodefp
:
if
self
.
nodelineno
>
20
:
self
.
write
(
'<HR>
\n
'
)
[
name
,
next
,
prev
,
up
]
=
self
.
nodelinks
[:
4
]
self
.
link
(
'Next'
,
next
)
self
.
link
(
'Prev'
,
prev
)
self
.
link
(
'Up'
,
up
)
if
self
.
nodename
!=
self
.
topname
:
self
.
link
(
'Top'
,
self
.
topname
)
self
.
write
(
'<HR>
\n
'
)
self
.
write
(
'</BODY>
\n
'
)
self
.
nodefp
.
close
()
self
.
nodefp
=
None
elif
self
.
node
:
if
not
self
.
cont
and
\
(
not
self
.
node
.
type
or
\
(
self
.
node
.
next
and
self
.
node
.
prev
and
self
.
node
.
up
)):
self
.
node
.
finalize
()
self
.
node
.
flush
()
else
:
self
.
nodestack
.
append
(
self
.
node
)
self
.
node
=
None
self
.
nodename
=
''
# Process a list of lines, expanding embedded @-commands
# This mostly distinguishes between menus and normal text
def
process
(
self
,
accu
):
if
self
.
debugging
>
1
:
print
(
'!'
*
self
.
debugging
,
'process:'
,
self
.
skip
,
self
.
stack
,
end
=
' '
)
if
accu
:
print
(
accu
[
0
][:
30
],
end
=
' '
)
if
accu
[
0
][
30
:]
or
accu
[
1
:]:
print
(
'...'
,
end
=
' '
)
print
()
if
self
.
inmenu
():
# XXX should be done differently
for
line
in
accu
:
mo
=
miprog
.
match
(
line
)
if
not
mo
:
line
=
line
.
strip
()
+
'
\n
'
self
.
expand
(
line
)
continue
bgn
,
end
=
mo
.
span
(
0
)
a
,
b
=
mo
.
span
(
1
)
c
,
d
=
mo
.
span
(
2
)
e
,
f
=
mo
.
span
(
3
)
g
,
h
=
mo
.
span
(
4
)
label
=
line
[
a
:
b
]
nodename
=
line
[
c
:
d
]
if
nodename
[
0
]
==
':'
:
nodename
=
label
else
:
nodename
=
line
[
e
:
f
]
punct
=
line
[
g
:
h
]
self
.
write
(
' <LI><A HREF="'
,
makefile
(
nodename
),
'">'
,
nodename
,
'</A>'
,
punct
,
'
\n
'
)
self
.
htmlhelp
.
menuitem
(
nodename
)
self
.
expand
(
line
[
end
:])
else
:
text
=
''
.
join
(
accu
)
self
.
expand
(
text
)
# find 'menu' (we might be inside 'ifset' or 'ifclear')
def
inmenu
(
self
):
#if 'menu' in self.stack:
# print 'inmenu :', self.skip, self.stack, self.stackinfo
stack
=
self
.
stack
while
stack
and
stack
[
-
1
]
in
(
'ifset'
,
'ifclear'
):
try
:
if
self
.
stackinfo
[
len
(
stack
)]:
return
0
except
KeyError
:
pass
stack
=
stack
[:
-
1
]
return
(
stack
and
stack
[
-
1
]
==
'menu'
)
# Write a string, expanding embedded @-commands
def
expand
(
self
,
text
):
stack
=
[]
i
=
0
n
=
len
(
text
)
while
i
<
n
:
start
=
i
mo
=
spprog
.
search
(
text
,
i
)
if
mo
:
i
=
mo
.
start
()
else
:
self
.
write
(
text
[
start
:])
break
self
.
write
(
text
[
start
:
i
])
c
=
text
[
i
]
i
=
i
+
1
if
c
==
'
\n
'
:
self
.
write
(
'
\n
'
)
continue
if
c
==
'<'
:
self
.
write
(
'<'
)
continue
if
c
==
'>'
:
self
.
write
(
'>'
)
continue
if
c
==
'&'
:
self
.
write
(
'&'
)
continue
if
c
==
'{'
:
stack
.
append
(
''
)
continue
if
c
==
'}'
:
if
not
stack
:
print
(
'*** Unmatched }'
)
self
.
write
(
'}'
)
continue
cmd
=
stack
[
-
1
]
del
stack
[
-
1
]
try
:
method
=
getattr
(
self
,
'close_'
+
cmd
)
except
AttributeError
:
self
.
unknown_close
(
cmd
)
continue
method
()
continue
if
c
!=
'@'
:
# Cannot happen unless spprog is changed
raise
RuntimeError
(
'unexpected funny %r'
%
c
)
start
=
i
while
i
<
n
and
text
[
i
]
in
string
.
ascii_letters
:
i
=
i
+
1
if
i
==
start
:
# @ plus non-letter: literal next character
i
=
i
+
1
c
=
text
[
start
:
i
]
if
c
==
':'
:
# `@:' means no extra space after
# preceding `.', `?', `!' or `:'
pass
else
:
# `@.' means a sentence-ending period;
# `@@', `@{', `@}' quote `@', `{', `}'
self
.
write
(
c
)
continue
cmd
=
text
[
start
:
i
]
if
i
<
n
and
text
[
i
]
==
'{'
:
i
=
i
+
1
stack
.
append
(
cmd
)
try
:
method
=
getattr
(
self
,
'open_'
+
cmd
)
except
AttributeError
:
self
.
unknown_open
(
cmd
)
continue
method
()
continue
try
:
method
=
getattr
(
self
,
'handle_'
+
cmd
)
except
AttributeError
:
self
.
unknown_handle
(
cmd
)
continue
method
()
if
stack
:
print
(
'*** Stack not empty at para:'
,
stack
)
# --- Handle unknown embedded @-commands ---
def
unknown_open
(
self
,
cmd
):
print
(
'*** No open func for @'
+
cmd
+
'{...}'
)
cmd
=
cmd
+
'{'
self
.
write
(
'@'
,
cmd
)
if
cmd
not
in
self
.
unknown
:
self
.
unknown
[
cmd
]
=
1
else
:
self
.
unknown
[
cmd
]
=
self
.
unknown
[
cmd
]
+
1
def
unknown_close
(
self
,
cmd
):
print
(
'*** No close func for @'
+
cmd
+
'{...}'
)
cmd
=
'}'
+
cmd
self
.
write
(
'}'
)
if
cmd
not
in
self
.
unknown
:
self
.
unknown
[
cmd
]
=
1
else
:
self
.
unknown
[
cmd
]
=
self
.
unknown
[
cmd
]
+
1
def
unknown_handle
(
self
,
cmd
):
print
(
'*** No handler for @'
+
cmd
)
self
.
write
(
'@'
,
cmd
)
if
cmd
not
in
self
.
unknown
:
self
.
unknown
[
cmd
]
=
1
else
:
self
.
unknown
[
cmd
]
=
self
.
unknown
[
cmd
]
+
1
# XXX The following sections should be ordered as the texinfo docs
# --- Embedded @-commands without {} argument list --
def
handle_noindent
(
self
):
pass
def
handle_refill
(
self
):
pass
# --- Include file handling ---
def
do_include
(
self
,
args
):
file
=
args
file
=
os
.
path
.
join
(
self
.
includedir
,
file
)
try
:
fp
=
open
(
file
,
'r'
)
except
IOError
as
msg
:
print
(
'*** Can
\'
t open include file'
,
repr
(
file
))
return
print
(
'!'
*
self
.
debugging
,
'--> file'
,
repr
(
file
))
save_done
=
self
.
done
save_skip
=
self
.
skip
save_stack
=
self
.
stack
self
.
includedepth
=
self
.
includedepth
+
1
self
.
parserest
(
fp
,
0
)
self
.
includedepth
=
self
.
includedepth
-
1
fp
.
close
()
self
.
done
=
save_done
self
.
skip
=
save_skip
self
.
stack
=
save_stack
print
(
'!'
*
self
.
debugging
,
'<-- file'
,
repr
(
file
))
# --- Special Insertions ---
def
open_dmn
(
self
):
pass
def
close_dmn
(
self
):
pass
def
open_dots
(
self
):
self
.
write
(
'...'
)
def
close_dots
(
self
):
pass
def
open_bullet
(
self
):
pass
def
close_bullet
(
self
):
pass
def
open_TeX
(
self
):
self
.
write
(
'TeX'
)
def
close_TeX
(
self
):
pass
def
handle_copyright
(
self
):
self
.
write
(
self
.
COPYRIGHT_SYMBOL
)
def
open_copyright
(
self
):
self
.
write
(
self
.
COPYRIGHT_SYMBOL
)
def
close_copyright
(
self
):
pass
def
open_minus
(
self
):
self
.
write
(
'-'
)
def
close_minus
(
self
):
pass
# --- Accents ---
# rpyron 2002-05-07
# I would like to do at least as well as makeinfo when
# it is producing HTML output:
#
# input output
# @"o @"o umlaut accent
# @'o 'o acute accent
# @,{c} @,{c} cedilla accent
# @=o @=o macron/overbar accent
# @^o @^o circumflex accent
# @`o `o grave accent
# @~o @~o tilde accent
# @dotaccent{o} @dotaccent{o} overdot accent
# @H{o} @H{o} long Hungarian umlaut
# @ringaccent{o} @ringaccent{o} ring accent
# @tieaccent{oo} @tieaccent{oo} tie-after accent
# @u{o} @u{o} breve accent
# @ubaraccent{o} @ubaraccent{o} underbar accent
# @udotaccent{o} @udotaccent{o} underdot accent
# @v{o} @v{o} hacek or check accent
# @exclamdown{} ¡ upside-down !
# @questiondown{} ¿ upside-down ?
# @aa{},@AA{} å,Å a,A with circle
# @ae{},@AE{} æ,Æ ae,AE ligatures
# @dotless{i} @dotless{i} dotless i
# @dotless{j} @dotless{j} dotless j
# @l{},@L{} l/,L/ suppressed-L,l
# @o{},@O{} ø,Ø O,o with slash
# @oe{},@OE{} oe,OE oe,OE ligatures
# @ss{} ß es-zet or sharp S
#
# The following character codes and approximations have been
# copied from makeinfo's HTML output.
def
open_exclamdown
(
self
):
self
.
write
(
'¡'
)
# upside-down !
def
close_exclamdown
(
self
):
pass
def
open_questiondown
(
self
):
self
.
write
(
'¿'
)
# upside-down ?
def
close_questiondown
(
self
):
pass
def
open_aa
(
self
):
self
.
write
(
'å'
)
# a with circle
def
close_aa
(
self
):
pass
def
open_AA
(
self
):
self
.
write
(
'Å'
)
# A with circle
def
close_AA
(
self
):
pass
def
open_ae
(
self
):
self
.
write
(
'æ'
)
# ae ligatures
def
close_ae
(
self
):
pass
def
open_AE
(
self
):
self
.
write
(
'Æ'
)
# AE ligatures
def
close_AE
(
self
):
pass
def
open_o
(
self
):
self
.
write
(
'ø'
)
# o with slash
def
close_o
(
self
):
pass
def
open_O
(
self
):
self
.
write
(
'Ø'
)
# O with slash
def
close_O
(
self
):
pass
def
open_ss
(
self
):
self
.
write
(
'ß'
)
# es-zet or sharp S
def
close_ss
(
self
):
pass
def
open_oe
(
self
):
self
.
write
(
'oe'
)
# oe ligatures
def
close_oe
(
self
):
pass
def
open_OE
(
self
):
self
.
write
(
'OE'
)
# OE ligatures
def
close_OE
(
self
):
pass
def
open_l
(
self
):
self
.
write
(
'l/'
)
# suppressed-l
def
close_l
(
self
):
pass
def
open_L
(
self
):
self
.
write
(
'L/'
)
# suppressed-L
def
close_L
(
self
):
pass
# --- Special Glyphs for Examples ---
def
open_result
(
self
):
self
.
write
(
'=>'
)
def
close_result
(
self
):
pass
def
open_expansion
(
self
):
self
.
write
(
'==>'
)
def
close_expansion
(
self
):
pass
def
open_print
(
self
):
self
.
write
(
'-|'
)
def
close_print
(
self
):
pass
def
open_error
(
self
):
self
.
write
(
'error-->'
)
def
close_error
(
self
):
pass
def
open_equiv
(
self
):
self
.
write
(
'=='
)
def
close_equiv
(
self
):
pass
def
open_point
(
self
):
self
.
write
(
'-!-'
)
def
close_point
(
self
):
pass
# --- Cross References ---
def
open_pxref
(
self
):
self
.
write
(
'see '
)
self
.
startsaving
()
def
close_pxref
(
self
):
self
.
makeref
()
def
open_xref
(
self
):
self
.
write
(
'See '
)
self
.
startsaving
()
def
close_xref
(
self
):
self
.
makeref
()
def
open_ref
(
self
):
self
.
startsaving
()
def
close_ref
(
self
):
self
.
makeref
()
def
open_inforef
(
self
):
self
.
write
(
'See info file '
)
self
.
startsaving
()
def
close_inforef
(
self
):
text
=
self
.
collectsavings
()
args
=
[
s
.
strip
()
for
s
in
text
.
split
(
','
)]
while
len
(
args
)
<
3
:
args
.
append
(
''
)
node
=
args
[
0
]
file
=
args
[
2
]
self
.
write
(
'`'
,
file
,
'
\'
, node `'
,
node
,
'
\'
'
)
def
makeref
(
self
):
text
=
self
.
collectsavings
()
args
=
[
s
.
strip
()
for
s
in
text
.
split
(
','
)]
while
len
(
args
)
<
5
:
args
.
append
(
''
)
nodename
=
label
=
args
[
0
]
if
args
[
2
]:
label
=
args
[
2
]
file
=
args
[
3
]
title
=
args
[
4
]
href
=
makefile
(
nodename
)
if
file
:
href
=
'../'
+
file
+
'/'
+
href
self
.
write
(
'<A HREF="'
,
href
,
'">'
,
label
,
'</A>'
)
# rpyron 2002-05-07 uref support
def
open_uref
(
self
):
self
.
startsaving
()
def
close_uref
(
self
):
text
=
self
.
collectsavings
()
args
=
[
s
.
strip
()
for
s
in
text
.
split
(
','
)]
while
len
(
args
)
<
2
:
args
.
append
(
''
)
href
=
args
[
0
]
label
=
args
[
1
]
if
not
label
:
label
=
href
self
.
write
(
'<A HREF="'
,
href
,
'">'
,
label
,
'</A>'
)
# rpyron 2002-05-07 image support
# GNU makeinfo producing HTML output tries `filename.png'; if
# that does not exist, it tries `filename.jpg'. If that does
# not exist either, it complains. GNU makeinfo does not handle
# GIF files; however, I include GIF support here because
# MySQL documentation uses GIF files.
def
open_image
(
self
):
self
.
startsaving
()
def
close_image
(
self
):
self
.
makeimage
()
def
makeimage
(
self
):
text
=
self
.
collectsavings
()
args
=
[
s
.
strip
()
for
s
in
text
.
split
(
','
)]
while
len
(
args
)
<
5
:
args
.
append
(
''
)
filename
=
args
[
0
]
width
=
args
[
1
]
height
=
args
[
2
]
alt
=
args
[
3
]
ext
=
args
[
4
]
# The HTML output will have a reference to the image
# that is relative to the HTML output directory,
# which is what 'filename' gives us. However, we need
# to find it relative to our own current directory,
# so we construct 'imagename'.
imagelocation
=
self
.
dirname
+
'/'
+
filename
if
os
.
path
.
exists
(
imagelocation
+
'.png'
):
filename
+=
'.png'
elif
os
.
path
.
exists
(
imagelocation
+
'.jpg'
):
filename
+=
'.jpg'
elif
os
.
path
.
exists
(
imagelocation
+
'.gif'
):
# MySQL uses GIF files
filename
+=
'.gif'
else
:
print
(
"*** Cannot find image "
+
imagelocation
)
#TODO: what is 'ext'?
self
.
write
(
'<IMG SRC="'
,
filename
,
'"'
, \
width
and
(
' WIDTH="'
+
width
+
'"'
)
or
""
, \
height
and
(
' HEIGHT="'
+
height
+
'"'
)
or
""
, \
alt
and
(
' ALT="'
+
alt
+
'"'
)
or
""
, \
'/>'
)
self
.
htmlhelp
.
addimage
(
imagelocation
)
# --- Marking Words and Phrases ---
# --- Other @xxx{...} commands ---
def
open_
(
self
):
pass
# Used by {text enclosed in braces}
def
close_
(
self
):
pass
open_asis
=
open_
close_asis
=
close_
def
open_cite
(
self
):
self
.
write
(
'<CITE>'
)
def
close_cite
(
self
):
self
.
write
(
'</CITE>'
)
def
open_code
(
self
):
self
.
write
(
'<CODE>'
)
def
close_code
(
self
):
self
.
write
(
'</CODE>'
)
def
open_t
(
self
):
self
.
write
(
'<TT>'
)
def
close_t
(
self
):
self
.
write
(
'</TT>'
)
def
open_dfn
(
self
):
self
.
write
(
'<DFN>'
)
def
close_dfn
(
self
):
self
.
write
(
'</DFN>'
)
def
open_emph
(
self
):
self
.
write
(
'<EM>'
)
def
close_emph
(
self
):
self
.
write
(
'</EM>'
)
def
open_i
(
self
):
self
.
write
(
'<I>'
)
def
close_i
(
self
):
self
.
write
(
'</I>'
)
def
open_footnote
(
self
):
# if self.savetext is not None:
# print '*** Recursive footnote -- expect weirdness'
id
=
len
(
self
.
footnotes
)
+
1
self
.
write
(
self
.
FN_SOURCE_PATTERN
%
{
'id'
:
repr
(
id
)})
self
.
startsaving
()
def
close_footnote
(
self
):
id
=
len
(
self
.
footnotes
)
+
1
self
.
footnotes
.
append
((
id
,
self
.
collectsavings
()))
def
writefootnotes
(
self
):
self
.
write
(
self
.
FN_HEADER
)
for
id
,
text
in
self
.
footnotes
:
self
.
write
(
self
.
FN_TARGET_PATTERN
%
{
'id'
:
repr
(
id
),
'text'
:
text
})
self
.
footnotes
=
[]
def
open_file
(
self
):
self
.
write
(
'<CODE>'
)
def
close_file
(
self
):
self
.
write
(
'</CODE>'
)
def
open_kbd
(
self
):
self
.
write
(
'<KBD>'
)
def
close_kbd
(
self
):
self
.
write
(
'</KBD>'
)
def
open_key
(
self
):
self
.
write
(
'<KEY>'
)
def
close_key
(
self
):
self
.
write
(
'</KEY>'
)
def
open_r
(
self
):
self
.
write
(
'<R>'
)
def
close_r
(
self
):
self
.
write
(
'</R>'
)
def
open_samp
(
self
):
self
.
write
(
'`<SAMP>'
)
def
close_samp
(
self
):
self
.
write
(
'</SAMP>
\'
'
)
def
open_sc
(
self
):
self
.
write
(
'<SMALLCAPS>'
)
def
close_sc
(
self
):
self
.
write
(
'</SMALLCAPS>'
)
def
open_strong
(
self
):
self
.
write
(
'<STRONG>'
)
def
close_strong
(
self
):
self
.
write
(
'</STRONG>'
)
def
open_b
(
self
):
self
.
write
(
'<B>'
)
def
close_b
(
self
):
self
.
write
(
'</B>'
)
def
open_var
(
self
):
self
.
write
(
'<VAR>'
)
def
close_var
(
self
):
self
.
write
(
'</VAR>'
)
def
open_w
(
self
):
self
.
write
(
'<NOBREAK>'
)
def
close_w
(
self
):
self
.
write
(
'</NOBREAK>'
)
def
open_url
(
self
):
self
.
startsaving
()
def
close_url
(
self
):
text
=
self
.
collectsavings
()
self
.
write
(
'<A HREF="'
,
text
,
'">'
,
text
,
'</A>'
)
def
open_email
(
self
):
self
.
startsaving
()
def
close_email
(
self
):
text
=
self
.
collectsavings
()
self
.
write
(
'<A HREF="mailto:'
,
text
,
'">'
,
text
,
'</A>'
)
open_titlefont
=
open_
close_titlefont
=
close_
def
open_small
(
self
):
pass
def
close_small
(
self
):
pass
def
command
(
self
,
line
,
mo
):
a
,
b
=
mo
.
span
(
1
)
cmd
=
line
[
a
:
b
]
args
=
line
[
b
:].
strip
()
if
self
.
debugging
>
1
:
print
(
'!'
*
self
.
debugging
,
'command:'
,
self
.
skip
,
self
.
stack
, \
'@'
+
cmd
,
args
)
try
:
func
=
getattr
(
self
,
'do_'
+
cmd
)
except
AttributeError
:
try
:
func
=
getattr
(
self
,
'bgn_'
+
cmd
)
except
AttributeError
:
# don't complain if we are skipping anyway
if
not
self
.
skip
:
self
.
unknown_cmd
(
cmd
,
args
)
return
self
.
stack
.
append
(
cmd
)
func
(
args
)
return
if
not
self
.
skip
or
cmd
==
'end'
:
func
(
args
)
def
unknown_cmd
(
self
,
cmd
,
args
):
print
(
'*** unknown'
,
'@'
+
cmd
,
args
)
if
cmd
not
in
self
.
unknown
:
self
.
unknown
[
cmd
]
=
1
else
:
self
.
unknown
[
cmd
]
=
self
.
unknown
[
cmd
]
+
1
def
do_end
(
self
,
args
):
words
=
args
.
split
()
if
not
words
:
print
(
'*** @end w/o args'
)
else
:
cmd
=
words
[
0
]
if
not
self
.
stack
or
self
.
stack
[
-
1
]
!=
cmd
:
print
(
'*** @end'
,
cmd
,
'unexpected'
)
else
:
del
self
.
stack
[
-
1
]
try
:
func
=
getattr
(
self
,
'end_'
+
cmd
)
except
AttributeError
:
self
.
unknown_end
(
cmd
)
return
func
()
def
unknown_end
(
self
,
cmd
):
cmd
=
'end '
+
cmd
print
(
'*** unknown'
,
'@'
+
cmd
)
if
cmd
not
in
self
.
unknown
:
self
.
unknown
[
cmd
]
=
1
else
:
self
.
unknown
[
cmd
]
=
self
.
unknown
[
cmd
]
+
1
# --- Comments ---
def
do_comment
(
self
,
args
):
pass
do_c
=
do_comment
# --- Conditional processing ---
def
bgn_ifinfo
(
self
,
args
):
pass
def
end_ifinfo
(
self
):
pass
def
bgn_iftex
(
self
,
args
):
self
.
skip
=
self
.
skip
+
1
def
end_iftex
(
self
):
self
.
skip
=
self
.
skip
-
1
def
bgn_ignore
(
self
,
args
):
self
.
skip
=
self
.
skip
+
1
def
end_ignore
(
self
):
self
.
skip
=
self
.
skip
-
1
def
bgn_tex
(
self
,
args
):
self
.
skip
=
self
.
skip
+
1
def
end_tex
(
self
):
self
.
skip
=
self
.
skip
-
1
def
do_set
(
self
,
args
):
fields
=
args
.
split
(
' '
)
key
=
fields
[
0
]
if
len
(
fields
)
==
1
:
value
=
1
else
:
value
=
' '
.
join
(
fields
[
1
:])
self
.
values
[
key
]
=
value
def
do_clear
(
self
,
args
):
self
.
values
[
args
]
=
None
def
bgn_ifset
(
self
,
args
):
if
args
not
in
self
.
values
or
self
.
values
[
args
]
is
None
:
self
.
skip
=
self
.
skip
+
1
self
.
stackinfo
[
len
(
self
.
stack
)]
=
1
else
:
self
.
stackinfo
[
len
(
self
.
stack
)]
=
0
def
end_ifset
(
self
):
try
:
if
self
.
stackinfo
[
len
(
self
.
stack
)
+
1
]:
self
.
skip
=
self
.
skip
-
1
del
self
.
stackinfo
[
len
(
self
.
stack
)
+
1
]
except
KeyError
:
print
(
'*** end_ifset: KeyError :'
,
len
(
self
.
stack
)
+
1
)
def
bgn_ifclear
(
self
,
args
):
if
args
in
self
.
values
and
self
.
values
[
args
]
is
not
None
:
self
.
skip
=
self
.
skip
+
1
self
.
stackinfo
[
len
(
self
.
stack
)]
=
1
else
:
self
.
stackinfo
[
len
(
self
.
stack
)]
=
0
def
end_ifclear
(
self
):
try
:
if
self
.
stackinfo
[
len
(
self
.
stack
)
+
1
]:
self
.
skip
=
self
.
skip
-
1
del
self
.
stackinfo
[
len
(
self
.
stack
)
+
1
]
except
KeyError
:
print
(
'*** end_ifclear: KeyError :'
,
len
(
self
.
stack
)
+
1
)
def
open_value
(
self
):
self
.
startsaving
()
def
close_value
(
self
):
key
=
self
.
collectsavings
()
if
key
in
self
.
values
:
self
.
write
(
self
.
values
[
key
])
else
:
print
(
'*** Undefined value: '
,
key
)
# --- Beginning a file ---
do_finalout
=
do_comment
do_setchapternewpage
=
do_comment
do_setfilename
=
do_comment
def
do_settitle
(
self
,
args
):
View remainder of file in raw view
Back
|
FazBrowse Home
|
New Git URL