lagden / highlight

Make the words shine
https://www.npmjs.com/package/lagden-highlight
MIT License
1 stars 0 forks source link

Replacement gets confused with lots of small words #1

Closed wyze closed 7 years ago

wyze commented 7 years ago

Here is a contrived example of what I mean:

const source = 'A system for offer based restaurant reservations comprises a processor and a memory. The processor is configured to: receive a request for a reservation including a set of attributes such as a date or date range, a time range, a location, a cuisine, and a party size; determine a set of available reservations based on an actual table availability for the date, time, and the party size; determine one or more offers based on the date, time, and the party size; determine an overlapping subset between the set of available reservations and the one or more offers; and provide an indication of the overlapping subset. The memory is coupled to the processor and is configured to provide the processor with instructions.'
const q = 'are to a is in on the of at or an'
const highlighted = highlight(source, q)

This would produce the following and set to highlighted above:

the0 system for offer bthe1sed restthe1urant reservations comprises the1 processor and the1 memory. The processor is configured to: receive the1 request for the1 reservation including the1 set of attributes such the1s the1 date or date range, the1 time range, the1 location, the1 cuisine, and the1 pthe1rty size; determine the1 set of the1vthe1ilthe1ble reservations bthe1sed on an the1ctuthe1l tthe1ble the1vthe1ilthe1bility for the date, time, and the pthe1rty size; determine one or more offers bthe1sed on the date, time, and the pthe1rty size; determine an overlthe1pping subset between the set of the1vthe1ilthe1ble reservations and the one or more offers; and provide an indication of the overlthe1pping subset. The memory is coupled to the processor and is configured to provide the processor with instructions.

I ran into this in my project at work where a user could potentially paste in a large body of text that is split and then attempts to highlight. I do have a fix and will submit a PR shortly.

wyze commented 7 years ago

Sorry to bother, but after writing a test, it looks like it is some other processing of the results that I am doing that is causing the weird output.

lagden commented 7 years ago

I am working on it...

wyze commented 7 years ago

Well, I can't reproduce it in a test, but when ran within my project, even without my extra processing, it still produces the output described above.

I'll submit my PR anyways and you can take a look.