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

Default anchorPattern selects too many links when URI contains (fn|footnote|note) #1824

Open
kevin1 opened this issue Jan 21, 2024 · 3 comments
Assignees
Labels

Comments

@kevin1
Copy link
Contributor

kevin1 commented Jan 21, 2024

The default anchorPattern is /(fn|footnote|note)[:\-_\d]/gi. This could select too many links when the URI of the page contains the strings fn, footnote, or note.

For example, a page containing the following element is served at https://footnote.example.com/:

<a href="#">go to top</a>

Then in the following code, pattern will match because link.href is https://footnote.example.com/#

return queryAll<HTMLAnchorElement>(document, scope + ' a[href*="#"]').filter(
(link) => (link.href + link.rel).match(pattern),
)

I believe this can be fixed by setting the default anchorPattern to /#(fn|footnote|note)[:\-_\d]/gi

@goblindegook goblindegook self-assigned this Feb 1, 2024
@goblindegook
Copy link
Owner

The setup still tries to match the URL fragment with an existing footnote at the bottom at the document, though. So while it is less efficient because it picks too many link candidates, I suspect it will not lead to incorrect footnotes being created. But I could be wrong... do you have a counter example?

@kevin1
Copy link
Contributor Author

kevin1 commented Feb 7, 2024

Hey @goblindegook - sorry I should be more clear, it causes the footnote matching to fail entirely so none of the footnotes are converted by littlefoot. The document remains unmodified. The footnote matching code emits the following error:

[Error] SyntaxError: '#' is not a valid selector.
	querySelectorAll (littlefoot.min.js:2:4794)
	C (littlefoot.min.js:2:4794)
	(anonymous function) (littlefoot.min.js:2:6602)
	map
	B (littlefoot.min.js:2:6525)
	tt (littlefoot.min.js:2:9786)
	(anonymous function) (index:51)

because findReference would parse the href https://footnote.example.com/# into a query of simply #

const fragment = link.href.split('#')[1]!
const related = queryAll<E>(
document,
'#' + window.CSS.escape(fragment),

@goblindegook
Copy link
Owner

Thank you, that's clear now. I'll work on a fix.

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

No branches or pull requests

2 participants