Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ var path = require('path');
var constantinople = require('constantinople');
var parseJSExpression = require('character-parser').parseMax;
var extname = path.extname;
var isPathAttribute = /^src|href$/i;

/**
* Initialize `Parser` with the given input `str` and `filename`.
Expand Down Expand Up @@ -472,6 +473,29 @@ Parser.prototype = {
return path;
},

/**
* Resolves src/href attribute paths
*
* @param {Object} attr
* @api private
*/

resolveAttributePath: function (attr) {
var val = attr.val;

if (attr.escaped) {
// Remove quotes (dirty)
val = val.substr(1, -1);
}

attr.val = this.resolvePath(val, 'src/href attributes');

if (attr.escaped) {
// Add quotes again (dirty)
attr.val = '"' + attr.val + '"';
}
},

/**
* 'extends' name
*/
Expand Down Expand Up @@ -756,6 +780,9 @@ Parser.prototype = {
if (tok.selfClosing) tag.selfClosing = true;

for (var i = 0; i < attrs.length; i++) {
if (isPathAttribute.test(attrs[i].name)) {
this.resolveAttributePath(attrs[i]);
}
tag.setAttribute(attrs[i].name, attrs[i].val, attrs[i].escaped);
}
continue;
Expand Down