Skip to content
This repository has been archived by the owner on Feb 24, 2018. It is now read-only.

Commit

Permalink
Walk the entire AST to look for the doctype
Browse files Browse the repository at this point in the history
  • Loading branch information
ForbesLindesay committed Aug 7, 2015
1 parent 23af218 commit c0662dc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ var parseJSExpression = require('character-parser').parseMax;
var constantinople = require('constantinople');
var stringify = require('js-stringify');
var addWith = require('with');
var walk = require('jade-walk');

var INTERNAL_VARIABLES = [
'jade',
Expand Down Expand Up @@ -58,7 +59,25 @@ function Compiler(node, options) {
this.mixins = {};
this.dynamicMixins = false;
this.eachCount = 0;
if (options.doctype) this.setDoctype(options.doctype);
if (options.doctype) {
this.setDoctype(options.doctype);
} else {
var doctypeList = [];
// doctypes[name.toLowerCase()] || '<!DOCTYPE ' + name + '>';
walk(node, function (node) {
if (node.type === 'Doctype' && node.val) {
var name = doctypes[node.val.toLowerCase()] || '<!DOCTYPE ' + node.val + '>';
if (doctypeList.indexOf(name) === -1) {
doctypeList.push(name);
}
}
});
if (doctypeList.length === 1) {
this.doctype = doctypeList[0];
this.terse = this.doctype.toLowerCase() == '<!doctype html>';
this.xml = 0 == this.doctype.indexOf('<?xml');
}
}
this.runtimeFunctionsUsed = [];
this.inlineRuntimeFunctions = options.inlineRuntimeFunctions;
if (this.debug && this.inlineRuntimeFunctions) {
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"doctypes": "^1.0.0",
"jade-attrs": "^1.0.2",
"jade-runtime": "^1.0.0",
"jade-walk": "0.0.2",
"js-stringify": "^1.0.1",
"void-elements": "^2.0.1",
"with": "^5.0.0"
Expand Down

0 comments on commit c0662dc

Please sign in to comment.