-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<script> tag contents are not ignored #98
Comments
My clunky workaround for this problem was to parse the input as html using a div tag, replace the contents of the script tags with a token before passing them through anchorme, and then restore them afterwards. There's probably a better way, but this works. // use a div element to parse the html
const parser = document.createElement('div');
parser.innerHTML = input;
const originalScripts = [];
// find all script tags in the html
let scriptTags = parser.getElementsByTagName('script');
for (var i = 0; i < scriptTags.length; i++) {
// store the script contents for later
originalScripts.push(scriptTags[i].innerText);
// replace script contents with a temporary token
scriptTags[i].innerText = `{{script-${i}}}`;
}
// convert anchors
var convertedHtml = anchorme(parser.innerHTML);
// restore script tag contents by replacing tokens with original value
for (var i = 0; i < originalScripts.length; i++) {
convertedHtml = convertedHtml.replace(`{{script-${i}}}`, originalScripts[i]);
}
return convertedHtml; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results in the following html
The text was updated successfully, but these errors were encountered: