Skip to content

Commit 2a521f6

Browse files
author
yxdragon
committed
markdown math
1 parent 43cd5c4 commit 2a521f6

File tree

4 files changed

+185
-169
lines changed

4 files changed

+185
-169
lines changed

imagepy/data/markdown.css

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
h1,
2+
h2,
3+
h3,
4+
h4,
5+
h5,
6+
h6,
7+
p,
8+
blockquote {
9+
margin: 0;
10+
padding: 0;
11+
}
12+
body {
13+
font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", Arial, sans-serif;
14+
font-size: 13px;
15+
line-height: 18px;
16+
color: #737373;
17+
background-color: white;
18+
margin: 10px 13px 10px 13px;
19+
}
20+
table {
21+
margin: 10px 0 15px 0;
22+
border-collapse: collapse;
23+
}
24+
td,th {
25+
border: 1px solid #ddd;
26+
padding: 3px 10px;
27+
}
28+
th {
29+
padding: 5px 10px;
30+
}
31+
32+
a {
33+
color: #0069d6;
34+
}
35+
a:hover {
36+
color: #0050a3;
37+
text-decoration: none;
38+
}
39+
a img {
40+
border: none;
41+
}
42+
p {
43+
margin-bottom: 9px;
44+
}
45+
p img {
46+
width:100%%;
47+
}
48+
h1,
49+
h2,
50+
h3,
51+
h4,
52+
h5,
53+
h6 {
54+
color: #404040;
55+
line-height: 36px;
56+
}
57+
h1 {
58+
margin-bottom: 18px;
59+
font-size: 30px;
60+
}
61+
h2 {
62+
font-size: 24px;
63+
}
64+
h3 {
65+
font-size: 18px;
66+
}
67+
h4 {
68+
font-size: 16px;
69+
}
70+
h5 {
71+
font-size: 14px;
72+
}
73+
h6 {
74+
font-size: 13px;
75+
}
76+
hr {
77+
margin: 0 0 19px;
78+
border: 0;
79+
border-bottom: 1px solid #ccc;
80+
}
81+
blockquote {
82+
padding: 13px 13px 21px 15px;
83+
margin-bottom: 18px;
84+
font-family:georgia,serif;
85+
font-style: italic;
86+
}
87+
blockquote:before {
88+
content:"\201C";
89+
font-size:40px;
90+
margin-left:-10px;
91+
font-family:georgia,serif;
92+
color:#eee;
93+
}
94+
blockquote p {
95+
font-size: 14px;
96+
font-weight: 300;
97+
line-height: 18px;
98+
margin-bottom: 0;
99+
font-style: italic;
100+
}
101+
code, pre {
102+
font-family: Monaco, Andale Mono, Courier New, monospace;
103+
}
104+
code {
105+
background-color: #fee9cc;
106+
color: rgba(0, 0, 0, 0.75);
107+
padding: 1px 3px;
108+
font-size: 12px;
109+
-webkit-border-radius: 3px;
110+
-moz-border-radius: 3px;
111+
border-radius: 3px;
112+
}
113+
pre {
114+
display: block;
115+
padding: 14px;
116+
margin: 0 0 18px;
117+
line-height: 16px;
118+
font-size: 11px;
119+
border: 1px solid #d9d9d9;
120+
white-space: pre-wrap;
121+
word-wrap: break-word;
122+
}
123+
pre code {
124+
background-color: #fff;
125+
color:#737373;
126+
font-size: 11px;
127+
padding: 0;
128+
}
129+
sup {
130+
font-size: 0.83em;
131+
vertical-align: super;
132+
line-height: 0;
133+
}
134+
* {
135+
-webkit-print-color-adjust: exact;
136+
}
137+
@media screen and (min-width: 914px) {
138+
body {
139+
width: 854px;
140+
margin:10px auto;
141+
}
142+
}
143+
@media print {
144+
body,code,pre code,h1,h2,h3,h4,h5,h6 {
145+
color: black;
146+
}
147+
table, pre {
148+
page-break-inside: avoid;
149+
}
150+
}

imagepy/ui/mkdownwindow.py

Lines changed: 33 additions & 169 deletions
Original file line numberDiff line numberDiff line change
@@ -1,184 +1,42 @@
1-
import wx, wx.html2 as webview
1+
import wx, os, time, wx.html2 as webview
22
from markdown import markdown
33
from imagepy import IPy, root_dir
4-
import os
54

65
def md2html(mdstr):
7-
exts = ['markdown.extensions.extra', 'markdown.extensions.codehilite','markdown.extensions.tables','markdown.extensions.toc']
6+
exts = ['markdown.extensions.extra', 'markdown.extensions.codehilite',
7+
'markdown.extensions.tables','markdown.extensions.toc', 'mdx_math']
88

