-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from hadynz/hierarchy-tags
Hierarchical tags are never highlighted
- Loading branch information
Showing
5 changed files
with
92 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { redactText } from './search.utils'; | ||
|
||
describe('redactText', () => { | ||
it('Hashtags are redacted', () => { | ||
const sentence = 'I love playing #football'; | ||
const expected = 'I love playing '; | ||
|
||
const actual = redactText(sentence); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('Hierarchial hashtags are redacted', () => { | ||
const sentence = 'I love playing #sport/football'; | ||
const expected = 'I love playing '; | ||
|
||
const actual = redactText(sentence); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('Links are redacted', () => { | ||
const sentence = 'I love [[sleeping]] and [[https://aoe.com|gaming]]'; | ||
const expected = 'I love and '; | ||
|
||
const actual = redactText(sentence); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('Code blocks are redacted', () => { | ||
const sentence = '```cs\ | ||
code block\ | ||
```'; | ||
const expected = ' \ | ||
\ | ||
'; | ||
|
||
const actual = redactText(sentence); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('Frontmatter is redacted', () => { | ||
const sentence = '---\ | ||
tags: [aoe, aoe2]\ | ||
---\ | ||
# Heading 1\ | ||
```'; | ||
const expected = ' \ | ||
\ | ||
\ | ||
# Heading 1\ | ||
```'; | ||
|
||
const actual = redactText(sentence); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
|
||
it('Frontmatter with preceding empty lines is redacted', () => { | ||
const sentence = '\ | ||
\ | ||
---\ | ||
tags: [aoe, aoe2]\ | ||
---\ | ||
# Heading 1\ | ||
```'; | ||
const expected = '\ | ||
\ | ||
\ | ||
\ | ||
\ | ||
# Heading 1\ | ||
```'; | ||
|
||
const actual = redactText(sentence); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export const redactText = (text: string): string => { | ||
return text | ||
.replace(/```[\s\S]+?```/g, (m) => ' '.repeat(m.length)) // remove code blocks | ||
.replace(/^\n*?---[\s\S]+?---/g, (m) => ' '.repeat(m.length)) // remove yaml front matter | ||
.replace(/#+([a-zA-Z0-9_/]+)/g, (m) => ' '.repeat(m.length)) // remove hashtags | ||
.replace(/\[(.*?)\]+/g, (m) => ' '.repeat(m.length)); // remove links | ||
}; |