Skip to content

Commit

Permalink
[feature] add support for optional XML and HTML pretags
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreasMadsen committed Mar 22, 2013
1 parent eea3725 commit f3a289b
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions lib/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,28 @@ var NO_ENDING_TAG = ['br', 'col', 'link', 'hr', 'command',
// that attr.end is relative to attr.start, reduce calculations
function parse(content) {

// skip doctype
var doctype = content.indexOf('<!'),
begin = content.indexOf('<', doctype + 1),
end = content.lastIndexOf('>');
// Search for XML declaration and DOCTYPE declaration
// Both are optional
var begin = content.indexOf('<');

// Is XML declaration
if (content[begin + 1] === '?') {
begin = content.indexOf('<', begin + 1);
}

// Is DOCTYPE declartion
if (content[begin + 1] === '!') {
begin = content.indexOf('<', begin + 1);
}

// Find end of document
var end = content.lastIndexOf('>');

var root = {
isRoot: true,
pos: {
beforebegin: 0,
afterbegin: begin - 0,
afterbegin: begin,
beforeend: end,
afterend: (content.length - 1) - end
},
Expand Down

0 comments on commit f3a289b

Please sign in to comment.