Last active
March 13, 2022 17:25
-
-
Save danielepolencic/67013b543f1938858aa68c41095b2156 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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’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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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’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