Skip to content

Commit

Permalink
Better word separation
Browse files Browse the repository at this point in the history
Words joined by carriage returns (\n), as well as words that are
separated by punctuation (.,!;:) are now separated properly.

This also appropriately handles American style punctuation (e.g. it
separates 'He said "Hello, there!"' as ['He', 'said', '"Hello,' 'there!"'])
  • Loading branch information
clarkf committed Mar 12, 2014
1 parent 6314d4e commit 455c1c7
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion bm/squirt.js
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ sq.host = window.location.search.match('sq-dev') ?
return function textToNodes(text) {
text = "3\n 2\n 1\n " + text.trim('\n').replace(/\s+\n/g,'\n');
return text
.split(' ')
.replace(/[\,\.\!\:\;](?![\"\'\)\]\}])/g, "$& ")
.split(/[\s]+/g)
.filter(function(word){ return word.length; })
.map(wordToNode);
};
Expand Down

0 comments on commit 455c1c7

Please sign in to comment.