Skip to content
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

Support for XML namespace prefixes in DOM Element names / tagnames (XHTML, SVG, MathML), with proposed fix #78

Open
danielweck opened this issue Feb 19, 2024 · 1 comment

Comments

@danielweck
Copy link

danielweck commented Feb 19, 2024

finder/finder.ts

Lines 220 to 229 in feef199

function tagName(input: Element): Knot | null {
const name = input.tagName.toLowerCase()
if (config.tagName(name)) {
return {
name,
penalty: 2,
}
}
return null
}

My current workaround is:

{
name: name.replace(/^(.+:)(.+)$/, "*|$2"),
}

Examples:

  • m:math ==> *|math
  • svg:a ==> *|a
  • div ==> div

Unfortunately the wildcard * prefix is necessary because the querySelector() API does not support namespace prefixes, unlike CSS stylesheets:

https://developer.mozilla.org/en-US/docs/Web/SVG/Element/a

...consequently, for example *|a will match not only SVG link elements but also HTML hyperlinks! :(

https://www.w3.org/TR/selectors-api/#namespace-prefix-needs-to-be-resolved

@danielweck
Copy link
Author

Follow-up, I've added name._____.replace(/^\*\|(a|script|style)$/, "*|$1:not(|$1)") to exclude HTML elements with the same name as namespace-prefixed SVG element names (could be extended to other common names, and MathML too...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant