Skip to content

Add text fragments to quarto-search.js items - #14003

Merged
cderv merged 1 commit into
mainfrom
feature/quarto-search-js-text-fragments
Feb 11, 2026
Merged

cderv merged 1 commit into
mainfrom
feature/quarto-search-js-text-fragments

Conversation

@vezwork

@vezwork vezwork commented Feb 6, 2026 •

Copy link
Copy Markdown
Member

Description

Adds text fragments to items in search. Example video:

Kapture.2026-02-06.at.12.51.59.mp4

I have attempted to write this code quite defensively so that it will not break things. Its not quite the ideal place for this code since this piece of code can be called multiple time for a single item, but it gets the job done.

Text fragments are well supported and apparently browsers will fall back to id linking if the text fragment is not supported or found (worked in my testing in chrome and safari and firefox on Desktop MacOS Tahoe, e.g. https://en.wikipedia.org/wiki/Dog#Domestication:~:text=blablabla).

@posit-snyk-bot

posit-snyk-bot commented Feb 6, 2026 •

Copy link
Copy Markdown
Collaborator

✅ Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
✅ Open Source Security 0 0 0 0 0 issues
✅ Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@vezwork
vezwork requested review from cderv and cscheid February 6, 2026 18:34
@cscheid

cscheid commented Feb 9, 2026

Copy link
Copy Markdown
Member

The PR looks good. Just to be clear, this exists in part to improve the situation we have wrt visibility of search results in the page, right?

@cscheid cscheid self-assigned this Feb 9, 2026
@vezwork

vezwork commented Feb 10, 2026 •

Copy link
Copy Markdown
Member Author

Just to be clear, this exists in part to improve the situation we have wrt visibility of search results in the page, right?

Yes, this will be helpful for all search results, but will be especially helpful once we have tabsets that have behaviour that they switch tabs to reveal specific content in response to browser ctrl+f or text fragment links. I am looking into using the <details> element to create a tabset that supports this. It should work based on my testing across desktop browsers.

@vezwork

vezwork commented Feb 10, 2026 •

Copy link
Copy Markdown
Member Author

Should we merge this? Whats the next release it will be in? Will it be in a "daily" sort of build before the main release so that we can use it in a build of the quarto.org docs?

@cderv
cderv merged commit 7a76706 into main Feb 11, 2026
49 checks passed
@cderv
cderv deleted the feature/quarto-search-js-text-fragments branch February 11, 2026 11:08
cderv added a commit that referenced this pull request Feb 11, 2026
@cderv

cderv commented Feb 11, 2026

Copy link
Copy Markdown
Member

Will it be in a "daily" sort of build before the main release so that we can use it in a build of the quarto.org docs?

Yes I'll build the new prerelease, and we can see effect in quarto.org

@cderv cderv added this to the v1.9 milestone Feb 11, 2026
@cderv

cderv commented Feb 11, 2026

Copy link
Copy Markdown
Member

1.9.20 has the change

@mcanouil

mcanouil commented Feb 11, 2026 •

Copy link
Copy Markdown
Collaborator

@vezwork

Probably worth taking a look at this discussion as it's about text fragments and query parameters in URL.

Especially, the following part which is involving in removing the search text highlighting

  • // function to clear highlighting on the page when the search query changes
    // (e.g. if the user edits the query or clears it)
    let highlighting = true;
    const resetHighlighting = (searchTerm) => {
    if (mainEl && highlighting && query && searchTerm !== query) {
    clearHighlight(query, mainEl);
    highlighting = false;
    }
    };

@cderv

cderv commented Feb 18, 2026

Copy link
Copy Markdown
Member

Follow-up note from investigating #14047: text fragments work well on Algolia-powered sites where ?q= is not in search result URLs. On sites using built-in fuse.js search, the highlight() function's DOM mutation (wrapping matches in <mark> tags) destroys the browser's text fragment highlight before the user sees it. This is because ?q= is only added by fuseSearch() (~line 1299), triggering the highlight()/replaceState() code path. As @mcanouil noted in #13123, replaceState() also strips :~:text=, but testing shows the DOM mutation alone is sufficient to destroy the text fragment even with replaceState() blocked.

Both mechanisms serve different purposes (<mark> highlights all matches, :~:text= highlights one and scrolls to it — see #13123 discussion), so making them coexist on fuse.js sites would be valuable. Related: #14047.

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.

5 participants