MCPcopy
hub / github.com/icindy/wxParse / HTMLParser

Function HTMLParser

wxParse/htmlparser.js:38–182  ·  view source on GitHub ↗
(html, handler)

Source from the content-addressed store, hash-verified

36var special = makeMap("wxxxcode-style,script,style,view,scroll-view,block");
37
38function HTMLParser(html, handler) {
39 var index, chars, match, stack = [], last = html;
40 stack.last = function () {
41 return this[this.length - 1];
42 };
43
44 while (html) {
45 chars = true;
46
47 // Make sure we're not in a script or style element
48 if (!stack.last() || !special[stack.last()]) {
49
50 // Comment
51 if (html.indexOf("<!--") == 0) {
52 index = html.indexOf("-->");
53
54 if (index >= 0) {
55 if (handler.comment)
56 handler.comment(html.substring(4, index));
57 html = html.substring(index + 3);
58 chars = false;
59 }
60
61 // end tag
62 } else if (html.indexOf("</") == 0) {
63 match = html.match(endTag);
64
65 if (match) {
66 html = html.substring(match[0].length);
67 match[0].replace(endTag, parseEndTag);
68 chars = false;
69 }
70
71 // start tag
72 } else if (html.indexOf("<") == 0) {
73 match = html.match(startTag);
74
75 if (match) {
76 html = html.substring(match[0].length);
77 match[0].replace(startTag, parseStartTag);
78 chars = false;
79 }
80 }
81
82 if (chars) {
83 index = html.indexOf("<");
84 var text = ''
85 while (index === 0) {
86 text += "<";
87 html = html.substring(1);
88 index = html.indexOf("<");
89 }
90 text += index < 0 ? html : html.substring(0, index);
91 html = index < 0 ? "" : html.substring(index);
92
93 if (handler.chars)
94 handler.chars(text);
95 }

Callers 1

html2jsonFunction · 0.85

Calls 1

parseEndTagFunction · 0.85

Tested by

no test coverage detected