Skip to content

Commit 69fef40

Browse files
matticoMichael-F-Bryan
authored andcommitted
Improve print output (#680)
* Update print styles for new sidebar behavior * Hide copy icons in print output * Wait for mathjax rendering to complete before printing * Remove old wrapping css Browsers this old are already hilariously broken, so we don't need these fallbacks. * Change mathjax script type Chrome won't execute this if it's not marked as js * Ensure page has rendered before printing In certain situations Chrome willl fire window.onLoad before it's done rendering. Add a 100ms delay to work around this.
1 parent a323620 commit 69fef40

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

src/theme/book.css

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,12 +1322,14 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
13221322
.mobile-nav-chapters {
13231323
display: none;
13241324
}
1325-
#page-wrapper {
1326-
left: 0;
1327-
overflow-y: initial;
1328-
}
13291325
#page-wrapper.page-wrapper {
1330-
padding-left: 0px;
1326+
-webkit-transform: none;
1327+
-moz-transform: none;
1328+
-o-transform: none;
1329+
-ms-transform: none;
1330+
transform: none;
1331+
margin-left: 0px;
1332+
overflow-y: initial;
13311333
}
13321334
#content {
13331335
max-width: none;
@@ -1361,16 +1363,14 @@ html:not(.sidebar-visible) #menu-bar:not(:hover).folded > #menu-bar-sticky-conta
13611363
h6 {
13621364
page-break-inside: avoid;
13631365
page-break-after: avoid;
1364-
/*break-after: avoid*/
13651366
}
13661367
pre,
13671368
code {
13681369
page-break-inside: avoid;
1369-
white-space: pre-wrap /* CSS 3 */;
1370-
white-space: -moz-pre-wrap /* Mozilla, since 1999 */;
1371-
white-space: -pre-wrap /* Opera 4-6 */;
1372-
white-space: -o-pre-wrap /* Opera 7 */;
1373-
word-wrap: break-word /* Internet Explorer 5.5+ */;
1370+
white-space: pre-wrap;
1371+
}
1372+
.fa {
1373+
display: none !important;
13741374
}
13751375
}
13761376
.tooltiptext {

src/theme/index.hbs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,6 @@
212212
</script>
213213
{{/if}}
214214

215-
{{#if is_print}}
216-
<script type="text/javascript">
217-
document.addEventListener('DOMContentLoaded', function() {
218-
window.print();
219-
})
220-
</script>
221-
{{/if}}
222-
223215
{{#if playpen_js}}
224216
<script src="ace.js" type="text/javascript" charset="utf-8"></script>
225217
<script src="editor.js" type="text/javascript" charset="utf-8"></script>
@@ -246,5 +238,23 @@
246238
<script type="text/javascript" src="{{this}}"></script>
247239
{{/each}}
248240

241+
{{#if is_print}}
242+
{{#if mathjax_support}}
243+
<script type="text/javascript">
244+
window.addEventListener('load', function() {
245+
MathJax.Hub.Register.StartupHook('End', function() {
246+
window.setTimeout(window.print, 100);
247+
});
248+
});
249+
</script>
250+
{{else}}
251+
<script type="text/javascript">
252+
window.addEventListener('load', function() {
253+
window.setTimeout(window.print, 100);
254+
});
255+
</script>
256+
{{/if}}
257+
{{/if}}
258+
249259
</body>
250260
</html>

src/theme/stylus/print.styl

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,10 @@
77
display: none
88
}
99

10-
#page-wrapper {
11-
left: 0;
12-
overflow-y: initial;
13-
}
14-
1510
#page-wrapper.page-wrapper {
16-
padding-left: 0px;
11+
transform: none;
12+
margin-left: 0px;
13+
overflow-y: initial;
1714
}
1815

1916
#content {
@@ -46,15 +43,14 @@
4643
h1, h2, h3, h4, h5, h6 {
4744
page-break-inside: avoid
4845
page-break-after: avoid
49-
/*break-after: avoid*/
5046
}
5147

5248
pre, code {
5349
page-break-inside: avoid
54-
white-space: pre-wrap /* CSS 3 */
55-
white-space: -moz-pre-wrap /* Mozilla, since 1999 */
56-
white-space: -pre-wrap /* Opera 4-6 */
57-
white-space: -o-pre-wrap /* Opera 7 */
58-
word-wrap: break-word /* Internet Explorer 5.5+ */
50+
white-space: pre-wrap
51+
}
52+
53+
.fa {
54+
display: none !important
5955
}
6056
}

0 commit comments

Comments
 (0)