99
html = '''
10-
<html lang="zh-cn">
11-
<head>
12-
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
13-
</head>
10+
<html lang="zh-cn">
11+
<head>
12+
<meta content="text/html; charset=utf-8" http-equiv="content-type" />
13+
</head>
1414
15-
<style>
16-
h1,
17-
h2,
18-
h3,
19-
h4,
20-
h5,
21-
h6,
22-
p,
23-
blockquote {
24-
margin: 0;
25-
padding: 0;
26-
}
27-
body {
28-
font-family: "Helvetica Neue", Helvetica, "Hiragino Sans GB", Arial, sans-serif;
29-
font-size: 13px;
30-
line-height: 18px;
31-
color: #737373;
32-
background-color: white;
33-
margin: 10px 13px 10px 13px;
34-
}
35-
table {
36-
margin: 10px 0 15px 0;
37-
border-collapse: collapse;
38-
}
39-
td,th {
40-
border: 1px solid #ddd;
41-
padding: 3px 10px;
42-
}
43-
th {
44-
padding: 5px 10px;
45-
}
15+
<script type="text/x-mathjax-config">
16+
MathJax.Hub.Config({
17+
config: ["MMLorHTML.js"],
18+
jax: ["input/TeX", "output/HTML-CSS", "output/NativeMML"],
19+
extensions: ["MathMenu.js", "MathZoom.js"]
20+
});
21+
</script>
4622
47-
a {
48-
color: #0069d6;
49-
}
50-
a:hover {
51-
color: #0050a3;
52-
text-decoration: none;
53-
}
54-
a img {
55-
border: none;
56-
}
57-
p {
58-
margin-bottom: 9px;
59-
}
60-
p img {
61-
width:100%%;
62-
}
63-
h1,
64-
h2,
65-
h3,
66-
h4,
67-
h5,
68-
h6 {
69-
color: #404040;
70-
line-height: 36px;
71-
}
72-
h1 {
73-
margin-bottom: 18px;
74-
font-size: 30px;
75-
}
76-
h2 {
77-
font-size: 24px;
78-
}
79-
h3 {
80-
font-size: 18px;
81-
}
82-
h4 {
83-
font-size: 16px;
84-
}
85-
h5 {
86-
font-size: 14px;
87-
}
88-
h6 {
89-
font-size: 13px;
90-
}
91-
hr {
92-
margin: 0 0 19px;
93-
border: 0;
94-
border-bottom: 1px solid #ccc;
95-
}
96-
blockquote {
97-
padding: 13px 13px 21px 15px;
98-
margin-bottom: 18px;
99-
font-family:georgia,serif;
100-
font-style: italic;
101-
}
102-
blockquote:before {
103-
content:"\201C";
104-
font-size:40px;
105-
margin-left:-10px;
106-
font-family:georgia,serif;
107-
color:#eee;
108-
}
109-
blockquote p {
110-
font-size: 14px;
111-
font-weight: 300;
112-
line-height: 18px;
113-
margin-bottom: 0;
114-
font-style: italic;
115-
}
116-
code, pre {
117-
font-family: Monaco, Andale Mono, Courier New, monospace;
118-
}
119-
code {
120-
background-color: #fee9cc;
121-
color: rgba(0, 0, 0, 0.75);
122-
padding: 1px 3px;
123-
font-size: 12px;
124-
-webkit-border-radius: 3px;
125-
-moz-border-radius: 3px;
126-
border-radius: 3px;
127-
}
128-
pre {
129-
display: block;
130-
padding: 14px;
131-
margin: 0 0 18px;
132-
line-height: 16px;
133-
font-size: 11px;
134-
border: 1px solid #d9d9d9;
135-
white-space: pre-wrap;
136-
word-wrap: break-word;
137-
}
138-
pre code {
139-
background-color: #fff;
140-
color:#737373;
141-
font-size: 11px;
142-
padding: 0;
143-
}
144-
sup {
145-
font-size: 0.83em;
146-
vertical-align: super;
147-
line-height: 0;
148-
}
149-
* {
150-
-webkit-print-color-adjust: exact;
151-
}
152-
@media screen and (min-width: 914px) {
153-
body {
154-
width: 854px;
155-
margin:10px auto;
156-
}
157-
}
158-
@media print {
159-
body,code,pre code,h1,h2,h3,h4,h5,h6 {
160-
color: black;
161-
}
162-
table, pre {
163-
page-break-inside: avoid;
164-
}
165-
}
166-
</style>
23+
<script type="text/javascript"
24+
src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.4/MathJax.js">
25+
</script>
16726
168-
<body>
27+
<style>
28+
@import url("%s");
29+
</style>
16930
170-
%s
171-
</body>
172-
</html>
31+
<body>
32+
%s
33+
</body>
34+
</html>
17335
'''
17436

17537
ret = markdown(mdstr,extensions=exts)
176-
'''
177-
f = open('yn.html', 'w', encoding='utf-8')
178-
f.write(html % ret);
179-
f.close()
180-
'''
181-
return html % ret
38+
39+
return html % (IPy.root_dir+'/data/markdown.css', ret)
18240

18341
class HtmlPanel(wx.Panel):
18442
def __init__(self, parent, cont='', url=''):
@@ -203,11 +61,17 @@ def OnWebViewTitleChanged(self, evt):
20361
if evt.GetString() == 'about:blank': return
20462
if evt.GetString() == 'http:///': return
20563
self.frame.SetTitle("%s -- %s" % (self.titleBase, evt.GetString()))
64+
if os.path.exists(IPy.root_dir+'/data/index.htm'):
65+
os.remove(IPy.root_dir+'/data/index.htm')
20666

20767
class MkDownWindow(wx.Frame):
20868
def __init__(self, parent, title, cont, url):
20969
wx.Frame.__init__ (self, parent, id = wx.ID_ANY, title = title, size = wx.Size(500,500))
21070
logopath = os.path.join(root_dir, 'data/logo.ico')
21171
self.SetIcon(wx.Icon(logopath, wx.BITMAP_TYPE_ICO))
21272
cont = '\n'.join([i.strip() for i in cont.split('\n')])
213-
HtmlPanel(self, md2html(cont), url)
73+
74+
with open(IPy.root_dir+'/data/index.htm', 'w', encoding='utf-8') as f:
75+
f.write(md2html(cont))
76+
HtmlPanel(self, url = IPy.root_dir+'/data/index.htm')
77+

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ wxpython
1313
xlrd
1414
xlwt
1515
markdown
16+
python-markdown-math
1617
moderngl

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ def get_data_files():
4343
'xlwt',
4444
'openpyxl',
4545
'markdown',
46+
'python-markdown-math',
4647
'numba'
4748
],
4849
)

0 commit comments

Comments
 (0)