mirror of
https://github.com/kennethreitz/dive-into-python3.git
synced 2026-06-05 15:00:18 +00:00
added print stylesheet
This commit is contained in:
@@ -7,6 +7,8 @@
|
||||
h1:before{content:""}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8><input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
body{counter-reset:h1 11}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#advanced-classes>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
body{counter-reset:h1 7}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#advanced-iterators>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -11,6 +11,8 @@ ins{background:#9f9}
|
||||
del{background:#f87}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#case-study-porting-chardet-to-python-3>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
body{counter-reset:h1 12}
|
||||
</style>
|
||||
<link rel=stylesheet type=text/css media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#strings>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
body{counter-reset:h1 5}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#generators>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -11,6 +11,8 @@ h1:before{content:""}
|
||||
#b:before{content:"B. \00a0 \00a0"}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8><input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ body{counter-reset:h1 -1}
|
||||
h1:before{counter-increment:h1;content:""}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
body{counter-reset:h1 6}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#iterators>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
body{counter-reset:h1 2}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=root value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#native-datatypes>Dive Into Python 3</a> <span>‣</span>
|
||||
@@ -18,7 +20,7 @@ body{counter-reset:h1 2}
|
||||
</blockquote>
|
||||
<p id=toc>
|
||||
<h2 id=divingin>Diving In</h2>
|
||||
<p class=f>Cast aside <a href=your-first-python-program.html>your first Python program</a> for just a minute, and let’s talk about datatypes. In Python, <a href=your-first-python-program.html#datatypes>every variable has a datatype</a>, but you don’t need to declare it explicitly. Based on each variable’s original assignment, Python figures out what type it is and keeps tracks of that internally.
|
||||
<p class=f>Cast aside <a href=your-first-python-program.html>your first Python program</a> for just a minute, and let’s talk about datatypes. In Python, <a href=your-first-python-program.html#declaringfunctions>every variable has a datatype</a>, but you don’t need to declare it explicitly. Based on each variable’s original assignment, Python figures out what type it is and keeps tracks of that internally.
|
||||
<p>Python has many native datatypes. Here are the important ones:
|
||||
<ol>
|
||||
<li><b>Booleans</b> are either <code>True</code> or <code>False</code>.
|
||||
|
||||
@@ -18,6 +18,8 @@ th,td,td pre{margin:0}
|
||||
td pre{padding:0;border:0}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#porting-code-to-python-3-with-2to3>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
/*
|
||||
|
||||
"Dive Into Python 3" print stylesheet
|
||||
|
||||
Copyright (c) 2009, Mark Pilgrim, All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
||||
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/* print-specific (and some Prince-specific) rules */
|
||||
|
||||
@page {
|
||||
size: US-Letter;
|
||||
margin: 30pt;
|
||||
padding: 0;
|
||||
@bottom-center {
|
||||
font: 12pt/1.75 Helvetica, 'Gill Sans', 'Gill Sans MT', Corbel, 'Nimbus Sans L', sans-serif;
|
||||
content: counter(page);
|
||||
}
|
||||
}
|
||||
pre {
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
h1 {
|
||||
page-break-before: always;
|
||||
prince-bookmark-level: 1;
|
||||
}
|
||||
h2 {
|
||||
prince-bookmark-level: 2;
|
||||
}
|
||||
h3 {
|
||||
prince-bookmark-level: 3;
|
||||
}
|
||||
|
||||
/* typography */
|
||||
|
||||
body, .w a {
|
||||
font: 12pt/1.75 Helvetica, 'Gill Sans', 'Gill Sans MT', Corbel, 'Nimbus Sans L', sans-serif;
|
||||
word-spacing: 0;
|
||||
}
|
||||
pre, kbd, samp, code, var, .b {
|
||||
font-size: 10pt;
|
||||
line-height: 2.1;
|
||||
}
|
||||
span {
|
||||
font-size: 12pt;
|
||||
}
|
||||
.baa {
|
||||
font-size: 13pt;
|
||||
}
|
||||
.q span {
|
||||
font-size: 13pt;
|
||||
}
|
||||
.note span {
|
||||
color: #000;
|
||||
}
|
||||
.f:first-letter {
|
||||
color: #888;
|
||||
font: normal 48pt/0.68 serif;
|
||||
}
|
||||
p {
|
||||
margin: 1.75em 0;
|
||||
font-size: 12pt;
|
||||
}
|
||||
ul, ol {
|
||||
margin: 1.75em 20pt;
|
||||
font-size: 12pt;
|
||||
}
|
||||
|
||||
/* basics */
|
||||
|
||||
html {
|
||||
background: #fff;
|
||||
color: #000;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
/* links */
|
||||
|
||||
a {
|
||||
text-decoration: none;
|
||||
border-bottom: 1px dotted;
|
||||
}
|
||||
a:link, .w a {
|
||||
color: #000;
|
||||
}
|
||||
a:visited {
|
||||
color: #000;
|
||||
}
|
||||
|
||||
/* code blocks */
|
||||
|
||||
pre {
|
||||
border: 0;
|
||||
}
|
||||
.c {
|
||||
font-size: 10pt;
|
||||
line-height: 2.1;
|
||||
}
|
||||
}
|
||||
mark {
|
||||
background: gainsboro;
|
||||
}
|
||||
|
||||
/* headers and pullquotes */
|
||||
|
||||
h1, h1 code {
|
||||
font-size: 24pt;
|
||||
}
|
||||
h2, h2 code {
|
||||
font-size: 18pt;
|
||||
}
|
||||
h3, h3 code {
|
||||
font-size: 13pt;
|
||||
}
|
||||
aside {
|
||||
font-size: 24pt;
|
||||
background: #667;
|
||||
color: white;
|
||||
}
|
||||
|
||||
/* overrides */
|
||||
|
||||
.w, .d {
|
||||
display: none !important;
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "started build"
|
||||
|
||||
# make build directory and copy original files there for preflighting
|
||||
rm -rf build
|
||||
mkdir build
|
||||
@@ -7,6 +9,8 @@ cp robots.txt *.js *.css build/
|
||||
rm -f examples/*.pyc
|
||||
cp -R examples build/
|
||||
|
||||
echo "minimizing HTML"
|
||||
|
||||
# minimize HTML (XXX this script is quite fragile and relies on knowledge of how I write HTML)
|
||||
for f in *.html; do
|
||||
python htmlminimizer.py "$f" build/"$f"
|
||||
@@ -24,19 +28,26 @@ sed -i -e "s|//google\.|google.|g" build/dip3.js
|
||||
sed -i -e "s|//}.; /\* google\..*|});|g" build/dip3.js
|
||||
|
||||
# minimize JS and CSS
|
||||
echo "minimizing JS"
|
||||
revision=`hg log|grep changeset|cut -d":" -f3|head -1`
|
||||
java -jar yuicompressor-2.4.2.jar build/dip3.js > build/$revision.js
|
||||
echo "minimizing CSS"
|
||||
java -jar yuicompressor-2.4.2.jar build/dip3.css > build/$revision.css
|
||||
java -jar yuicompressor-2.4.2.jar build/mobile.css > build/m-$revision.css
|
||||
java -jar yuicompressor-2.4.2.jar build/print.css > build/p-$revision.css
|
||||
sed -i -e "s|;}|}|g" build/$revision.css
|
||||
sed -i -e "s|;}|}|g" build/m-$revision.css
|
||||
sed -i -e "s|;}|}|g" build/p-$revision.css
|
||||
|
||||
# put CSS inline
|
||||
echo "inlining CSS"
|
||||
css=`cat build/$revision.css`
|
||||
mobilecss=`cat build/m-$revision.css`
|
||||
#sed -i -e "s|<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>|<style>@media screen and (max-device-width:480px)\{${mobilecss}\}</style>|g" -e "s|<link rel=stylesheet href=dip3.css>|<style>${css}</style>|g" -e "s|</style><style>||g" build/*.html
|
||||
sed -i -e "s|<link rel=stylesheet href=dip3.css>|<style>${css}</style>|g" -e "s|</style><style>||g" build/*.html
|
||||
|
||||
# secondary stylesheets will be served from a separate domain
|
||||
echo "fixing hrefs"
|
||||
sed -i -e "s|href=mobile.css|href=http://wearehugh.com/dip3/m-${revision}.css|g" build/*.html
|
||||
sed -i -e "s|href=print.css|href=http://wearehugh.com/dip3/p-${revision}.css|g" build/*.html
|
||||
|
||||
# JS will be served from a separate domain
|
||||
sed -i -e "s|dip3\.js|http://wearehugh.com/dip3/${revision}.js|g" build/*.html
|
||||
@@ -46,6 +57,7 @@ sed -i -e "s|html5\.js|http://wearehugh.com/dip3/html5.js|g" build/*.html
|
||||
#sed -i -e "s|bsb.png|http://wearehugh.com/dip3/bsb.png|g" build/*.html
|
||||
|
||||
# minimize URLs
|
||||
echo "minimizing URLs"
|
||||
sed -i -e "s|=http:|=|g" build/*.html
|
||||
sed -i -e "s|href=index.html|href=/|g" build/*.html
|
||||
|
||||
@@ -53,5 +65,6 @@ sed -i -e "s|href=index.html|href=/|g" build/*.html
|
||||
chmod 644 build/*.html build/*.css build/*.js build/examples/*.py build/examples/*.txt build/*.txt
|
||||
|
||||
# ship it!
|
||||
rsync -essh -avzP build/$revision.js build/html5.js build/m-$revision.css diveintomark.org:~/web/wearehugh.com/dip3/
|
||||
echo "publishing"
|
||||
rsync -essh -avzP build/$revision.js build/html5.js build/m-$revision.css build/p-$revision.css diveintomark.org:~/web/wearehugh.com/dip3/
|
||||
rsync -essh -avzP build/*.html build/examples build/*.txt diveintomark.org:~/web/diveintopython3.org/
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
body{counter-reset:h1 10}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=root value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#refactoring>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
body{counter-reset:h1 4}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=root value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#regular-expressions>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -19,6 +19,8 @@ td pre{padding:0;border:0}
|
||||
td a:link, td a:visited{border:0}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#special-method-names>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
body{counter-reset:h1 3}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#strings>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -11,6 +11,8 @@ ul{list-style:none;margin:0;padding:0}
|
||||
ul li ol{margin:0;padding:0 0 0 2.5em}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8><input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> Dive Into Python 3 <span>‣</span>
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
body{counter-reset:h1 8}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=root value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#unit-testing>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
+25
-6
@@ -3,42 +3,61 @@
|
||||
# TODO:
|
||||
# - fix internal xrefs (look for href=<in [chapters]>.html)
|
||||
# - fix duplicate IDs
|
||||
# - print stylesheet
|
||||
|
||||
import re
|
||||
|
||||
# get list of chapters
|
||||
chapters = []
|
||||
for line in open('index.html'):
|
||||
if not line.count('<li') or not line.count('<a href'):
|
||||
continue
|
||||
chapters.append(line.split('<a href=', 1)[1].split('>', 1)[0])
|
||||
|
||||
# construct regexes used to fix internal xrefs
|
||||
chapter_href = re.compile("<a href=({0})>".format("|".join(chapters)))
|
||||
chapter_fragment_href = re.compile("<a href=({0})#(.*?)>".format("|".join(chapters)))
|
||||
same_chapter_fragment_href = re.compile("<a href=#(.*?)")
|
||||
id_munge = re.compile(" id=(.*?)[ >]")
|
||||
|
||||
# munge and combine chapter-specific styles
|
||||
out = open('build/single.html', 'w', encoding="utf-8")
|
||||
out.write(open('util/single-header.html', encoding="utf-8").read())
|
||||
out.write("<style>\n")
|
||||
for filename in chapters:
|
||||
include = False
|
||||
id = "chapter-" + filename.split(".", 1)[0]
|
||||
id_prefix = filename.split(".", 1)[0]
|
||||
chapter_id = "chapter-" + id_prefix
|
||||
for line in open(filename, encoding="utf-8"):
|
||||
if line.count('</style>'):
|
||||
include = False
|
||||
if include and not line.count('counter-reset'):
|
||||
line = "#{0} {1}".format(id, line)
|
||||
line = line.replace(",", ", #{0} ".format(id))
|
||||
line = "#{0} {1}".format(chapter_id, line)
|
||||
line = line.replace(",", ", #{0} ".format(chapter_id))
|
||||
out.write(line)
|
||||
if line.count('<style>'):
|
||||
include = True
|
||||
out.write("</style>\n")
|
||||
out.write(open('util/single-header2.html', encoding="utf-8").read())
|
||||
|
||||
# munge and combine chapters
|
||||
for filename in chapters:
|
||||
include = False
|
||||
id = "chapter-" + filename.split(".", 1)[0]
|
||||
out.write("<div id={0}>\n".format(id))
|
||||
id_prefix = filename.split(".", 1)[0]
|
||||
chapter_id = "chapter-" + id_prefix
|
||||
out.write("<div id={0}>\n".format(chapter_id))
|
||||
for line in open(filename, encoding="utf-8"):
|
||||
if line.count('<h1>'):
|
||||
include = True
|
||||
if line.count('<p class=nav') or line.count('<p class=c>©'):
|
||||
include = False
|
||||
if line.count('<p id=toc'):
|
||||
line = line.replace(' id=toc', '')
|
||||
if include:
|
||||
# fix cross-references
|
||||
line = id_munge.sub(lambda x: " id={0}-{1}>".format(id_prefix, x.group(1)), line)
|
||||
line = same_chapter_fragment_href.sub(lambda x: "<a href=#{0}-{1}".format(id_prefix, x.group(1)), line)
|
||||
line = chapter_href.sub(lambda x: "<a href=#chapter-" + x.group(1).replace('.html', '') + ">", line)
|
||||
line = chapter_fragment_href.sub(lambda x: "<a href=#{0}-{1}>".format(x.group(1).replace('.html', ''), x.group(2)) , line)
|
||||
out.write(line)
|
||||
out.write("</div>\n")
|
||||
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
<head>
|
||||
<meta charset=utf-8>
|
||||
<title>Dive into Python 3</title>
|
||||
<meta name="author" content="Mark Pilgrim">
|
||||
<meta name="subject" content="Python 3 from novice to pro">
|
||||
<meta name="keywords" content="python, python3, py3k, free, book">
|
||||
<link rel=stylesheet href=dip3.css>
|
||||
<style>
|
||||
body{counter-reset:h1 -2}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
@@ -9,6 +9,8 @@ body{counter-reset:h1 -1}
|
||||
h3:before{content:""}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#whats-new>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -9,6 +9,8 @@ body{counter-reset:h1 13}
|
||||
mark{display:inline}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=root value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#xml>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
@@ -11,6 +11,8 @@ td,th{border:1px solid #bbb;padding:0 1.75em}
|
||||
th{text-align:left}
|
||||
</style>
|
||||
<link rel=stylesheet media='only screen and (max-device-width: 480px)' href=mobile.css>
|
||||
<link rel=stylesheet media=print href=print.css>
|
||||
<meta name=viewport content='initial-scale=1.0'>
|
||||
</head>
|
||||
<form action=http://www.google.com/cse><div><input type=hidden name=cx value=014021643941856155761:l5eihuescdw><input type=hidden name=ie value=UTF-8> <input name=q size=25> <input type=submit name=sa value=Search></div></form>
|
||||
<p>You are here: <a href=index.html>Home</a> <span>‣</span> <a href=table-of-contents.html#your-first-python-program>Dive Into Python 3</a> <span>‣</span>
|
||||
|
||||
Reference in New Issue
Block a user