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

Return top-level text alongside page anchors in fragments #369

Merged
merged 3 commits into from
Jul 28, 2023

Conversation

bglw
Copy link
Contributor

@bglw bglw commented Jul 27, 2023

This PR fills out the next iteration of support for #215 — namely returning the "text" parameter for anchors when returning a result. This is the last step before having Pagefind calculate the correct heading for you, which will come in another PR.

The way this text is extracted could be up for debate, but the chosen method seems sane. For anchors, Pagefind will use all text that is either a direct descendant of the element, or is within strictly inline elements.

For example:

<h2 id="my_id">This title with a <span>span<span>!</h2>

will result in a my_id anchor with the text This title with a span!.

However,

<div id="my_id">This div with a <div>nested div<div>!</div>

will result in a my_id anchor with the text This div with a!.

This is to prevent having something <body id="body"> result in an anchor containing the entire page again.

@bglw bglw merged commit c3216a8 into main Jul 28, 2023
4 checks passed
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

Successfully merging this pull request may close these issues.

1 participant