-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ignoreHtmlEntity option (#46)
- Loading branch information
Showing
10 changed files
with
137 additions
and
47 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
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,24 @@ | ||
import { extractMatchRangeList } from './utils'; | ||
|
||
const HTML_ENTITY_REGEX = /(&[\w#]+;)/g; | ||
|
||
export const useCheckIsHtmlEntity = (text: string) => { | ||
const htmlEntityMatchList = text.matchAll(HTML_ENTITY_REGEX); | ||
const htmlEntityRangeList = extractMatchRangeList(htmlEntityMatchList); | ||
const reversedHtmlEntityRangeList = htmlEntityRangeList.reverse(); | ||
|
||
return (match: RegExpMatchArray) => { | ||
const startIndex = match.index!; | ||
const entityRange = reversedHtmlEntityRangeList.find( | ||
([rangeStart]) => startIndex > rangeStart, | ||
); | ||
|
||
if (!entityRange) { | ||
return false; | ||
} | ||
|
||
const [, rangeEnd] = entityRange; | ||
const isInclude = startIndex < rangeEnd; | ||
return isInclude; | ||
}; | ||
}; |
Oops, something went wrong.