1 Star 0 Fork 0

Sterne Lee/mapp-coder-weekly

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
parse.js 24.12 KB
一键复制 编辑 原始数据 按行查看 历史
李兴广 提交于 2020-03-28 21:33 . feat(weekly): 更新页面
const html = `
<table border=0 align="center" border="0"> <tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; "> <div> <table border=0 border=0><tr> <td align="left" style="padding-left: 4px; font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; "><p>#480 — March 20, 2020</p></td> <td align="right" style="padding-right: 4px; font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; "><p><a href="https://javascriptweekly.com/link/85694/rss" style=" color: #3366aa;">Unsubscribe</a> : <a href="https://javascriptweekly.com/link/85695/rss" style=" color: #3366aa;">Read on the Web</a></p></td> </tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p>✍️ We hope you're doing okay in these unusual times. We'll be publishing <em>JavaScript Weekly</em> as usual, but you may notice some changes as we adapt – please hang in there with us 🙂</p> <p>If you have anything to share that would help the community, virtual events, etc. you can reply to any issue to let us know and we'll try to share what we can :-)<br><em>— Peter C, your humble editor.</em></p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0 12px;"><p>JavaScript Weekly</p></td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; "> <a href="https://javascriptweekly.com/link/85703/rss" style=" color: #3366aa;"><img src="https://res.cloudinary.com/cpress/image/upload/w_1280,e_sharpen:60/wdp6q3sspl8ojqzkfsc6.jpg" width="640" style=" line-height: 100%; "></a> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85703/rss" title="github.com" style=" color: #3366aa; font-size: 1.1em; line-height: 1.4em;">μPlot 1.0: A Fast, Tiny Time Series Chart Library</a></span> — A fast, memory efficient Canvas-based time series plotting library. How fast? Try 150,000 data points in 60ms fast. <a href="https://javascriptweekly.com/link/85704/rss" style=" color: #3366aa; ">Lots of demos here</a>.</p> <p>Leon Sorokin </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85705/rss" title="github.blog" style=" color: #3366aa; font-size: 1.05em;">npm is Joining GitHub</a></span> — This is perhaps the biggest Node news of the year! npm Inc. (including the public repository) is being acquired by GitHub (who you might recall launched their own <a href="https://javascriptweekly.com/link/85706/rss" style=" color: #3366aa; ">package registry</a> less than a year ago). Fingers crossed this only means good things for npm. If you want more background, Isaac Z. Schlueter tells <a href="https://javascriptweekly.com/link/85707/rss" style=" color: #3366aa; ">his side of the story here.</a></p> <p>GitHub </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <a href="https://javascriptweekly.com/link/85696/rss" style=" color: #3366aa; "><img src="https://copm.s3.amazonaws.com/20fd5e89.png" width="166" height="125" style="padding-top: 12px; padding-left: 12px; line-height: 100%; "></a> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85696/rss" title="www.site24x7.com" style=" color: #3366aa; font-size: 1.05em;">Optimize Your Front-End Performance in Real-Time</a></span> — Identify JS errors, errors in AJAX calls, page load time with Site24x7 Real User Monitoring. You can also track your CDN performance, analyze user sessions, measure and reduce resource load time. <a href="https://javascriptweekly.com/link/85696/rss" style=" color: #3366aa; ">Sign Up</a>.</p> <p>Site24x7 <span style="text-transform: uppercase; margin-left: 4px; font-size: 0.9em; color: #993 !important; padding: 1px 4px; ">sponsor</span></p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85708/rss" title="phabricator.wikimedia.org" style=" color: #3366aa; font-size: 1.05em;">Wikimedia (The Folks Behind Wikipedia) Are Adopting Vue.js</a></span> — Wikimedia will be using Vue for their future front-end development, but no, Wikipedia is <em>not</em> becoming an SPA! This post digs into the how and why of the decision, while on Twitter, Vue.js creator Evan You <a href="https://javascriptweekly.com/link/85709/rss" style=" color: #3366aa; ">explains more from his side.</a> Hacker News had <a href="https://javascriptweekly.com/link/85710/rss" style=" color: #3366aa; ">a very busy thread</a> on the topic too.</p> <p>Wikimedia Foundation </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;">▶ <a href="https://javascriptweekly.com/link/85711/rss" title="snipcart.com" style=" color: #3366aa; font-size: 1.05em;">16 Hand-Picked JavaScript Podcasts Still Running in 2020</a></span> — This is an update of a list originally made in 2018. If you do, somehow, have spare time to listen to podcasts now, this up to date list may be useful.</p> <p>Mathieu Dionne <span style="text-transform: uppercase; margin-left: 4px; font-size: 0.9em; padding: 1px 4px; ">podcast</span></p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85727/rss" title="babeljs.io" style=" color: #3366aa; font-size: 1.05em;">Babel 7.9.0 Released</a></span> — A new minor release for the popular JavaScript compiler which includes updates related to <code>@babel/preset-env</code>, TypeScript 3.8, Flow, and JSX.</p> <p>Nicolò Ribaudo </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px;"> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p>⚡️ Quick Releases</p> <ul> <li><a href="https://javascriptweekly.com/link/85728/rss" style=" color: #3366aa; font-weight: 600;">Vue 3.0.0 alpha 9</a></li> <li> <a href="https://javascriptweekly.com/link/85729/rss" style=" color: #3366aa; font-weight: 600;">Vuex 4.0 alpha 1</a> — Adds support for Vue 3.0 alpha.</li> <li> <a href="https://javascriptweekly.com/link/85730/rss" style=" color: #3366aa; font-weight: 600;">Tesseract.js 2.1</a> — Pure JavaScript OCR.</li> <li> <a href="https://javascriptweekly.com/link/85731/rss" style=" color: #3366aa; font-weight: 600;">Cypress 4.2.0</a> — Test anything that runs in a browser.</li> <li> <a href="https://javascriptweekly.com/link/85732/rss" style=" color: #3366aa; font-weight: 600;">Grunt 1.1</a> — Legacy task runner.</li> </ul> </td></tr></table> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0;"><p>💻 Jobs</p></td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85697/rss" title="jobs.lever.co" style=" color: #3366aa; font-size: 1.05em;">UX/Frontend Engineer @ Siteline</a></span> — Join the founding engineering team at Siteline and help us revolutionize the payments process for construction.</p> <p>Siteline </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85698/rss" title="www.vettery.com" style=" color: #3366aa; font-size: 1.05em;">Find a Dev Job Through Vettery</a></span> — Vettery is completely free for job seekers. Make a profile, name your salary, and connect with hiring managers from top employers.</p> <p>Vettery </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0;"><p>📘 Articles &amp; Tutorials </p></td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; "> <a href="https://javascriptweekly.com/link/85712/rss" style=" color: #3366aa;"><img src="https://res.cloudinary.com/cpress/image/upload/w_1280,e_sharpen:60/fktpu5sy0e7forh8fwpv.jpg" width="640" style=" line-height: 100%; "></a> </td></tr></table> <table border=0 border=0><tr><td style=" font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; "></td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85712/rss" title="observablehq.com" style=" color: #3366aa; font-size: 1.05em;">An Interactive Introduction to AntV</a></span> — We recently linked to a neat <a href="https://javascriptweekly.com/link/85713/rss" style=" color: #3366aa; ">interactive introduction to D3</a>, here’s something similar for <a href="https://javascriptweekly.com/link/85714/rss" style=" color: #3366aa; ">AntV</a>, a data visualization toolset originally built for financial data. Worth a play.</p> <p>Jiazhe Wang </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85715/rss" title="www.smashingmagazine.com" style=" color: #3366aa; font-size: 1.05em;">Implementing Infinite Scroll And Image Lazy Loading</a></span> — A tutorial on using the Intersection Observer API to implement infinite scrolling and image lazy loading in a functional React component.</p> <p>Chidi Orji </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85701/rss" title="wallabyjs.com" style=" color: #3366aa; font-size: 1.05em;">A Much Faster Way to Debug Code Than with Breakpoints or console.log</a></span> — Move forward and backwards through your code to understand the conditions that led to a specific bug, view runtime values, edit-and-continue, and more.</p> <p>Wallaby.js <span style="text-transform: uppercase; margin-left: 4px; font-size: 0.9em; color: #993 !important; padding: 1px 4px; ">sponsor</span></p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85716/rss" title="www.arbazsiddiqui.me" style=" color: #3366aa; font-size: 1.05em;">Some Real World Use Cases for JS Proxies</a></span> — <a href="https://javascriptweekly.com/link/85717/rss" style=" color: #3366aa; ">Proxies</a> are far from a universally understood concept in the JavaScript world, so it might help to think about them in a context where you might use them.</p> <p>Arbaz Siddiqui </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85718/rss" title="davidwalsh.name" style=" color: #3366aa; font-size: 1.05em;">How to Cancel a Fetch Request</a></span> — This looks at the new AbortController API which can help with one of the shortcomings of promises: That you can’t cancel a fetch request.</p> <p>David Walsh </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85719/rss" title="techblog.commercetools.com" style=" color: #3366aa; font-size: 1.05em;">Five Practical Tips When Using React Hooks in Production</a></span></p> <p>Tobias Deekens </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85702/rss" title="buildkite.com" style=" color: #3366aa; font-size: 1.05em;">Faster CI/CD for All Your Software Projects Using Buildkite</a></span></p> <p>Buildkite <span style="text-transform: uppercase; margin-left: 4px; font-size: 0.9em; color: #993 !important; padding: 1px 4px; ">sponsor</span></p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85720/rss" title="blog.logrocket.com" style=" color: #3366aa; font-size: 1.05em;">Using Watchers for Form Input Validation in Vue.js</a></span> — The watch option in Vue.js offers a way to respond to data changes in a given element and perform form input validation.</p> <p>Nwose Lotanna </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0;"><p>🔧 Code &amp; Tools</p></td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85721/rss" title="uppload.js.org" style=" color: #3366aa; font-size: 1.05em;">Uppload: A 'Better' JavaScript Image Uploader</a></span> — Open source, highly customizable with 30+ plugins and can be used with any file uploading backend.</p> <p>El Niño </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85722/rss" title="github.com" style=" color: #3366aa; font-size: 1.05em;">Heapify: The 'Fastest JavaScript Priority Queue Out There'</a></span> — It’s a bold claim, but there are some benchmarks, plus no dependencies and it’s well explained and documented too.</p> <p>Lucio Paiva </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85723/rss" title="www.truework.com" style=" color: #3366aa; font-size: 1.05em;">Introducing Gretchen: Making <code>fetch</code> Happen in TypeScript</a></span> — An introduction to <a href="https://javascriptweekly.com/link/85724/rss" style=" color: #3366aa; ">Gretchen</a>, a modern, TypeScript-focused Fetch API abstraction.</p> <p>Eric Bailey </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85700/rss" title="getstream.io" style=" color: #3366aa; font-size: 1.05em;">Stream Chat API &amp; JavaScript SDK for Custom Chat Apps</a></span> — Build real-time chat in less time. Rapidly ship in-app messaging with our highly reliable chat infrastructure.</p> <p>Stream <span style="text-transform: uppercase; margin-left: 4px; font-size: 0.9em; color: #993 !important; padding: 1px 4px; ">sponsor</span></p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85733/rss" title="atomiks.github.io" style=" color: #3366aa; font-size: 1.05em;">Tippy.js 6.1: Highly Customizable Tooltip and Popover Library</a></span> — Accessible, easy to theme, fast on low-end devices, and TypeScript ready. Also a great example of a good project site/homepage. <a href="https://javascriptweekly.com/link/85734/rss" style=" color: #3366aa; ">GitHub repo.</a></p> <p>atomiks </p> </td></tr></table> <table border=0 border=0><tr><td style="font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; padding: 0px 15px;"> <p><span style="font-weight: 600; font-size: 1.1em; color: #000;"><a href="https://javascriptweekly.com/link/85725/rss" title="github.com" style=" color: #3366aa; font-size: 1.05em;">Seafox: A Fast Spec-Compliant JavaScript Parser Written in Typescript</a></span> — Generates AST according to the <a href="https://javascriptweekly.com/link/85726/rss" style=" color: #3366aa; ">ESTree</a> AST format, and can be used to perform syntactic analysis of JavaScript code.</p> <p>Kenny Flash </p> </td></tr></table> <table border=0 border=0><tr><td style=" font-family: -apple-system,BlinkMacSystemFont,Helvetica,sans-serif; font-size: 15px; line-height: 1.55em; "></td></tr></table> </div> </td></tr> </table> <img src="https://javascriptweekly.com/open/480/rss" width="1" height="1" />
`
const TEXTNODE = 'TEXTNODE';
const COMMENTNODE = 'COMMENTNODE';
const NODESTART = 'NODESTART';
const NODEEND = 'NODEEND';
const NODECLOSESELF = 'NODECLOSESELF';
const COMMENTSTART = 'COMMENTSTART';
const COMMENTEND = 'COMMENTEND';
function removeAllSpace(str) {
return str.replace(/\s*/g, '');
}
function removeMultiSpace(str) {
return str.replace(/\s{2,}/g, " ");
}
function removeEqualSpace(str) {
return str.replace(/\s*\=\s*/g, '=');
}
function isText(obj) {
return obj && obj.type == TEXTNODE;
}
const WxDomParser = (function () {
function WxDomParser() {
this.nodeRegex = /(<(\w+)\s*([\s\S]*?)(\/){0,1}>)|<\/(\w+)>|(\{:{0,1}\w+?\})|(<!--)|(-->)/g;
this.attrRegex = /[\w\-]+=['"][\s\S]*?['"]/g;
}
WxDomParser.prototype.parseStart = function (htmlStr, optionRegex) {
if (optionRegex === void 0) { optionRegex = this.nodeRegex; }
var matchResult = this.findAllNodes(htmlStr, optionRegex);
return this.makeWxTree(matchResult);
};
WxDomParser.prototype.findAllNodes = function (htmlStr, optionRegex) {
if (optionRegex === void 0) { optionRegex = this.nodeRegex; }
var result;
var allMatches = [], nextIndex = 0;
while (result = optionRegex.exec(htmlStr)) {
var match = result[0], startTag = result[1], startTagName = result[2], attr = result[3], endSelf = result[4], endTagName = result[5], exp = result[6], startComment = result[7], endComment = result[8];
var index = result.index, length_1 = match.length;
if (index > nextIndex) {
allMatches.push({
type: TEXTNODE,
value: htmlStr.slice(nextIndex, index)
});
}
if (exp) {
allMatches.push({
type: TEXTNODE,
value: exp
});
}
nextIndex = index + length_1;
var type = void 0;
if (startTagName) {
type = NODESTART;
}
else if (endTagName) {
type = NODEEND;
}
else if (startComment) {
type = COMMENTSTART;
}
else if (endComment) {
type = COMMENTEND;
}
else {
type = NODECLOSESELF;
}
allMatches.push({
type: type, match: match, attr: attr, startTag: startTag, startTagName: startTagName, endSelf: endSelf, endTagName: endTagName, startComment: startComment, endComment: endComment, index: index, length: length_1
});
}
return allMatches;
};
WxDomParser.prototype.makeWxTree = function (results) {
var openTreeList = [{ nodeName: 'ROOT', attr: [], children: [] }];
for (var i = 0; i < results.length; i++) {
this.make(results[i], results[i - 1], results[i + 1], openTreeList);
}
return openTreeList[0];
};
WxDomParser.prototype.make = function (result, last, next, openTreeList) {
var tree = openTreeList[openTreeList.length - 1];
if (isText(result)) {
if (!isText(last) && !isText(next)) {
if (removeAllSpace(result.value) !== '') {
tree.children.push({ nodeName: TEXTNODE, attr: [], children: [result.value] });
}
}
else {
tree.children.push({ nodeName: TEXTNODE, attr: [], children: [result.value] });
}
}
else {
if (result.endTagName || result.endComment) {
openTreeList.pop();
}
else {
var nodeName = result.startTagName, startComment = result.startComment;
if (result.endSelf) {
tree.children.push({ nodeName: nodeName, attr: this.getAttributes(result.attr), children: [] });
}
else {
if (nodeName) {
var newOpenTree = { nodeName: nodeName, attr: this.getAttributes(result.attr), children: [] };
tree.children.push(newOpenTree);
openTreeList.push(newOpenTree);
}
if (startComment) {
var newOpenTree = { nodeName: COMMENTNODE, attr: [], children: [] };
tree.children.push(newOpenTree);
openTreeList.push(newOpenTree);
}
}
}
}
};
WxDomParser.prototype.getAttributes = function (attr) {
var slimAttr = removeMultiSpace(removeEqualSpace(attr));
var attrArray = [];
var attrExpression;
while (attrExpression = this.attrRegex.exec(attr)) {
var p = attrExpression[0].split('=');
attrArray.push({
name: p[0],
value: p[1].replace(/["']/g, '')
});
}
return attrArray;
};
return WxDomParser;
}());
const parse = new WxDomParser()
const content = parse.parseStart(html)
console.log(content)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/sternelee/mapp-coder-weekly.git
[email protected]:sternelee/mapp-coder-weekly.git
sternelee
mapp-coder-weekly
mapp-coder-weekly
master

搜索帮助