Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added shy, mdash, ndash to entityMap. #205

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
21 changes: 12 additions & 9 deletions dom-parser.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function DOMParser(options){
this.options = options ||{locator:{}};

}

DOMParser.prototype.parseFromString = function(source,mimeType){
Expand All @@ -11,11 +11,14 @@ DOMParser.prototype.parseFromString = function(source,mimeType){
var locator = options.locator;
var defaultNSMap = options.xmlns||{};
var isHTML = /\/x?html?$/.test(mimeType);//mimeType.toLowerCase().indexOf('html') > -1;
var entityMap = isHTML?htmlEntity.entityMap:{'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"};
var entityMap = isHTML?htmlEntity.entityMap: {
'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'",
'shy': '-','mdash': '-','ndash': '-'
};
if(locator){
domBuilder.setDocumentLocator(locator)
}

sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
sax.domBuilder = options.domBuilder || domBuilder;
if(isHTML){
Expand Down Expand Up @@ -58,8 +61,8 @@ function buildErrorHandler(errorImpl,domBuilder,locator){
/**
* +ContentHandler+ErrorHandler
* +LexicalHandler+EntityResolver2
* -DeclHandler-DTDHandler
*
* -DeclHandler-DTDHandler
*
* DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
* DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
* @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
Expand All @@ -74,7 +77,7 @@ function position(locator,node){
/**
* @see org.xml.sax.ContentHandler#startDocument
* @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
*/
*/
DOMHandler.prototype = {
startDocument : function() {
this.doc = new DOMImplementation().createDocument(null, null, null);
Expand All @@ -88,7 +91,7 @@ DOMHandler.prototype = {
var len = attrs.length;
appendElement(this, el);
this.currentElement = el;

this.locator && position(this.locator,el)
for (var i = 0 ; i < len; i++) {
var namespaceURI = attrs.getURI(i);
Expand Down Expand Up @@ -151,15 +154,15 @@ DOMHandler.prototype = {
this.locator && position(this.locator,comm)
appendElement(this, comm);
},

startCDATA:function() {
//used in characters() methods
this.cdata = true;
},
endCDATA:function() {
this.cdata = false;
},

startDTD:function(name, publicId, systemId) {
var impl = this.doc.implementation;
if (impl && impl.createDocumentType) {
Expand Down