-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Title finder not working correctly #576
Comments
@1cg any suggestions on approaches to fixing this? The current logic is overly simple and won’t work, but getting into regexp patterns can lead to complex code. Right now I don’t see any other way though. |
I agree, and I don't think this would be too bad.
or something like that. Are you willing to take a crack at it? |
Well here's my crack at implementing your version with a regexp. function findTitle(content) {
var contentWithSvgsRemoved = content.replace('/<svg[^>]*>[\s\S]*?<\/svg>/gim', '');
var result = contentWithSvgsRemoved.match('/<title[^>]*>([\s\S]*?)<\/title>/im');
if (result) {
return result[1];
}
} |
Feels quite hacky, still looks for an exact match of <svg id=""><title>Image title</title></svg>
<title id="">New title</title> I dislike the idea of matching against |
Ok, so this version does rule out function findTitle(content) {
var contentWithSvgsRemoved = content.replace(/<svg(\s[^>]*>|>)([\s\S]*?)<\/svg>/gim, '');
var result = contentWithSvgsRemoved.match(/<title(\s[^>]*>|>)([\s\S]*?)<\/title>/im);
if (result) {
return result[2];
}
} |
Good points. I'm good w/ this, if you want to make the change. |
Yup, I'll write a test and implement, thanks for taking a look. |
Tests verified and I've created a Thank you @bencroker! |
The title finder, as well as the check for SVG tags, require tags that are closed immediately. Tags that have attributes are not being detected, the regexp and the
indexOf
functions need tweaking.htmx/src/htmx.js
Lines 708 to 718 in 0aa372d
The text was updated successfully, but these errors were encountered: