Skip to content

Instantly share code, notes, and snippets.

@danielepolencic
Last active March 13, 2022 17:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save danielepolencic/67013b543f1938858aa68c41095b2156 to your computer and use it in GitHub Desktop.
Save danielepolencic/67013b543f1938858aa68c41095b2156 to your computer and use it in GitHub Desktop.
<div></div><hr><h4>Page 2</h4><body class="logged-out env-production page-responsive"> <include-fragment class="js-notification-shelf-include-fragment"></include-fragment> <div class="application-main "> </div> <p id="ajax-error-message" class="ajax-error-message"> <svg class="octicon octicon-alert" width="16" height="16"><path/></svg> You can&#x2019;t perform that action at this time. </p> <p class="js-stale-session-flash"> <svg class="octicon octicon-alert" width="16" height="16"><path/></svg> <span class="js-stale-session-flash-signed-in">You signed in with another tab or window. <a href>Reload</a> to refresh your session.</span> <span class="js-stale-session-flash-signed-out">You signed out in another tab or window. <a href>Reload</a> to refresh your session.</span> </p> <template id="site-details-dialog"> <details class="details-reset details-overlay details-overlay-dark lh-default text-gray-dark hx_rsm"> <summary></summary> <details-dialog class="Box Box--overlay d-flex flex-column anim-fade-in fast hx_rsm-dialog hx_rsm-modal"> </details-dialog> </details>
</template> </body>
const hastParser = require('hast-util-raw')
const rawHtml = `<div></div><hr><h4>Page 2</h4><body class="logged-out env-production page-responsive"> <include-fragment class="js-notification-shelf-include-fragment"></include-fragment> <div class="application-main "> </div> <p id="ajax-error-message" class="ajax-error-message"> <svg class="octicon octicon-alert" width="16" height="16"><path/></svg> You can&#x2019;t perform that action at this time. </p> <p class="js-stale-session-flash"> <svg class="octicon octicon-alert" width="16" height="16"><path/></svg> <span class="js-stale-session-flash-signed-in">You signed in with another tab or window. <a href>Reload</a> to refresh your session.</span> <span class="js-stale-session-flash-signed-out">You signed out in another tab or window. <a href>Reload</a> to refresh your session.</span> </p> <template id="site-details-dialog"> <details class="details-reset details-overlay details-overlay-dark lh-default text-gray-dark hx_rsm"> <summary></summary> <details-dialog class="Box Box--overlay d-flex flex-column anim-fade-in fast hx_rsm-dialog hx_rsm-modal"> </details-dialog> </details></template> </body>`
function parseHtml(content) {
return hastParser({
type: 'root',
children: [
{ type: 'doctype', name: 'html' },
{ type: 'raw', value: content ?? '' },
],
})
}
console.log(parseHtml(rawHtml))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment