Skip to content

Commit f7af518

Browse files
authored
Merge pull request #9 from oramasearch/docs/readme
updates readme
2 parents 68175f3 + 893989c commit f7af518

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

README.md

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ bun i @orama/highlight
1414
# Usage
1515

1616
```js
17-
import { highlight } from '@orama/highlight'
17+
import { Highlight } from '@orama/highlight'
1818

1919
const inputString = 'The quick brown fox jumps over the lazy dog'
2020
const toHighlight = 'brown fox jump'
2121

22-
const highlighted = highlight(inputString, toHighlight)
22+
const highlighter = new Highlight()
23+
const highlighted = highlighter.highlight(inputString, toHighlight)
2324

2425
console.log(highlighted.positions)
25-
2626
// [
2727
// {
2828
// start: 10,
@@ -36,23 +36,17 @@ console.log(highlighted.positions)
3636
// }
3737
// ]
3838

39-
console.log(highlighted.toString())
40-
39+
console.log(highlighted.HTML)
4140
// "The quick <mark class="orama-highlight">brown</mark> <mark class="orama-highlight">fox</mark> <mark class="orama-highlight">jump</mark>s over the lazy dog"
42-
```
43-
44-
By default, `@orama/highlight` returns an object containing two properties:
4541

46-
- `toString`, a function that returns valid HTML code with highlighted substrings wrapped into a `<mark>` tag and a `orama-highlight` CSS class
47-
- `positions`an array of positions for all the highlighted substrings in the original input
42+
console.log(highlighted.trim(10))
43+
// "...uick <mark class="orama-highlight">brown</mark>..."
44+
```
4845

49-
You can always customize the library behavior by passing a third parameter with the following parameters:
46+
You can always customize the library behavior by passing some options to the class constructor:
5047

5148
```js
52-
const inputString = 'The quick brown fox jumps over the lazy dog'
53-
const toHighlight = 'brown fox jump'
54-
55-
const highlighted = highlight(inputString, toHighlight, {
49+
const highlighted = new Highlight({
5650
caseSensitive: true, // Only highlight words that respect the second parameter's casing. Default is false
5751
wholeWords: true, // Only highlight entire words, no prefixes
5852
HTMLTag: 'div', // Default is "mark"

0 commit comments

Comments
 (0)