This repository has been archived by the owner on Apr 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
/
docwiki.cgi
165 lines (123 loc) · 3.59 KB
/
docwiki.cgi
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
#!/usr/bin/python
#################################
reldocpath = "doc_wiki/"
thisfile = "docwiki.cgi"
#################################
from sys import exit
import re
int_link_re = re.compile("\[\[.+\]\]")
import cgitb
cgitb.enable()
from cgi import FieldStorage
form = FieldStorage()
def fileExists(fname):
try:
open(fname)
return True
except IOError:
return False
def printContentType():
print "Content-Type: text/html\n\n"
def convert(string):
slist = re.split("\[\[(.+?)\]\]",string)
mdstring = slist[0]
for j in range(1,len(slist)):
chunk = slist[j]
if j%2 == 0:
mdstring += chunk
else:
fname = reldocpath + chunk
if not fileExists(fname+'.md'):
open(fname+'.md','w')
open(fname+'.html','w')
mdstring += "[" + chunk + "](" + thisfile + "?page=" + chunk + ")"
import markdown2
return markdown2.markdown(mdstring)
md = form.getvalue("value")
page = form.getvalue("page")
if page == None: page = "main"
mdfname = page + ".md"
htfname = page + ".html"
bodyhtml = ""
if md:
mdfile = open(reldocpath + mdfname,'w')
mdfile.write(md)
mdfile.close()
bodyhtml = convert(md)
htfile = open(reldocpath + htfname,'w')
htfile.write(bodyhtml)
htfile.close()
printContentType()
print bodyhtml
exit(0)
else:
htfile = open(reldocpath + htfname,'r')
bodyhtml = "".join(htfile.readlines())
htfile.close()
header = \
"""
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ITensor - Intelligent Tensor Library</title>
<meta http-equiv="content-language" content="en" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<link rel="icon" href="favicon.ico"/>
<link rel="stylesheet" href="style.css" type="text/css"/>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">$(document).ready(function(){});</script>
<script type="text/javascript" src="scripts/jquery.corner.js"></script>
<script type="text/javascript" src="scripts/jquery.jeditable.mini.js"></script>
<script type="text/javascript" src="scripts/jquery.autogrow.js"></script>
<script type="text/javascript" src="scripts/jquery.jeditable.autogrow.js"></script>
<style type="text/css">
</style>
</head>
<body>
<div id="main">
<div id="navbar" class="rounded">
<ul>
<li><a href="index.html">Home</a> </li>
<li><a href="news.html">News</a> </li>
<li><a class="thispage" href="%s">Learn</a> </li>
<li><a href="contribute.html">Contribute</a></li>
</ul>
</div>
<div id="banner">
<img src="ITensor.png" /></br>
</div>
<div class="full section rounded"> <h2>Documentation</h2> </div>
<div class="full">
<p>
</p>
</div>
<div class="full edit docs" id="input">
"""%(thisfile,)
footer = \
"""
</div>
<div id="footer"></div>
<script type="text/javascript">
$(document).ready(function() {
$('.edit').editable("%s?page=%s", {
type : "textarea",
event : "dblclick",
onblur : "ignore",
cancel : "Cancel",
submit : "OK",
indicator : 'Saving...',
loadurl : "docs/%s.md",
loadtype : 'POST'
});
});
</script>
</div> <!--class="main"-->
<script type="text/javascript">$(function() {$('.rounded').corner("7px");});</script>
</body>
</html>
""" \
% (thisfile,page,page)
printContentType()
print header
print bodyhtml
print footer