@@ -1035,6 +1035,7 @@ ${await utils.readFile(path.join(__dirname, '../js/multipage.js'))}
1035
1035
}
1036
1036
1037
1037
let cssContents = await utils . readFile ( path . join ( __dirname , '../css/elements.css' ) ) ;
1038
+ let printCssContents = await utils . readFile ( path . join ( __dirname , '../css/print.css' ) ) ;
1038
1039
1039
1040
const FONT_FILE_CONTENTS = new Map (
1040
1041
zip (
@@ -1072,9 +1073,11 @@ ${await utils.readFile(path.join(__dirname, '../js/multipage.js'))}
1072
1073
1073
1074
const scriptLocationOnDisk = path . join ( this . assets . directory , 'ecmarkup.js' ) ;
1074
1075
const styleLocationOnDisk = path . join ( this . assets . directory , 'ecmarkup.css' ) ;
1076
+ const printStyleLocationOnDisk = path . join ( this . assets . directory , 'print.css' ) ;
1075
1077
1076
1078
this . generatedFiles . set ( scriptLocationOnDisk , jsContents ) ;
1077
1079
this . generatedFiles . set ( styleLocationOnDisk , cssContents ) ;
1080
+ this . generatedFiles . set ( printStyleLocationOnDisk , printCssContents ) ;
1078
1081
for ( const [ , fontFile ] of FONT_FILES ) {
1079
1082
this . generatedFiles . set (
1080
1083
path . join ( this . assets . directory , fontFile ) ,
@@ -1087,6 +1090,7 @@ ${await utils.readFile(path.join(__dirname, '../js/multipage.js'))}
1087
1090
script . setAttribute ( 'defer' , '' ) ;
1088
1091
this . doc . head . appendChild ( script ) ;
1089
1092
1093
+ this . addStyle ( this . doc . head , path . relative ( outDir , printStyleLocationOnDisk ) , true ) ;
1090
1094
this . addStyle ( this . doc . head , path . relative ( outDir , styleLocationOnDisk ) ) ;
1091
1095
} else {
1092
1096
// i.e. assets.type === 'inline'
@@ -1099,6 +1103,9 @@ ${await utils.readFile(path.join(__dirname, '../js/multipage.js'))}
1099
1103
const style = this . doc . createElement ( 'style' ) ;
1100
1104
style . textContent = cssContents ;
1101
1105
this . doc . head . appendChild ( style ) ;
1106
+ const printStyle = this . doc . createElement ( 'style' ) ;
1107
+ printStyle . textContent = `@media print {\n${ printCssContents } \n}` ;
1108
+ this . doc . head . appendChild ( printStyle ) ;
1102
1109
}
1103
1110
this . addStyle (
1104
1111
this . doc . head ,
@@ -1108,10 +1115,13 @@ ${await utils.readFile(path.join(__dirname, '../js/multipage.js'))}
1108
1115
) ;
1109
1116
}
1110
1117
1111
- private addStyle ( head : HTMLHeadElement , href : string ) {
1118
+ private addStyle ( head : HTMLHeadElement , href : string , print : boolean = false ) {
1112
1119
const style = this . doc . createElement ( 'link' ) ;
1113
1120
style . setAttribute ( 'rel' , 'stylesheet' ) ;
1114
1121
style . setAttribute ( 'href' , href ) ;
1122
+ if ( print ) {
1123
+ style . setAttribute ( 'media' , 'print' ) ;
1124
+ }
1115
1125
1116
1126
// insert early so that the document's own stylesheets can override
1117
1127
const firstLink = head . querySelector ( 'link[rel=stylesheet], style' ) ;
0 commit comments