Skip to content

Commit 3c00f86

Browse files
committed
add @page compilation support
1 parent cf146b4 commit 3c00f86

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed

examples/page.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page {
2+
size: auto;
3+
margin: 10%
4+
}
5+
6+
@page foo, bar {
7+
bar: baz
8+
}

examples/page.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
/**
3+
* Module dependencies.
4+
*/
5+
6+
var parse = require('css-parse')
7+
, stringify = require('..')
8+
, fs = require('fs')
9+
, read = fs.readFileSync
10+
, css = read('examples/page.css', 'utf8');
11+
12+
console.log(stringify(parse(css), { compress: false }));

index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Compiler.prototype.compile = function(node){
3636
*/
3737

3838
Compiler.prototype.visit = function(node){
39+
if ('page' == node.type) return this.page(node);
3940
if (node.document) return this.document(node);
4041
if (node.comment) return this.comment(node);
4142
if (node.charset) return this.charset(node);
@@ -165,6 +166,19 @@ Compiler.prototype.keyframe = function(node){
165166
+ '\n' + this.indent() + '}\n';
166167
};
167168

169+
/**
170+
* Visit page node.
171+
*/
172+
173+
Compiler.prototype.page = function(node){
174+
return '@page ' + node.selectors.join(', ')
175+
+ ' {\n'
176+
+ this.indent(1)
177+
+ node.declarations.map(this.declaration, this).join(';\n')
178+
+ this.indent(-1)
179+
+ '\n}';
180+
};
181+
168182
/**
169183
* Visit rule node.
170184
*/

test/cases/page.css

Whitespace-only changes.

0 commit comments

Comments
 (0)