Created
July 31, 2019 21:17
-
-
Save sineemore/114435fc32f5194ac0db55126d8b4d79 to your computer and use it in GitHub Desktop.
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
class NodeMarkup { | |
// class... | |
spanWord({start, end}) { | |
const space = /\s/ | |
const word = /[^\s]/ | |
while (start < this.text.length - 1 && space.test(this.text[start])) | |
start++ | |
while (start > 0 && word.test(this.text[start - 1])) | |
start-- | |
while (end > 0 && space.test(this.text[end])) | |
end-- | |
while (end < this.text.length - 1 && word.test(this.text[end])) | |
end++ | |
if (start >= end) { | |
return false | |
return {start, end} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment