Skip to content

Commit b10f43f

Browse files
committed
complete EntityMap
1 parent 162cabc commit b10f43f

File tree

2 files changed

+173
-10
lines changed

2 files changed

+173
-10
lines changed

dom-parser.js

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
function DOMParser(options){
22
this.options = options ||{locator:{}};
3-
3+
44
}
5-
DOMParser.prototype.parseFromString = function(source,mimeType){
5+
DOMParser.prototype.parseFromString = function(source,mimeType){
66
var options = this.options;
77
var sax = new XMLReader();
88
var domBuilder = options.domBuilder || new DOMHandler();//contentHandler and LexicalHandler
99
var errorHandler = options.errorHandler;
1010
var locator = options.locator;
1111
var defaultNSMap = options.xmlns||{};
12-
var entityMap = {'lt':'<','gt':'>','amp':'&','quot':'"','apos':"'"}
12+
if(typeof require == 'function'){
13+
var entityMap = require('./entity-map').EntityMap;
14+
}
1315
if(locator){
1416
domBuilder.setDocumentLocator(locator)
1517
}
16-
18+
1719
sax.errorHandler = buildErrorHandler(errorHandler,domBuilder,locator);
1820
sax.domBuilder = options.domBuilder || domBuilder;
1921
if(/\/x?html?$/.test(mimeType)){
@@ -58,8 +60,8 @@ function buildErrorHandler(errorImpl,domBuilder,locator){
5860
/**
5961
* +ContentHandler+ErrorHandler
6062
* +LexicalHandler+EntityResolver2
61-
* -DeclHandler-DTDHandler
62-
*
63+
* -DeclHandler-DTDHandler
64+
*
6365
* DefaultHandler:EntityResolver, DTDHandler, ContentHandler, ErrorHandler
6466
* DefaultHandler2:DefaultHandler,LexicalHandler, DeclHandler, EntityResolver2
6567
* @link http://www.saxproject.org/apidoc/org/xml/sax/helpers/DefaultHandler.html
@@ -74,7 +76,7 @@ function position(locator,node){
7476
/**
7577
* @see org.xml.sax.ContentHandler#startDocument
7678
* @link http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
77-
*/
79+
*/
7880
DOMHandler.prototype = {
7981
startDocument : function() {
8082
this.document = new DOMImplementation().createDocument(null, null, null);
@@ -88,7 +90,7 @@ DOMHandler.prototype = {
8890
var len = attrs.length;
8991
appendElement(this, el);
9092
this.currentElement = el;
91-
93+
9294
this.locator && position(this.locator,el)
9395
for (var i = 0 ; i < len; i++) {
9496
var namespaceURI = attrs.getURI(i);
@@ -149,15 +151,15 @@ DOMHandler.prototype = {
149151
this.locator && position(this.locator,comm)
150152
appendElement(this, comm);
151153
},
152-
154+
153155
startCDATA:function() {
154156
//used in characters() methods
155157
this.cdata = true;
156158
},
157159
endCDATA:function() {
158160
this.cdata = false;
159161
},
160-
162+
161163
startDTD:function(name, publicId, systemId) {
162164
var impl = this.document.implementation;
163165
if (impl && impl.createDocumentType) {

entity-map.js

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
var EntityMap = {
2+
'lt': '<',
3+
'gt': '>',
4+
'amp': '&',
5+
'quot': '"',
6+
'apos': "'",
7+
8+
// Math
9+
10+
'forall': '\u2200', // for all
11+
'part': '\u2202', // part
12+
'exists': '\u2203', // exists
13+
'empty': '\u2205', // empty
14+
'nabla': '\u2207', // nabla
15+
'isin': '\u2208', // isin
16+
'notin': '\u2209', // notin
17+
'ni': '\u220B', // ni
18+
'prod': '\u220F', // prod
19+
'sum': '\u2211', // sum
20+
'minus': '\u2212', // minus
21+
'lowast': '\u2217', // lowast
22+
'radic': '\u221A', // square root
23+
'prop': '\u221D', // proportional to
24+
'infin': '\u221E', // infinity
25+
'ang': '\u2220', // angle
26+
'and': '\u2227', // and
27+
'or': '\u2228', // or
28+
'cap': '\u2229', // cap
29+
'cup': '\u222A', // cup
30+
'int': '\u222B', // integral
31+
'there4': '\u2234', // therefore
32+
'sim': '\u223C', // simular to
33+
'cong': '\u2245', // approximately equal
34+
'asymp': '\u2248', // almost equal
35+
'ne': '\u2260', // not equal
36+
'equiv': '\u2261', // equivalent
37+
'le': '\u2264', // less or equal
38+
'ge': '\u2265', // greater or equal
39+
'sub': '\u2282', // subset of
40+
'sup': '\u2283', // superset of
41+
'nsub': '\u2284', // not subset of
42+
'sube': '\u2286', // subset or equal
43+
'supe': '\u2287', // superset or equal
44+
'oplus': '\u2295', // circled plus
45+
'otimes': '\u2297', // cirled times
46+
'perp': '\u22A5', // perpendicular
47+
'sdot': '\u22C5', // dot operator
48+
49+
// Greek
50+
51+
'Alpha': '\u0391', // Alpha
52+
'Beta': '\u0392', // Beta
53+
'Gamma': '\u0393', // Gamma
54+
'Delta': '\u0394', // Delta
55+
'Epsilon': '\u0395', // Epsilon
56+
'Zeta': '\u0396', // Zeta
57+
'Eta': '\u0397', // Eta
58+
'Theta': '\u0398', // Theta
59+
'Iota': '\u0399', // Iota
60+
'Kappa': '\u039A', // Kappa
61+
'Lambda': '\u039B', // Lambda
62+
'Mu': '\u039C', // Mu
63+
'Nu': '\u039D', // Nu
64+
'Xi': '\u039E', // Xi
65+
'Omicron': '\u039F', // Omicron
66+
'Pi': '\u03A0', // Pi
67+
'Rho': '\u03A1', // Rho
68+
'Sigma': '\u03A3', // Sigma
69+
'Tau': '\u03A4', // Tau
70+
'Upsilon': '\u03A5', // Upsilon
71+
'Phi': '\u03A6', // Phi
72+
'Chi': '\u03A7', // Chi
73+
'Psi': '\u03A8', // Psi
74+
'Omega': '\u03A9', // Omega
75+
76+
'alpha': '\u03B1', // alpha
77+
'beta': '\u03B2', // beta
78+
'gamma': '\u03B3', // gamma
79+
'delta': '\u03B4', // delta
80+
'epsilon': '\u03B5', // epsilon
81+
'zeta': '\u03B6', // zeta
82+
'eta': '\u03B7', // eta
83+
'theta': '\u03B8', // theta
84+
'iota': '\u03B9', // iota
85+
'kappa': '\u03BA', // kappa
86+
'lambda': '\u03BB', // lambda
87+
'mu': '\u03BC', // mu
88+
'nu': '\u03BD', // nu
89+
'xi': '\u03BE', // xi
90+
'omicron': '\u03BF', // omicron
91+
'pi': '\u03C0', // pi
92+
'rho': '\u03C1', // rho
93+
'sigmaf': '\u03C2', // sigmaf
94+
'sigma': '\u03C3', // sigma
95+
'tau': '\u03C4', // tau
96+
'upsilon': '\u03C5', // upsilon
97+
'phi': '\u03C6', // phi
98+
'chi': '\u03C7', // chi
99+
'psi': '\u03C8', // psi
100+
'omega': '\u03C9', // omega
101+
'thetasym': '\u03D1', // theta symbol
102+
'upsih': '\u03D2', // upsilon symbol
103+
'piv': '\u03D6', // pi symbol
104+
105+
// Others
106+
107+
'OElig': '\u0152', // capital ligature OE
108+
'oelig': '\u0153', // small ligature oe
109+
'Scaron': '\u0160', // capital S with caron
110+
'scaron': '\u0161', // small S with caron
111+
'Yuml': '\u0178', // capital Y with diaeres
112+
'fnof': '\u0192', // f with hook
113+
'circ': '\u02C6', // modifier letter circumflex accent
114+
'tilde': '\u02DC', // small tilde
115+
'ensp': '\u2002', // en space
116+
'emsp': '\u2003', // em space
117+
'thinsp': '\u2009', // thin space
118+
'zwnj': '\u200C', // zero width non-joiner
119+
'zwj': '\u200D', // zero width joiner
120+
'lrm': '\u200E', // left-to-right mark
121+
'rlm': '\u200F', // right-to-left mark
122+
'ndash': '\u2013', // en dash
123+
'mdash': '\u2014', // em dash
124+
'lsquo': '\u2018', // left single quotation mark
125+
'rsquo': '\u2019', // right single quotation mark
126+
'sbquo': '\u201A', // single low-9 quotation mark
127+
'ldquo': '\u201C', // left double quotation mark
128+
'rdquo': '\u201D', // right double quotation mark
129+
'bdquo': '\u201E', // double low-9 quotation mark
130+
'dagger': '\u2020', // dagger
131+
'Dagger': '\u2021', // double dagger
132+
'bull': '\u2022', // bullet
133+
'hellip': '\u2026', // horizontal ellipsis
134+
'permil': '\u2030', // per mille 
135+
'prime': '\u2032', // minutes
136+
'Prime': '\u2033', // seconds
137+
'lsaquo': '\u2039', // single left angle quotation
138+
'rsaquo': '\u203A', // single right angle quotation
139+
'oline': '\u203E', // overline
140+
'euro': '\u20AC', // euro
141+
'trade': '\u2122', // trademark
142+
'larr': '\u2190', // left arrow
143+
'uarr': '\u2191', // up arrow
144+
'rarr': '\u2192', // right arrow
145+
'darr': '\u2193', // down arrow
146+
'harr': '\u2194', // left right arrow
147+
'crarr': '\u21B5', // carriage return arrow
148+
'lceil': '\u2308', // left ceiling
149+
'rceil': '\u2309', // right ceiling
150+
'lfloor': '\u230A', // left floor
151+
'rfloor': '\u230B', // right floor
152+
'loz': '\u25CA', // lozenge
153+
'spades': '\u2660', // spade
154+
'clubs': '\u2663', // club
155+
'hearts': '\u2665', // heart
156+
'diams': '\u2666', // diamond
157+
}
158+
159+
if(typeof require == 'function'){
160+
exports.EntityMap = EntityMap;
161+
}

0 commit comments

Comments
 (0)