Comments (5)
Probably not at this time. What would be the use case? Could you give me an example?
from highlight-words.
It would be a UX feature of search:
- Backend searches through content of multiple pages using
highlight-words
- The highlighted text of each
SearchResult
is shown to a user, wrapped in a link - The link has a hash including the
textFragment
from theSearchResult
- clicking on the link scrolls to the unique location of the highlight in one of those pages
from highlight-words.
So on the back end, you're searching some content and getting back a list of matches/non-matches, wrapped in a link with the hash and the text fragment.
So why can't you use it as is now? You're already getting back a list of matches/non-matches. So you could forEach match and wrap it however you want. What am I missing?
from highlight-words.
getting back a list of matches/non-matches, wrapped in a link with the hash and the text fragment
Yes, to be clear, it's not the list itself that is wrapped in the link, it's each item in the list.
What am I missing?
Not entirely sure where the gaps are but I'll try to re-explain in more detail.
The Text Fragment (the thing after the #:~:text=
, as mentioned in the issue description above) is not yet generated - it needs to be generated somewhere. Generating a Text Fragment which is unique across the whole document can be done with code like this, but this code deals with selections on the page, which are not relevant in the backend.
Given that highlight-words
has the whole document already in memory and is already splitting it into chunks, it is potentially in a good position to create a unique Text Fragment so that a link can be created to this specific highlight.
As of now, the highlight-words
data passed back in the chunks offers a rudimentary way of creating a link (${previousChunk}-,${currentChunk},-${nextChunk}
), but this naive approach is not robust - one first case where they fail is when a phrase is repeated in the document.
from highlight-words.
Understood. I don't think personally this helps others in many ways to be honest. The argument could be made, if you already have the document, why not return some JSX, or a vue component, or a lit element. But that's not the purpose of this. We just split the content into chunks that are either a match or not a match. And the consumer can manipulate it afterwards as they please.
In my own use cases, I either count the matches (so I don't need extra work happening inside of the matcher for some transformation I won't use) or I apply some CSS on chunks conditionally (again, that work should not happen in the matcher).
I understand your use case. The uniqueness of the fragment will be problematic either in the library or outside of it, so I don't think that's an argument either - if the phrase is repeated in the document, it will be the same problem in the matching function as it will in your app.
Bottom line, I don't see a point for this right now. We can revisit later if need be.
from highlight-words.
Related Issues (12)
- Option Proposal: `maxLength` HOT 9
- Investigate potential performance issues HOT 3
- New Option: `clipByLength` HOT 5
- ESM Support HOT 14
- Regular expresion in query param? HOT 11
- Invalid query type HOT 2
- This work with IE browser? HOT 1
- Query words with double spaces HOT 4
- Option to ignore diacritics HOT 1
- Declaration file not found with `Node16` module + moduleResolution HOT 12
- highlight-words libray is giving Math.random vunerbility scan as high HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from highlight-words.