-
Notifications
You must be signed in to change notification settings - Fork 0
/
jemdoc.py.html
350 lines (339 loc) · 11.9 KB
/
jemdoc.py.html
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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta name="generator" content="jemdoc, see http://jemdoc.jaboc.net/" />
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="jemdoc.css" type="text/css" />
<title></title>
</head>
<body>
<div id="layout-content">
<p>“”“jemdoc version 0.7.1, 2011-06-14.”“”</p>
<p>import sys
import os
import re
import time
import StringIO
from subprocess import *
import tempfile</p>
<p>def info():
print __doc__
print 'Platform: ’ <tt> sys.platform </tt> ’.’
print 'Python: <tt>s, located at </tt>s.’ % (sys.version<a href=":5">:5</a>, sys.executable)
print 'Equation support:’,
(supported, message) = testeqsupport()
if supported:
print 'yes.’
else:
print 'no.’
print message</p>
<p>def testeqsupport():
supported = True
msg = ’’
p = Popen('latex –version’, shell=True, stdout=PIPE, stderr=PIPE)
rc = p.wait()
if rc != 0:
msg <tt>= ’ latex: not found.<br />’
supported = False
else:
msg </tt>= ’ latex: ’ <tt> p.stdout.readlines()<a href="0">0</a>.rstrip() </tt> ’.<br />’
p = Popen('dvipng –version’, shell=True, stdout=PIPE, stderr=PIPE)
rc = p.wait()
if rc != 0:
msg <tt>= ’ dvipng: not found.<br />’
supported = False
else:
msg </tt>= ’ dvipng: ’ <tt> p.stdout.readlines()<a href="0">0</a>.rstrip() </tt> ’.<br />’</p>
<p>return (supported, msg<a href=":-1">:-1</a>)</p>
<p>class controlstruct(object):
def __init__(self, infile, outfile=None, conf=None, inname=None, eqs=True,
eqdir='eqs’, eqdpi=130):
self.inname = inname
self.inf = infile
self.outf = outfile
self.conf = conf
self.linenum = 0
self.otherfiles = <a href=""></a>
self.eqs = eqs
self.eqdir = eqdir
self.eqdpi = eqdpi
self.eqsupport = True
self.eqcache = True
self.eqpackages = <a href=""></a>
self.texlines = <a href=""></a>
self.analytics = None
self.eqbd = {}
self.baseline = None</p>
<p>def pushfile(self, newfile):
self.otherfiles.insert(0, self.inf)
self.inf = open(newfile, 'rb’)</p>
<p>def nextfile(self):
self.inf.close()
self.inf = self.otherfiles.pop(0)</p>
<p>def showhelp():
a = “”"Usage: jemdoc <a href="OPTIONS">OPTIONS</a> <a href="SOURCEFILE">SOURCEFILE</a>
Produces html markup from a jemdoc SOURCEFILE.</p>
<p>Most of the time you can use jemdoc without any additional flags.
For example, typing</p>
<p>jemdoc index</p>
<p>will produce an index.html from index.jemdoc, using a default
configuration.</p>
<p>Some configuration options can be overridden by specifying a
configuration file. You can use</p>
<p>jemdoc –show-config</p>
<p>to print a sample configuration file (which includes all of the
default options). Any or all of the configuration <a href="blocks">blocks</a> can be
overwritten by including them in a configuration file, and running,
for example,</p>
<p>jemdoc -c mywebsite.conf index.jemdoc </p>
<p>You can view version and installation details with</p>
<p>jemdoc –version</p>
<p>See http:<i></i>jemdoc.jaboc.net/ for many more details.“”"
b = ’’
for l in a.splitlines(True):
if l.startswith(’ ’*4):
b <tt>= l<a href="4:">4:</a>
else:
b </tt>= l</p>
<p>print b</p>
<p>def standardconf():
a = “”“<a href="firstbit">firstbit</a>
<!DOCTYPE html PUBLIC ”-<i></i>W3C<i></i>DTD XHTML 1.1<i></i>EN“
”http:<i></i>www.w3.org<i>TR</i>xhtml11<i>DTD</i>xhtml11.dtd“>
<html xmlns=”http:<i></i>www.w3.org<i>1999</i>xhtml“ xml:lang=”en“>
<head>
<meta name=”generator“ content=”jemdoc, see http:<i></i>jemdoc.jaboc.net<i>“ </i>>
<meta http-equiv=”Content-Type“ content=”text<i>html;charset=utf-8" </i>></p>
<p><a href="defaultcss">defaultcss</a>
<link rel=“stylesheet” href=“jemdoc.css” type=“text<i>css” </i>></p>
<p><a href="windowtitle">windowtitle</a>
<title>|</title></p>
<p><a href="fwtitlestart">fwtitlestart</a>
<div id=“fwtitle”></p>
<p><a href="fwtitleend">fwtitleend</a>
</div></p>
<p><a href="doctitle">doctitle</a>
<div id=“toptitle”>
<h1>|</h1></p>
<p><a href="subtitle">subtitle</a>
<div id=“subtitle”>|</div></p>
<p><a href="doctitleend">doctitleend</a>
</div></p>
<p><a href="bodystart">bodystart</a>
</head>
<body></p>
<p><a href="analytics">analytics</a>
<script type=“text<i>javascript”>
var gaJsHost = ((“https:” == document.location.protocol) ? “https:</i><i>ssl.” : “http:</i><i>www.”);
document.write(unescape(“<tt>3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'</tt>3E<tt>3C/script</tt>3E”));
<</i>script>
<script type=“text<i>javascript”>
try {
var pageTracker = _gat._getTracker(“|”);
pageTracker._trackPageview();
} catch(err) {}<</i>script></p>
<p><a href="menustart">menustart</a>
<table summary=“Table for page layout.” id=“tlayout”>
<tr valign=“top”>
<td id=“layout-menu”></p>
<p><a href="menuend">menuend</a>
</td>
<td id=“layout-content”></p>
<p><a href="menucategory">menucategory</a>
<div class=“menu-category”>|</div></p>
<p><a href="menuitem">menuitem</a>
<div class=“menu-item”><a href=“|1”>|2<<i>a><</i>div></p>
<p><a href="specificcss">specificcss</a>
<link rel=“stylesheet” href=“|” type=“text<i>css” </i>></p>
<p><a href="specificjs">specificjs</a>
<script src=“|.js” type=“text<i>javascript”><</i>script></p>
<p><a href="currentmenuitem">currentmenuitem</a>
<div class=“menu-item”><a href=“|1” class=“current”>|2<<i>a><</i>div></p>
<p><a href="nomenu">nomenu</a>
<div id=“layout-content”></p>
<p><a href="menulastbit">menulastbit</a>
<<i>td>
<</i>tr>
</table></p>
<p><a href="nomenulastbit">nomenulastbit</a>
</div></p>
<p><a href="bodyend">bodyend</a>
<<i>body>
<</i>html></p>
<p><a href="infoblock">infoblock</a>
<div class=“infoblock”></p>
<p><a href="codeblock">codeblock</a>
<div class=“codeblock”></p>
<p><a href="blocktitle">blocktitle</a>
<div class=“blocktitle”>|</div></p>
<p><a href="infoblockcontent">infoblockcontent</a>
<div class=“blockcontent”></p>
<p><a href="codeblockcontent">codeblockcontent</a>
<div class=“blockcontent”><pre></p>
<p><a href="codeblockend">codeblockend</a>
<<i>pre><</i>div></div></p>
<p><a href="codeblockcontenttt">codeblockcontenttt</a>
<div class=“blockcontent”><tt class=“tthl”></p>
<p><a href="codeblockendtt">codeblockendtt</a>
<<i>tt><</i>div></div></p>
<p><a href="infoblockend">infoblockend</a>
<<i>div><</i>div></p>
<p><a href="footerstart">footerstart</a>
<div id=“footer”>
<div id=“footer-text”></p>
<p><a href="footerend">footerend</a>
<<i>div>
<</i>div></p>
<p><a href="lastupdated">lastupdated</a>
<a href=“http:<i></i>www4.ncsu.edu<i> ipapapa</i>”>Ioannis Papapanagiotou</a></p>
<p><a href="sourcelink">sourcelink</a>
(<a href=“|”>source</a>)</p>
<p>“”"
b = ’’
for l in a.splitlines(True):
if l.startswith(’ ’):
b <tt>= l<a href="2:">2:</a>
else:
b </tt>= l</p>
<p>return b</p>
<p>class JandalError(Exception):
pass</p>
<p>class NoEqSupport(Exception):
pass</p>
<p>def raisejandal(msg, line=0):
if line == 0:
s = “<tt>s" </tt> msg
else:
s = ”line <tt>d: </tt>s" % (line, msg)
raise JandalError(s)</p>
<p>def readnoncomment(f):
l = f.readline()
if l == ’’:
return l
elif l<a href="0">0</a> == ’
return readnoncomment(f)
else:
return l.rstrip() + ’<br />’</p>
<p>def parseconf(cns):
syntax = {}
warn = False
fs = <a href="StringIO.StringIO(standardconf())">StringIO.StringIO(standardconf())</a>
for sname in cns:
fs.append(open(sname, 'rb’))</p>
<p>for f in fs:
while pc(controlstruct(f)) != ’’:
l = readnoncomment(f)
r = re.match(r’[(.*)]<br />’, l)</p>
<p>if r:
tag = r.group(1)</p>
<p>s = ’’
l = readnoncomment(f)
while l not in (’<br />’, ’’):
s += l
l = readnoncomment(f)</p>
<p>syntax<a href="tag">tag</a> = s</p>
<p>f.close()</p>
<p>return syntax</p>
<p>def insertmenuitems(f, mname, current, prefix):
m = open(mname, 'rb’)
while pc(controlstruct(m)) != ’’:
l = readnoncomment(m)
l = l.strip()
if l == ’’:
continue</p>
<p>r = re.match(r’s<b>(.</b>?)s<b>[(.</b>)]’, l)</p>
<p>if r:
link = r.group(2)
if ’:<i></i>’ not in r.group(2):
link = prefix + allreplace(link)</p>
<p>menuitem = re.sub(r’(?<!
) +’, ’ ’, r.group(1))</p>
<p>if r.group(2) == current:
hb(f.outf, f.conf<a href="'currentmenuitem'">'currentmenuitem'</a>, link, br(menuitem, f))
else:
hb(f.outf, f.conf<a href="'menuitem'">'menuitem'</a>, link, br(menuitem, f))</p>
<p>else:
hb(f.outf, f.conf<a href="'menucategory'">'menucategory'</a>, br(l, f))</p>
<p>m.close()</p>
<p>def out(f, s):
f.write(s)</p>
<p>def hb(f, tag, content1, content2=None):
“”“Writes out a halfblock (hb).”“”</p>
<p>if content1 is None:
content1 = “”</p>
<p>if content2 is None:
out(f, re.sub(r’|’, content1, tag))
else:
r = re.sub(r’|1’, content1, tag)
r = re.sub(r’|2’, content2, r)
out(f, r)</p>
<p>def pc(f, ditchcomments=True):
“”“Peeks at next character in the file.”“”
c = f.inf.read(1)
if c:
if ditchcomments and c == ’
l = nl(f)
if doincludes(f, l):
return "</p>
<p>if c in ’ t’:
return pc(f)</p>
<p>if c == '\’:
c += pc(f)</p>
<p>f.inf.seek(-1, 1)
elif f.otherfiles:
f.nextfile()
return pc(f, ditchcomments)</p>
<p>return c</p>
<p>def doincludes(f, l):
ir = 'includeraw{’
i = 'include{’
if l.startswith(ir):
nf = open(l<a href="len(ir):-2">len(ir):-2</a>, 'rb’)
f.outf.write(nf.read())
nf.close()
elif l.startswith(i):
f.pushfile(l<a href="len(i):-2">len(i):-2</a>)
else:
return False</p>
<p>return True</p>
<p>def nl(f, withcount=False, codemode=False):
“”“Get input file line.”“”
s = f.inf.readline()
if not s and f.otherfiles:
f.nextfile()
return nl(f, withcount, codemode)</p>
<p>f.linenum += 1</p>
<p>if not codemode:
s = s.lstrip(’ t’)
s = re.sub(r’s*(?<!\)</p>
<p>if withcount:
if s<a href="0">0</a> == ’.’:
m = r’.’
else:
m = s<a href="0">0</a></p>
<p>r = re.match(’(<tt>s+) ' </tt> m, s)
if not r:
raise SyntaxError(“couldn't handle the jandal (code 12039) on line”
" <tt>d" </tt> f.linenum)</p>
<p>if not codemode:
s = s.lstrip(’-.=:’)</p>
<p>return (s, len(r.group(1)))
else:
if not codemode:
s = s.lstrip(’-.=:’)</p>
<p>return s</p>
<p>def np(f, withcount=False, eatblanks=True):
“”“Gets the next paragraph from the input file.”“”
if withcount:
(s, c) = nl(f, withcount)
else:
s = nl(f)</p>
<p>while pc(f) not in (’<br />’, ’-’, ’.’, ’:’, ’’, ’=’, ’ ’, ’{’, '\(’, '\)’):
s += nl(f)</p>
<p>while eatblanks and pc(f) == ’<br />’:
nl(f)</p>
<p>if withcount:
return (s<a href=":-1">:-1</a>, c)
else:
return s<a href=":-1">:-1</a></p>