Add support for rounding to end of sentence #22
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Use:
Also includes initial tests (all passing) (could do with more?)
If options.round is used, then as the text is parsed, if it hits the character limit, it also checks to see if it's at the edge of a closing sentence tag . If not, it'll continue to scoop up the text.
If the parser reaches a
PARSER_TAG_COMMENCED
character (<
), then it peeks at the upcoming HTML, and checks if that tag would suggest the end of a sentence, i.e. a</p>
,</div>
,</li>
, etc.Note: I also tested that it works correctly with unclosed
<p>
tags, which it does, but the current version of Downsize tries to close all tracked open tags (so if there's more than one automatic closing<p>
tag), they're all slapped on the end of the string, resulting in:<p>foo<p>bar</p></p>
- this is a completely separate bug which may or may not be worth dealing with.