-
-
Notifications
You must be signed in to change notification settings - Fork 48
/
printable.js
75 lines (66 loc) · 1.53 KB
/
printable.js
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
/** @module */
import postcssPlugin from '../helpers/postcss_plugin'
const marpitPrintContainerStyle = `
html, body {
background-color: #fff;
margin: 0;
page-break-inside: avoid;
break-inside: avoid-page;
}
`.trim()
/**
* Marpit PostCSS printable plugin.
*
* Make printable slide deck as PDF.
*
* @param {Object} opts
* @param {string} opts.width
* @param {string} opts.height
* @alias module:postcss/printable
*/
const plugin = postcssPlugin('marpit-postcss-printable', (opts) => (css) => {
css.walkAtRules('media', (rule) => {
if (rule.params === 'marpit-print') rule.remove()
})
css.first.before(
`
@page {
size: ${opts.width} ${opts.height};
margin: 0;
}
@media marpit-print {
section {
page-break-before: always;
break-before: page;
}
section, section * {
-webkit-print-color-adjust: exact !important;
animation-delay: 0s !important;
animation-duration: 0s !important;
color-adjust: exact !important;
transition: none !important;
}
:marpit-container > svg[data-marpit-svg] {
display: block;
height: 100vh;
width: 100vw;
}
}
`.trim()
)
})
/**
* The post-process PostCSS plugin of Marpit printable plugin.
*
* @alias module:postcss/printable.postprocess
*/
export const postprocess = postcssPlugin(
'marpit-postcss-printable-postprocess',
() => (css) =>
css.walkAtRules('media', (rule) => {
if (rule.params !== 'marpit-print') return
rule.params = 'print'
rule.first.before(marpitPrintContainerStyle)
})
)
export default plugin