Skip to content

Commit 5aa1367

Browse files
committed
Add script for generating web-embeddable help
Mallard's generated HTML help looks great on its own, but it's not really directly embeddable into another website without some modifications. Rather than write a new XSLT transformation (...) this commit adds a simple script that pulls out the requisite bits of HTML, and perform some CSS munging to get the rules to fit into Meld's existing web site without too much weirdness. In order to run, this script requires Python's BeautifulSoup 4 module, and a command-line executable copy of Sass. There's a reason I used Sass for this at the time, but now I can't for the life of me remember why.
1 parent 10ea981 commit 5aa1367

1 file changed

Lines changed: 122 additions & 0 deletions

File tree

help/C/buildwebhelp.py

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#! /usr/bin/python
2+
3+
import glob
4+
import os
5+
import subprocess
6+
import sys
7+
8+
from bs4 import BeautifulSoup as bs
9+
10+
11+
JEKYLL_HEADER = """---
12+
layout: help
13+
title: Meld - Help
14+
---
15+
"""
16+
17+
SCSS_HEADER = """
18+
#help-content {
19+
border-left: solid 1px #e0e0df;
20+
border-right: solid 1px #e0e0df;
21+
background-color: #ffffff;
22+
}
23+
24+
#help-content div.body {
25+
border: none !important; }
26+
27+
#help-content div.headbar {
28+
margin: 10px !important;
29+
}
30+
31+
#help-content div.footbar {
32+
margin: 10px !important;
33+
}
34+
35+
#help-content {
36+
37+
.title {
38+
line-height: 1em;
39+
}
40+
41+
h1 {
42+
font-family: sans-serif;
43+
font-weight: bold;
44+
text-shadow: none;
45+
color: black;
46+
}
47+
48+
h2 {
49+
font-family: sans-serif;
50+
text-shadow: none;
51+
color: black;
52+
}
53+
"""
54+
55+
SCSS_FOOTER = """
56+
}
57+
"""
58+
59+
60+
def munge_html(filename):
61+
if not os.path.exists(filename):
62+
print >> sys.stderr, "File not found: " + filename
63+
sys.exit(1)
64+
65+
with open(filename) as f:
66+
contents = f.read()
67+
68+
soup = bs(contents)
69+
body = "".join([str(tag) for tag in soup.body])
70+
body = JEKYLL_HEADER + body
71+
72+
print "Rewriting " + filename
73+
with open(filename, "w") as f:
74+
f.write(body)
75+
76+
77+
def munge_css(filename):
78+
79+
if not os.path.exists(filename):
80+
print >> sys.stderr, "File not found: " + filename
81+
sys.exit(1)
82+
83+
with open(filename) as f:
84+
contents = f.read()
85+
86+
contents = SCSS_HEADER + contents + SCSS_FOOTER
87+
new_css = sassify(contents)
88+
89+
print "Rewriting " + filename
90+
with open(filename, 'w') as f:
91+
f.write(new_css)
92+
93+
94+
def sassify(scss_string):
95+
scss = subprocess.Popen(['scss', '-s'],
96+
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
97+
stdout, stderr = scss.communicate(scss_string)
98+
return stdout
99+
100+
101+
if __name__ == "__main__":
102+
103+
if os.path.exists('html'):
104+
print >> sys.stderr, "Refusing to overwrite existing html/ folder"
105+
sys.exit(1)
106+
107+
print >> sys.stderr, "Generating CSS with gnome-doc-tool..."
108+
subprocess.check_call(['gnome-doc-tool', 'css'])
109+
110+
print >> sys.stderr, "Generating HTML with gnome-doc-tool..."
111+
subprocess.check_call(['gnome-doc-tool', 'html', '-c', 'index.css',
112+
'--copy-graphics', '*.page'])
113+
114+
os.mkdir('html')
115+
for filename in glob.glob('*.html'):
116+
munge_html(filename)
117+
os.rename(filename, os.path.join('html', filename))
118+
119+
munge_css('index.css')
120+
os.rename('index.css', os.path.join('html', 'index.css'))
121+
122+
print >> sys.stderr, "Embeddable documentation written to html/"

0 commit comments

Comments
 (0)