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
|
#! /usr/bin/python3
import glob
import os
import subprocess
import sys
from bs4 import BeautifulSoup
JEKYLL_HEADER = """---
layout: help
title: Meld - Help
---
"""
SCSS_HEADER = """
#help-content {
border-left: solid 1px #e0e0df;
border-right: solid 1px #e0e0df;
background-color: #ffffff;
}
#help-content div.body {
border: none !important; }
#help-content div.headbar {
margin: 10px !important;
}
#help-content div.footbar {
margin: 10px !important;
}
#help-content {
.title {
line-height: 1em;
}
h1 {
font-family: sans-serif;
font-weight: bold;
text-shadow: none;
color: black;
}
h2 {
font-family: sans-serif;
text-shadow: none;
color: black;
}
"""
SCSS_FOOTER = """
}
"""
def munge_html(filename):
if not os.path.exists(filename):
print("File not found: " + filename, file=sys.stderr)
sys.exit(1)
with open(filename) as f:
contents = f.read()
soup = BeautifulSoup(contents, "lxml")
body = "".join([str(tag) for tag in soup.body])
body = JEKYLL_HEADER + body
print("Rewriting " + filename)
with open(filename, "w") as f:
f.write(body)
def munge_css(filename):
if not os.path.exists(filename):
print("File not found: " + filename, file=sys.stderr)
sys.exit(1)
with open(filename) as f:
contents = f.read()
contents = SCSS_HEADER + contents + SCSS_FOOTER
new_css = sassify(contents)
print("Rewriting " + filename)
with open(filename, 'w') as f:
f.write(new_css)
def sassify(scss_string):
scss = subprocess.Popen(
['scss', '-s'],
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
universal_newlines=True,
)
stdout, stderr = scss.communicate(scss_string)
return stdout
if __name__ == "__main__":
if os.path.exists('html'):
print("Refusing to overwrite existing html/ folder", file=sys.stderr)
sys.exit(1)
print("Generating CSS with gnome-doc-tool...", file=sys.stderr)
subprocess.check_call(['gnome-doc-tool', 'css'])
print("Generating HTML with gnome-doc-tool...", file=sys.stderr)
subprocess.check_call(['gnome-doc-tool', 'html', '-c', 'index.css',
'--copy-graphics', '*.page'])
os.mkdir('html')
for filename in glob.glob('*.html'):
munge_html(filename)
os.rename(filename, os.path.join('html', filename))
munge_css('index.css')
os.rename('index.css', os.path.join('html', 'index.css'))
print("Embeddable documentation written to html/", file=sys.stderr)
|