Skip to content

Commit

Permalink
Fix problem that env(doc-title) etc. doesn't work when used as a part…
Browse files Browse the repository at this point in the history
… of the `content` property value list.

`env(pub-title)` and `env(doc-title)` implemented in #512 had problem that it doesn't work when used as a part of the `content` property value list, e.g.:

```
content: env(doc-title) " (Page: " counter(page) ")" ;
```

Now, this works.
  • Loading branch information
MurakamiShinyu committed Apr 4, 2019
1 parent a657251 commit b205b30
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/adapt/cssvalid.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,12 @@ adapt.cssvalid.PrimitiveValidator.prototype.visitFunc = func => null;
/**
* @override
*/
adapt.cssvalid.PrimitiveValidator.prototype.visitExpr = expr => expr; // null;
adapt.cssvalid.PrimitiveValidator.prototype.visitExpr = function(expr) {
if (this.allowed & 0x7FE) { // ALLOW_STR|ALLOW_IDENT|...|ALLOW_ZERO_PERCENT
return expr;
}
return null;
};

/**
* @param {adapt.cssvalid.PrimitiveValidator} other
Expand Down
7 changes: 6 additions & 1 deletion src/adapt/vtree.js
Original file line number Diff line number Diff line change
Expand Up @@ -1638,8 +1638,13 @@ adapt.vtree.ContentPropertyHandler.prototype.visitSpaceList = function(list) {
/** @override */
adapt.vtree.ContentPropertyHandler.prototype.visitExpr = function(expr) {
const ex = expr.toExpr();
const val = ex.evaluate(this.context);
let val = ex.evaluate(this.context);
if (typeof val === "string") {
if (ex instanceof adapt.expr.Named) {
// For env(pub-title) and env(doc-title)
// Need to unquote the result. To be consistent with cssparse.evaluateExprToCSS()
val = adapt.cssparse.parseValue(ex.scope, new adapt.csstok.Tokenizer(val, null), "").stringValue();
}
goog.asserts.assert(this.elem.ownerDocument);
const node = this.exprContentListener(ex, val, this.elem.ownerDocument);
this.visitStrInner(val, node);
Expand Down

0 comments on commit b205b30

Please sign in to comment.