MpHtmlParser.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. /*
  2. 将 html 解析为适用于小程序 rich-text 的 DOM 结构
  3. github:https://github.com/jin-yufeng/Parser
  4. docs:https://jin-yufeng.github.io/Parser
  5. author:JinYufeng
  6. update:2020/04/13
  7. */
  8. var cfg = require('./config.js'),
  9. blankChar = cfg.blankChar,
  10. CssHandler = require('./CssHandler.js'),
  11. {
  12. screenWidth,
  13. system
  14. } = wx.getSystemInfoSync();
  15. // #ifdef MP-BAIDU || MP-ALIPAY || MP-TOUTIAO
  16. var entities = {
  17. lt: '<',
  18. gt: '>',
  19. amp: '&',
  20. quot: '"',
  21. apos: "'",
  22. nbsp: '\xA0',
  23. ensp: '\u2002',
  24. emsp: '\u2003',
  25. ndash: '–',
  26. mdash: '—',
  27. middot: '·',
  28. lsquo: '‘',
  29. rsquo: '’',
  30. ldquo: '“',
  31. rdquo: '”',
  32. bull: '•',
  33. hellip: '…',
  34. permil: '‰',
  35. copy: '©',
  36. reg: '®',
  37. trade: '™',
  38. times: '×',
  39. divide: '÷',
  40. cent: '¢',
  41. pound: '£',
  42. yen: '¥',
  43. euro: '€',
  44. sect: '§'
  45. };
  46. // #endif
  47. var emoji; // emoji 补丁包 https://jin-yufeng.github.io/Parser/#/instructions?id=emoji
  48. class MpHtmlParser {
  49. constructor(data, options = {}) {
  50. this.attrs = {};
  51. this.compress = options.compress;
  52. this.CssHandler = new CssHandler(options.tagStyle, screenWidth);
  53. this.data = data;
  54. this.domain = options.domain;
  55. this.DOM = [];
  56. this.i = this.start = this.audioNum = this.imgNum = this.videoNum = 0;
  57. this.protocol = this.domain && this.domain.includes('://') ? this.domain.split('://')[0] : '';
  58. this.state = this.Text;
  59. this.STACK = [];
  60. this.useAnchor = options.useAnchor;
  61. this.xml = options.xml;
  62. }
  63. parse() {
  64. if (emoji) this.data = emoji.parseEmoji(this.data);
  65. for (var c; c = this.data[this.i]; this.i++)
  66. this.state(c);
  67. if (this.state == this.Text) this.setText();
  68. while (this.STACK.length) this.popNode(this.STACK.pop());
  69. // #ifdef MP-BAIDU || MP-TOUTIAO
  70. // 将顶层标签的一些样式提取出来给 rich-text
  71. (function f(ns) {
  72. for (var i = ns.length, n; n = ns[--i];) {
  73. if (n.type == 'text') continue;
  74. if (!n.c) {
  75. var style = n.attrs.style;
  76. if (style) {
  77. var j, k, res;
  78. if ((j = style.indexOf('display')) != -1)
  79. res = style.substring(j, (k = style.indexOf(';', j)) == -1 ? style.length : k);
  80. if ((j = style.indexOf('float')) != -1)
  81. res += ';' + style.substring(j, (k = style.indexOf(';', j)) == -1 ? style.length : k);
  82. n.attrs.contain = res;
  83. }
  84. } else f(n.children);
  85. }
  86. })(this.DOM);
  87. // #endif
  88. if (this.DOM.length) {
  89. this.DOM[0].PoweredBy = 'Parser';
  90. if (this.title) this.DOM[0].title = this.title;
  91. }
  92. return this.DOM;
  93. }
  94. // 设置属性
  95. setAttr() {
  96. var name = this.getName(this.attrName);
  97. if (cfg.trustAttrs[name]) {
  98. if (!this.attrVal) {
  99. if (cfg.boolAttrs[name]) this.attrs[name] = 'T';
  100. } else if (name == 'src') this.attrs[name] = this.getUrl(this.attrVal.replace(/&amp;/g, '&'));
  101. else this.attrs[name] = this.attrVal;
  102. }
  103. this.attrVal = '';
  104. while (blankChar[this.data[this.i]]) this.i++;
  105. if (this.isClose()) this.setNode();
  106. else {
  107. this.start = this.i;
  108. this.state = this.AttrName;
  109. }
  110. }
  111. // 设置文本节点
  112. setText() {
  113. var back, text = this.section();
  114. if (!text) return;
  115. text = (cfg.onText && cfg.onText(text, () => back = true)) || text;
  116. if (back) {
  117. this.data = this.data.substr(0, this.start) + text + this.data.substr(this.i);
  118. let j = this.start + text.length;
  119. for (this.i = this.start; this.i < j; this.i++) this.state(this.data[this.i]);
  120. return;
  121. }
  122. if (!this.pre) {
  123. // 合并空白符
  124. var tmp = [];
  125. for (let i = text.length, c; c = text[--i];)
  126. if (!blankChar[c] || (!blankChar[tmp[0]] && (c = ' '))) tmp.unshift(c);
  127. text = tmp.join('');
  128. if (text == ' ') return;
  129. }
  130. // 处理实体
  131. var siblings = this.siblings(),
  132. i = -1,
  133. j, en;
  134. while (1) {
  135. if ((i = text.indexOf('&', i + 1)) == -1) break;
  136. if ((j = text.indexOf(';', i + 2)) == -1) break;
  137. if (text[i + 1] == '#') {
  138. en = parseInt((text[i + 2] == 'x' ? '0' : '') + text.substring(i + 2, j));
  139. if (!isNaN(en)) text = text.substr(0, i) + String.fromCharCode(en) + text.substring(j + 1);
  140. } else {
  141. en = text.substring(i + 1, j);
  142. // #ifdef MP-WEIXIN || MP-QQ || APP-PLUS
  143. if (en == 'nbsp') text = text.substr(0, i) + '\xA0' + text.substr(j + 1); // 解决 &nbsp; 失效
  144. else if (en != 'lt' && en != 'gt' && en != 'amp' && en != 'ensp' && en != 'emsp' && en != 'quot' && en != 'apos') {
  145. i && siblings.push({
  146. type: 'text',
  147. text: text.substr(0, i)
  148. })
  149. siblings.push({
  150. type: 'text',
  151. text: `&${en};`,
  152. en: 1
  153. })
  154. text = text.substr(j + 1);
  155. i = -1;
  156. }
  157. // #endif
  158. // #ifdef MP-BAIDU || MP-ALIPAY || MP-TOUTIAO
  159. if (entities[en]) text = text.substr(0, i) + entities[en] + text.substr(j + 1);
  160. // #endif
  161. }
  162. }
  163. text && siblings.push({
  164. type: 'text',
  165. text
  166. })
  167. }
  168. // 设置元素节点
  169. setNode() {
  170. var node = {
  171. name: this.tagName.toLowerCase(),
  172. attrs: this.attrs
  173. },
  174. close = cfg.selfClosingTags[node.name] || (this.xml && this.data[this.i] == '/');
  175. this.attrs = {};
  176. if (!cfg.ignoreTags[node.name]) {
  177. this.matchAttr(node);
  178. if (!close) {
  179. node.children = [];
  180. if (node.name == 'pre' && cfg.highlight) {
  181. this.remove(node);
  182. this.pre = node.pre = true;
  183. }
  184. this.siblings().push(node);
  185. this.STACK.push(node);
  186. } else if (!cfg.filter || cfg.filter(node, this) != false)
  187. this.siblings().push(node);
  188. } else {
  189. if (!close) this.remove(node);
  190. else if (node.name == 'source') {
  191. var parent = this.STACK[this.STACK.length - 1],
  192. attrs = node.attrs;
  193. if (parent && attrs.src)
  194. if (parent.name == 'video' || parent.name == 'audio')
  195. parent.attrs.source.push(attrs.src);
  196. else {
  197. var i, media = attrs.media;
  198. if (parent.name == 'picture' && !parent.attrs.src && !(attrs.src.indexOf('.webp') && system.includes('iOS')) &&
  199. (!media || (media.includes('px') &&
  200. (((i = media.indexOf('min-width')) != -1 && (i = media.indexOf(':', i + 8)) != -1 && screenWidth > parseInt(
  201. media.substr(i + 1))) ||
  202. ((i = media.indexOf('max-width')) != -1 && (i = media.indexOf(':', i + 8)) != -1 && screenWidth < parseInt(
  203. media.substr(i + 1)))))))
  204. parent.attrs.src = attrs.src;
  205. }
  206. } else if (node.name == 'base' && !this.domain) this.domain = node.attrs.href;
  207. }
  208. if (this.data[this.i] == '/') this.i++;
  209. this.start = this.i + 1;
  210. this.state = this.Text;
  211. }
  212. // 移除标签
  213. remove(node) {
  214. var name = node.name,
  215. j = this.i;
  216. while (1) {
  217. if ((this.i = this.data.indexOf('</', this.i + 1)) == -1) {
  218. if (name == 'pre' || name == 'svg') this.i = j;
  219. else this.i = this.data.length;
  220. return;
  221. }
  222. this.start = (this.i += 2);
  223. while (!blankChar[this.data[this.i]] && !this.isClose()) this.i++;
  224. if (this.getName(this.section()) == name) {
  225. // 代码块高亮
  226. if (name == 'pre') {
  227. this.data = this.data.substr(0, j + 1) + cfg.highlight(this.data.substring(j + 1, this.i - 5), node.attrs) +
  228. this.data.substr(this.i - 5);
  229. return this.i = j;
  230. } else if (name == 'style')
  231. this.CssHandler.getStyle(this.data.substring(j + 1, this.i - 7));
  232. else if (name == 'title')
  233. this.title = this.data.substring(j + 1, this.i - 7);
  234. if ((this.i = this.data.indexOf('>', this.i)) == -1) this.i = this.data.length;
  235. // 处理 svg
  236. if (name == 'svg') {
  237. var src = this.data.substring(j, this.i + 1);
  238. if (!node.attrs.xmlns) src = ' xmlns="http://www.w3.org/2000/svg"' + src;
  239. var i = j;
  240. while (this.data[j] != '<') j--;
  241. src = this.data.substring(j, i) + src;
  242. var parent = this.STACK[this.STACK.length - 1];
  243. if (node.attrs.width == '100%' && parent && (parent.attrs.style || '').includes('inline'))
  244. parent.attrs.style = 'width:300px;max-width:100%;' + parent.attrs.style;
  245. this.siblings().push({
  246. name: 'img',
  247. attrs: {
  248. src: 'data:image/svg+xml;utf8,' + src.replace(/#/g, '%23'),
  249. ignore: 'T'
  250. }
  251. })
  252. }
  253. return;
  254. }
  255. }
  256. }
  257. // 处理属性
  258. matchAttr(node) {
  259. var attrs = node.attrs,
  260. style = this.CssHandler.match(node.name, attrs, node) + (attrs.style || ''),
  261. styleObj = {};
  262. if (attrs.id) {
  263. if (this.compress & 1) attrs.id = void 0;
  264. else if (this.useAnchor) this.bubble();
  265. }
  266. if ((this.compress & 2) && attrs.class) attrs.class = void 0;
  267. switch (node.name) {
  268. case 'img':
  269. if (attrs['data-src']) {
  270. attrs.src = attrs.src || attrs['data-src'];
  271. attrs['data-src'] = void 0;
  272. }
  273. if (attrs.src && !attrs.ignore) {
  274. if (this.bubble()) attrs.i = (this.imgNum++).toString();
  275. else attrs.ignore = 'T';
  276. }
  277. break;
  278. case 'a':
  279. case 'ad':
  280. // #ifdef APP-PLUS
  281. case 'iframe':
  282. case 'embed':
  283. // #endif
  284. this.bubble();
  285. break;
  286. case 'font':
  287. if (attrs.color) {
  288. styleObj['color'] = attrs.color;
  289. attrs.color = void 0;
  290. }
  291. if (attrs.face) {
  292. styleObj['font-family'] = attrs.face;
  293. attrs.face = void 0;
  294. }
  295. if (attrs.size) {
  296. var size = parseInt(attrs.size);
  297. if (size < 1) size = 1;
  298. else if (size > 7) size = 7;
  299. var map = ['xx-small', 'x-small', 'small', 'medium', 'large', 'x-large', 'xx-large'];
  300. styleObj['font-size'] = map[size - 1];
  301. attrs.size = void 0;
  302. }
  303. break;
  304. case 'video':
  305. case 'audio':
  306. if (!attrs.id) attrs.id = node.name + (++this[`${node.name}Num`]);
  307. else this[`${node.name}Num`]++;
  308. if (node.name == 'video') {
  309. if (attrs.width) {
  310. style = `width:${parseFloat(attrs.width) + (attrs.width.includes('%') ? '%' : 'px')};${style}`;
  311. attrs.width = void 0;
  312. }
  313. if (attrs.height) {
  314. style = `height:${parseFloat(attrs.height) + (attrs.height.includes('%') ? '%' : 'px')};${style}`;
  315. attrs.height = void 0;
  316. }
  317. if (this.videoNum > 3) node.lazyLoad = true;
  318. }
  319. attrs.source = [];
  320. if (attrs.src) attrs.source.push(attrs.src);
  321. if (!attrs.controls && !attrs.autoplay)
  322. console.warn(`存在没有 controls 属性的 ${node.name} 标签,可能导致无法播放`, node);
  323. this.bubble();
  324. break;
  325. case 'td':
  326. case 'th':
  327. if (attrs.colspan || attrs.rowspan)
  328. for (var k = this.STACK.length, item; item = this.STACK[--k];)
  329. if (item.name == 'table') {
  330. item.c = void 0;
  331. break;
  332. }
  333. }
  334. if (attrs.align) {
  335. styleObj['text-align'] = attrs.align;
  336. attrs.align = void 0;
  337. }
  338. // 压缩 style
  339. var styles = style.replace(/&quot;/g, '"').replace(/&amp;/g, '&').split(';');
  340. style = '';
  341. for (var i = 0, len = styles.length; i < len; i++) {
  342. var info = styles[i].split(':');
  343. if (info.length < 2) continue;
  344. let key = info[0].trim().toLowerCase(),
  345. value = info.slice(1).join(':').trim();
  346. if (value.includes('-webkit') || value.includes('-moz') || value.includes('-ms') || value.includes('-o') || value
  347. .includes(
  348. 'safe'))
  349. style += `;${key}:${value}`;
  350. else if (!styleObj[key] || value.includes('import') || !styleObj[key].includes('import'))
  351. styleObj[key] = value;
  352. }
  353. if (node.name == 'img' && parseInt(styleObj.width || attrs.width) > screenWidth)
  354. styleObj.height = 'auto';
  355. for (var key in styleObj) {
  356. var value = styleObj[key];
  357. if (key.includes('flex') || key == 'order' || key == 'self-align') node.c = 1;
  358. // 填充链接
  359. if (value.includes('url')) {
  360. var j = value.indexOf('(');
  361. if (j++ != -1) {
  362. while (value[j] == '"' || value[j] == "'" || blankChar[value[j]]) j++;
  363. value = value.substr(0, j) + this.getUrl(value.substr(j));
  364. }
  365. }
  366. // 转换 rpx
  367. else if (value.includes('rpx'))
  368. value = value.replace(/[0-9.]+\s*rpx/g, $ => parseFloat($) * screenWidth / 750 + 'px');
  369. else if (key == 'white-space' && value.includes('pre'))
  370. this.pre = node.pre = true;
  371. style += `;${key}:${value}`;
  372. }
  373. style = style.substr(1);
  374. if (style) attrs.style = style;
  375. }
  376. // 节点出栈处理
  377. popNode(node) {
  378. // 空白符处理
  379. if (node.pre) {
  380. node.pre = this.pre = void 0;
  381. for (let i = this.STACK.length; i--;)
  382. if (this.STACK[i].pre)
  383. this.pre = true;
  384. }
  385. if (node.name == 'head' || (cfg.filter && cfg.filter(node, this) == false))
  386. return this.siblings().pop();
  387. var attrs = node.attrs;
  388. // 替换一些标签名
  389. if (node.name == 'picture') {
  390. node.name = 'img';
  391. if (!attrs.src && (node.children[0] || '').name == 'img')
  392. attrs.src = node.children[0].attrs.src;
  393. if (attrs.src && !attrs.ignore)
  394. attrs.i = (this.imgNum++).toString();
  395. return node.children = void 0;
  396. }
  397. if (cfg.blockTags[node.name]) node.name = 'div';
  398. else if (!cfg.trustTags[node.name]) node.name = 'span';
  399. // 处理列表
  400. if (node.c) {
  401. if (node.name == 'ul') {
  402. var floor = 1;
  403. for (let i = this.STACK.length; i--;)
  404. if (this.STACK[i].name == 'ul') floor++;
  405. if (floor != 1)
  406. for (let i = node.children.length; i--;)
  407. node.children[i].floor = floor;
  408. } else if (node.name == 'ol') {
  409. for (let i = 0, num = 1, child; child = node.children[i++];)
  410. if (child.name == 'li') {
  411. child.type = 'ol';
  412. child.num = ((num, type) => {
  413. if (type == 'a') return String.fromCharCode(97 + (num - 1) % 26);
  414. if (type == 'A') return String.fromCharCode(65 + (num - 1) % 26);
  415. if (type == 'i' || type == 'I') {
  416. num = (num - 1) % 99 + 1;
  417. var one = ['I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'],
  418. ten = ['X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'],
  419. res = (ten[Math.floor(num / 10) - 1] || '') + (one[num % 10 - 1] || '');
  420. if (type == 'i') return res.toLowerCase();
  421. return res;
  422. }
  423. return num;
  424. })(num++, attrs.type) + '.';
  425. }
  426. }
  427. }
  428. // 处理表格的边框
  429. if (node.name == 'table') {
  430. var padding = attrs.cellpadding,
  431. spacing = attrs.cellspacing,
  432. border = attrs.border;
  433. if (node.c) {
  434. this.bubble();
  435. if (!padding) padding = 2;
  436. if (!spacing) spacing = 2;
  437. }
  438. if (border) attrs.style = `border:${border}px solid gray;${attrs.style || ''}`;
  439. if (spacing) attrs.style = `border-spacing:${spacing}px;${attrs.style || ''}`;
  440. if (border || padding)
  441. (function f(ns) {
  442. for (var i = 0, n; n = ns[i]; i++) {
  443. if (n.name == 'th' || n.name == 'td') {
  444. if (border) n.attrs.style = `border:${border}px solid gray;${n.attrs.style}`;
  445. if (padding) n.attrs.style = `padding:${padding}px;${n.attrs.style}`;
  446. } else f(n.children || []);
  447. }
  448. })(node.children)
  449. }
  450. this.CssHandler.pop && this.CssHandler.pop(node);
  451. // 自动压缩
  452. if (node.name == 'div' && !Object.keys(attrs).length) {
  453. var siblings = this.siblings();
  454. if (node.children.length == 1 && node.children[0].name == 'div')
  455. siblings[siblings.length - 1] = node.children[0];
  456. }
  457. }
  458. // 工具函数
  459. bubble() {
  460. for (var i = this.STACK.length, item; item = this.STACK[--i];) {
  461. if (cfg.richOnlyTags[item.name]) {
  462. if (item.name == 'table' && !Object.hasOwnProperty.call(item, 'c')) item.c = 1;
  463. return false;
  464. }
  465. item.c = 1;
  466. }
  467. return true;
  468. }
  469. getName = val => this.xml ? val : val.toLowerCase();
  470. getUrl(url) {
  471. if (url[0] == '/') {
  472. if (url[1] == '/') url = this.protocol + ':' + url;
  473. else if (this.domain) url = this.domain + url;
  474. } else if (this.domain && url.indexOf('data:') != 0 && !url.includes('://'))
  475. url = this.domain + '/' + url;
  476. return url;
  477. }
  478. isClose = () => this.data[this.i] == '>' || (this.data[this.i] == '/' && this.data[this.i + 1] == '>');
  479. section = () => this.data.substring(this.start, this.i);
  480. siblings = () => this.STACK.length ? this.STACK[this.STACK.length - 1].children : this.DOM;
  481. // 状态机
  482. Text(c) {
  483. if (c == '<') {
  484. var next = this.data[this.i + 1],
  485. isLetter = c => (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
  486. if (isLetter(next)) {
  487. this.setText();
  488. this.start = this.i + 1;
  489. this.state = this.TagName;
  490. } else if (next == '/') {
  491. this.setText();
  492. if (isLetter(this.data[++this.i + 1])) {
  493. this.start = this.i + 1;
  494. this.state = this.EndTag;
  495. } else
  496. this.Comment();
  497. } else if (next == '!') {
  498. this.setText();
  499. this.Comment();
  500. }
  501. }
  502. }
  503. Comment() {
  504. var key;
  505. if (this.data.substring(this.i + 2, this.i + 4) == '--') key = '-->';
  506. else if (this.data.substring(this.i + 2, this.i + 9) == '[CDATA[') key = ']]>';
  507. else key = '>';
  508. if ((this.i = this.data.indexOf(key, this.i + 2)) == -1) this.i = this.data.length;
  509. else this.i += key.length - 1;
  510. this.start = this.i + 1;
  511. this.state = this.Text;
  512. }
  513. TagName(c) {
  514. if (blankChar[c]) {
  515. this.tagName = this.section();
  516. while (blankChar[this.data[this.i]]) this.i++;
  517. if (this.isClose()) this.setNode();
  518. else {
  519. this.start = this.i;
  520. this.state = this.AttrName;
  521. }
  522. } else if (this.isClose()) {
  523. this.tagName = this.section();
  524. this.setNode();
  525. }
  526. }
  527. AttrName(c) {
  528. var blank = blankChar[c];
  529. if (blank) {
  530. this.attrName = this.section();
  531. c = this.data[this.i];
  532. }
  533. if (c == '=') {
  534. if (!blank) this.attrName = this.section();
  535. while (blankChar[this.data[++this.i]]);
  536. this.start = this.i--;
  537. this.state = this.AttrValue;
  538. } else if (blank) this.setAttr();
  539. else if (this.isClose()) {
  540. this.attrName = this.section();
  541. this.setAttr();
  542. }
  543. }
  544. AttrValue(c) {
  545. if (c == '"' || c == "'") {
  546. this.start++;
  547. if ((this.i = this.data.indexOf(c, this.i + 1)) == -1) return this.i = this.data.length;
  548. this.attrVal = this.section();
  549. this.i++;
  550. } else {
  551. for (; !blankChar[this.data[this.i]] && !this.isClose(); this.i++);
  552. this.attrVal = this.section();
  553. }
  554. this.setAttr();
  555. }
  556. EndTag(c) {
  557. if (blankChar[c] || c == '>' || c == '/') {
  558. var name = this.getName(this.section());
  559. for (var i = this.STACK.length; i--;)
  560. if (this.STACK[i].name == name) break;
  561. if (i != -1) {
  562. var node;
  563. while ((node = this.STACK.pop()).name != name);
  564. this.popNode(node);
  565. } else if (name == 'p' || name == 'br')
  566. this.siblings().push({
  567. name,
  568. attrs: {}
  569. });
  570. this.i = this.data.indexOf('>', this.i);
  571. this.start = this.i + 1;
  572. if (this.i == -1) this.i = this.data.length;
  573. else this.state = this.Text;
  574. }
  575. }
  576. }
  577. module.exports = MpHtmlParser;