Skip to content

Commit 7effa0a

Browse files
author
p12
committed
Preprocess: rewrite the preprocess script in Python
1 parent 6d35056 commit 7effa0a

File tree

4 files changed

+62
-37
lines changed

4 files changed

+62
-37
lines changed

Makefile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,9 @@ qch-help-project.xml: cppreference-doc-en.devhelp2
120120
#create the project (copies the file list)
121121
xsltproc devhelp2qch.xsl cppreference-doc-en.devhelp2 > "qch-help-project.xml"
122122

123-
#copy the source documentation tree, since changes will be made inplace
123+
#create preprocessed archive
124124
output:
125-
cp -r "reference" "output"
126-
127-
#remove useless UI elements
128-
find "output" -name "*.html" -exec ./fix_html.sh '{}' \;
129-
130-
#append css modifications
131-
cat fix_html-css.css >> "output/en.cppreference.com/mwiki/load7fe1.css"
125+
./preprocess.py
132126

133127
#redownloads the source documentation directly from en.cppreference.com
134128
source:

preprocess-httrack_meta.sed

Lines changed: 0 additions & 1 deletion
This file was deleted.

preprocess.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env python
2+
3+
# Copyright (C) 2011, 2012 p12 <tir5c3@yahoo.co.uk>
4+
#
5+
# This file is part of cppreference-doc
6+
#
7+
# This program is free software: you can redistribute it and/or modify
8+
# it under the terms of the GNU General Public License as published by
9+
# the Free Software Foundation, either version 3 of the License, or
10+
# (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
# GNU General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU General Public License
18+
# along with this program. If not, see http://www.gnu.org/licenses/.
19+
20+
import fnmatch
21+
import re
22+
import os
23+
24+
# copy the source tree
25+
os.system('rm -rf output')
26+
os.system('mkdir output')
27+
os.system('cp -rt output reference/*')
28+
29+
# find all html and css files
30+
html_files = []
31+
css_files = []
32+
for root, dirnames, filenames in os.walk('output'):
33+
for filename in fnmatch.filter(filenames, '*.html'):
34+
html_files.append(os.path.join(root, filename))
35+
for filename in fnmatch.filter(filenames, '*.css'):
36+
css_files.append(os.path.join(root, filename))
37+
38+
#
39+
r1 = re.compile('<!-- Added by HTTrack -->.*?<!-- \/Added by HTTrack -->')
40+
r2 = re.compile('<!-- Mirrored from .*?-->')
41+
42+
# clean the html files
43+
for fn in html_files:
44+
f = open(fn, "r")
45+
text = f.read()
46+
f.close()
47+
48+
text = r1.sub('', text);
49+
text = r2.sub('', text);
50+
51+
f = open(fn, "w")
52+
f.write(text)
53+
f.close()
54+
55+
tmpfile = fn + '.tmp';
56+
os.system('xsltproc --novalid --html preprocess.xsl "' + fn + '" > "' + tmpfile + '"')
57+
os.system('mv "' + tmpfile + '" "' + fn + '"')
58+
59+
60+
os.system('cat preprocess-css.css >> "output/en.cppreference.com/mwiki/load7fe1.css"')

preprocess.sh

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)