-
-
Notifications
You must be signed in to change notification settings - Fork 238
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
154 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
243 changes: 134 additions & 109 deletions
243
lib/tree_construction/doctype.js → lib/common/doctype.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,109 +1,134 @@ | ||
'use strict'; | ||
|
||
//Const | ||
var VALID_DOCTYPE_NAME = 'html', | ||
QUIRKS_MODE_SYSTEM_ID = 'http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd', | ||
QUIRKS_MODE_PUBLIC_ID_PREFIXES = [ | ||
"+//silmaril//dtd html pro v0r11 19970101//en", | ||
"-//advasoft ltd//dtd html 3.0 aswedit + extensions//en", | ||
"-//as//dtd html 3.0 aswedit + extensions//en", | ||
"-//ietf//dtd html 2.0 level 1//en", | ||
"-//ietf//dtd html 2.0 level 2//en", | ||
"-//ietf//dtd html 2.0 strict level 1//en", | ||
"-//ietf//dtd html 2.0 strict level 2//en", | ||
"-//ietf//dtd html 2.0 strict//en", | ||
"-//ietf//dtd html 2.0//en", | ||
"-//ietf//dtd html 2.1e//en", | ||
"-//ietf//dtd html 3.0//en", | ||
"-//ietf//dtd html 3.0//en//", | ||
"-//ietf//dtd html 3.2 final//en", | ||
"-//ietf//dtd html 3.2//en", | ||
"-//ietf//dtd html 3//en", | ||
"-//ietf//dtd html level 0//en", | ||
"-//ietf//dtd html level 0//en//2.0", | ||
"-//ietf//dtd html level 1//en", | ||
"-//ietf//dtd html level 1//en//2.0", | ||
"-//ietf//dtd html level 2//en", | ||
"-//ietf//dtd html level 2//en//2.0", | ||
"-//ietf//dtd html level 3//en", | ||
"-//ietf//dtd html level 3//en//3.0", | ||
"-//ietf//dtd html strict level 0//en", | ||
"-//ietf//dtd html strict level 0//en//2.0", | ||
"-//ietf//dtd html strict level 1//en", | ||
"-//ietf//dtd html strict level 1//en//2.0", | ||
"-//ietf//dtd html strict level 2//en", | ||
"-//ietf//dtd html strict level 2//en//2.0", | ||
"-//ietf//dtd html strict level 3//en", | ||
"-//ietf//dtd html strict level 3//en//3.0", | ||
"-//ietf//dtd html strict//en", | ||
"-//ietf//dtd html strict//en//2.0", | ||
"-//ietf//dtd html strict//en//3.0", | ||
"-//ietf//dtd html//en", | ||
"-//ietf//dtd html//en//2.0", | ||
"-//ietf//dtd html//en//3.0", | ||
"-//metrius//dtd metrius presentational//en", | ||
"-//microsoft//dtd internet explorer 2.0 html strict//en", | ||
"-//microsoft//dtd internet explorer 2.0 html//en", | ||
"-//microsoft//dtd internet explorer 2.0 tables//en", | ||
"-//microsoft//dtd internet explorer 3.0 html strict//en", | ||
"-//microsoft//dtd internet explorer 3.0 html//en", | ||
"-//microsoft//dtd internet explorer 3.0 tables//en", | ||
"-//netscape comm. corp.//dtd html//en", | ||
"-//netscape comm. corp.//dtd strict html//en", | ||
"-//o'reilly and associates//dtd html 2.0//en", | ||
"-//o'reilly and associates//dtd html extended 1.0//en", | ||
"-//spyglass//dtd html 2.0 extended//en", | ||
"-//sq//dtd html 2.0 hotmetal + extensions//en", | ||
"-//sun microsystems corp.//dtd hotjava html//en", | ||
"-//sun microsystems corp.//dtd hotjava strict html//en", | ||
"-//w3c//dtd html 3 1995-03-24//en", | ||
"-//w3c//dtd html 3.2 draft//en", | ||
"-//w3c//dtd html 3.2 final//en", | ||
"-//w3c//dtd html 3.2//en", | ||
"-//w3c//dtd html 3.2s draft//en", | ||
"-//w3c//dtd html 4.0 frameset//en", | ||
"-//w3c//dtd html 4.0 transitional//en", | ||
"-//w3c//dtd html experimental 19960712//en", | ||
"-//w3c//dtd html experimental 970421//en", | ||
"-//w3c//dtd w3 html//en", | ||
"-//w3o//dtd w3 html 3.0//en", | ||
"-//w3o//dtd w3 html 3.0//en//", | ||
"-//webtechs//dtd mozilla html 2.0//en", | ||
"-//webtechs//dtd mozilla html//en" | ||
], | ||
QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES = [ | ||
'-//w3c//dtd html 4.01 frameset//', | ||
'-//w3c//dtd html 4.01 transitional//' | ||
], | ||
QUIRKS_MODE_PUBLIC_IDS = [ | ||
'-//w3o//dtd w3 html strict 3.0//en//', | ||
'-/w3c/dtd html 4.0 transitional/en', | ||
'html' | ||
]; | ||
|
||
exports.isQuirks = function (name, publicId, systemId) { | ||
if (name !== VALID_DOCTYPE_NAME) | ||
return true; | ||
|
||
if (systemId && systemId.toLowerCase() === QUIRKS_MODE_SYSTEM_ID) | ||
return true; | ||
|
||
if (publicId !== null) { | ||
publicId = publicId.toLowerCase(); | ||
|
||
if (QUIRKS_MODE_PUBLIC_IDS.indexOf(publicId) > -1) | ||
return true; | ||
|
||
var prefixes = QUIRKS_MODE_PUBLIC_ID_PREFIXES; | ||
|
||
if (systemId === null) | ||
prefixes = prefixes.concat(QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES); | ||
|
||
for (var i = 0; i < prefixes.length; i++) { | ||
if (publicId.indexOf(prefixes[i]) === 0) | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
}; | ||
'use strict'; | ||
|
||
//Const | ||
var VALID_DOCTYPE_NAME = 'html', | ||
QUIRKS_MODE_SYSTEM_ID = 'http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd', | ||
QUIRKS_MODE_PUBLIC_ID_PREFIXES = [ | ||
"+//silmaril//dtd html pro v0r11 19970101//en", | ||
"-//advasoft ltd//dtd html 3.0 aswedit + extensions//en", | ||
"-//as//dtd html 3.0 aswedit + extensions//en", | ||
"-//ietf//dtd html 2.0 level 1//en", | ||
"-//ietf//dtd html 2.0 level 2//en", | ||
"-//ietf//dtd html 2.0 strict level 1//en", | ||
"-//ietf//dtd html 2.0 strict level 2//en", | ||
"-//ietf//dtd html 2.0 strict//en", | ||
"-//ietf//dtd html 2.0//en", | ||
"-//ietf//dtd html 2.1e//en", | ||
"-//ietf//dtd html 3.0//en", | ||
"-//ietf//dtd html 3.0//en//", | ||
"-//ietf//dtd html 3.2 final//en", | ||
"-//ietf//dtd html 3.2//en", | ||
"-//ietf//dtd html 3//en", | ||
"-//ietf//dtd html level 0//en", | ||
"-//ietf//dtd html level 0//en//2.0", | ||
"-//ietf//dtd html level 1//en", | ||
"-//ietf//dtd html level 1//en//2.0", | ||
"-//ietf//dtd html level 2//en", | ||
"-//ietf//dtd html level 2//en//2.0", | ||
"-//ietf//dtd html level 3//en", | ||
"-//ietf//dtd html level 3//en//3.0", | ||
"-//ietf//dtd html strict level 0//en", | ||
"-//ietf//dtd html strict level 0//en//2.0", | ||
"-//ietf//dtd html strict level 1//en", | ||
"-//ietf//dtd html strict level 1//en//2.0", | ||
"-//ietf//dtd html strict level 2//en", | ||
"-//ietf//dtd html strict level 2//en//2.0", | ||
"-//ietf//dtd html strict level 3//en", | ||
"-//ietf//dtd html strict level 3//en//3.0", | ||
"-//ietf//dtd html strict//en", | ||
"-//ietf//dtd html strict//en//2.0", | ||
"-//ietf//dtd html strict//en//3.0", | ||
"-//ietf//dtd html//en", | ||
"-//ietf//dtd html//en//2.0", | ||
"-//ietf//dtd html//en//3.0", | ||
"-//metrius//dtd metrius presentational//en", | ||
"-//microsoft//dtd internet explorer 2.0 html strict//en", | ||
"-//microsoft//dtd internet explorer 2.0 html//en", | ||
"-//microsoft//dtd internet explorer 2.0 tables//en", | ||
"-//microsoft//dtd internet explorer 3.0 html strict//en", | ||
"-//microsoft//dtd internet explorer 3.0 html//en", | ||
"-//microsoft//dtd internet explorer 3.0 tables//en", | ||
"-//netscape comm. corp.//dtd html//en", | ||
"-//netscape comm. corp.//dtd strict html//en", | ||
"-//o'reilly and associates//dtd html 2.0//en", | ||
"-//o'reilly and associates//dtd html extended 1.0//en", | ||
"-//spyglass//dtd html 2.0 extended//en", | ||
"-//sq//dtd html 2.0 hotmetal + extensions//en", | ||
"-//sun microsystems corp.//dtd hotjava html//en", | ||
"-//sun microsystems corp.//dtd hotjava strict html//en", | ||
"-//w3c//dtd html 3 1995-03-24//en", | ||
"-//w3c//dtd html 3.2 draft//en", | ||
"-//w3c//dtd html 3.2 final//en", | ||
"-//w3c//dtd html 3.2//en", | ||
"-//w3c//dtd html 3.2s draft//en", | ||
"-//w3c//dtd html 4.0 frameset//en", | ||
"-//w3c//dtd html 4.0 transitional//en", | ||
"-//w3c//dtd html experimental 19960712//en", | ||
"-//w3c//dtd html experimental 970421//en", | ||
"-//w3c//dtd w3 html//en", | ||
"-//w3o//dtd w3 html 3.0//en", | ||
"-//w3o//dtd w3 html 3.0//en//", | ||
"-//webtechs//dtd mozilla html 2.0//en", | ||
"-//webtechs//dtd mozilla html//en" | ||
], | ||
QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES = [ | ||
'-//w3c//dtd html 4.01 frameset//', | ||
'-//w3c//dtd html 4.01 transitional//' | ||
], | ||
QUIRKS_MODE_PUBLIC_IDS = [ | ||
'-//w3o//dtd w3 html strict 3.0//en//', | ||
'-/w3c/dtd html 4.0 transitional/en', | ||
'html' | ||
]; | ||
|
||
|
||
//Utils | ||
function enquoteDoctypeId(id) { | ||
var quote = id.indexOf('"') !== -1 ? '\'' : '"'; | ||
|
||
return quote + id + quote; | ||
} | ||
|
||
|
||
//API | ||
exports.isQuirks = function (name, publicId, systemId) { | ||
if (name !== VALID_DOCTYPE_NAME) | ||
return true; | ||
|
||
if (systemId && systemId.toLowerCase() === QUIRKS_MODE_SYSTEM_ID) | ||
return true; | ||
|
||
if (publicId !== null) { | ||
publicId = publicId.toLowerCase(); | ||
|
||
if (QUIRKS_MODE_PUBLIC_IDS.indexOf(publicId) > -1) | ||
return true; | ||
|
||
var prefixes = QUIRKS_MODE_PUBLIC_ID_PREFIXES; | ||
|
||
if (systemId === null) | ||
prefixes = prefixes.concat(QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES); | ||
|
||
for (var i = 0; i < prefixes.length; i++) { | ||
if (publicId.indexOf(prefixes[i]) === 0) | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
}; | ||
|
||
exports.serializeContent = function (name, publicId, systemId) { | ||
var str = '!DOCTYPE ' + name; | ||
|
||
if (publicId !== null) | ||
str += ' PUBLIC ' + enquoteDoctypeId(publicId); | ||
|
||
else if (systemId !== null) | ||
str += ' SYSTEM'; | ||
|
||
if (systemId !== null) | ||
str += ' ' + enquoteDoctypeId(systemId); | ||
|
||
return str; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters