All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.
Accidental version bump during migration to sourcehut. Sorry about that.
opts.stripTogetherWithTheirContents
(d2031ab)filteredTagLocations
for pair tags which are stripped with content (6bd6f4c)Why change what's returned, upon user's request, when we can return everything and let the user pick?
That's why we removed opts.returnRangesOnly
.
Function's output is a plain object now, containing:
opts.ignoreTags
and opts.onlyStripTags
)opts.ignoreTags
and opts.onlyStripTags
)opts.ignoreTags
and opts.onlyStripTags
opts.ignoreTags
and opts.onlyStripTags
)stripHtml("abc<a>click me</a>def");
// => {
// log: {
// timeTakenInMilliseconds: 6
// },
// result: "abc click me def",
// ranges: [
// [3, 6, " "],
// [14, 18, " "],
// ],
// allTagLocations: [
// [3, 6],
// [14, 18],
// ],
// filteredTagLocations: [
// [3, 6],
// [14, 18],
// ],
// }
allTagLocations
can be used for syntax highlighting, for example.
Migration instructions:
Previously, function on defaults returned result string. Now it's under result
key, in output plain object.
Previously, you could request ranges output via opts.returnRangesOnly
. Now ranges are always present under key ranges
.
Some people mistakenly took ranges output for exact tag locations. Now exact tag locations are under allTagLocations
key.
That's different from ranges output, because ranges are instructions: what to add, what to replace and can be merged and their character indexes covered will include whitespace management.
allTagLocations
, on other hand, are exact tag locations. If you slice them using String.slice()
you'll get string from bracket-to-bracket like <a>
.
opts.dumpLinkHrefsNearby
and algorithm improvements (777407e)opts.onlyStripTags
(7bb49c8)opts.trimOnlySpaces
(b8c6f29)opts.returnRangesOnly
- when there are no HTML tags in the input and the option is on, an empty array is returned (as opposed to the input string, incorrectly returned previously). Sorry about that.opts.onlyStripTags
Breaking changes: opts.dumpLinkHrefsNearby
was previously Boolean. Now it's a plain object and its key enabled
(opts.dumpLinkHrefsNearby.enabled
) does the same thing that opts.dumpLinkHrefsNearby
did before v3
.
This makes it easier for us to contain all new opts.dumpLinkHrefsNearby
settings in one place:
{
ignoreTags: [],
stripTogetherWithTheirContents: stripTogetherWithTheirContentsDefaults,
skipHtmlDecoding: false,
returnRangesOnly: false,
trimOnlySpaces: false,
dumpLinkHrefsNearby: { // <------ CHANGED!
enabled: false, // <-------- 💥 NEW!
putOnNewLine: false, // <--- 💥 NEW!
wrapHeads: "", // <--------- 💥 NEW!
wrapTails: "" // <---------- 💥 NEW!
}
}
range-
dependencies have been renamed, namely ranges-push and ranges-apply. We tapped them.opts.dumpLinkHrefsNearby
- handy when producing Email Text versions64 unit tests, 451 assertions, 2226 lines of unit tests at 90% line coverage.
✨ opts.trimOnlySpaces
- up until now, by default, the outsides of the string was trimmed using String.trim()
which erased:
will also be erased)\n
), carriage returns (\r
) and combination thereof (\r\n
)This becomes a challenge in automated environments where data is considered to be clean and multiple datum can be parts of another. For example, we might be cleaning JSON fields where value is "sandwitched" out of three fields: "Hi ", "%%-firstname-%%", ", welcome to special club!". To improve formatting, some outer spaces like after "Hi" can be replaced with a non-breaking space. This way, words would never wrap there. However, if all fields were cleaned by a tool which used this HTML stripping function, outer non-breaking spaces would get deleted and result would end up: "HiJohn, welcome to special club!". This option makes trimming more strict - only spaces deleted during string trimming.
One day I noticed that my Nunjucks code (just a greater-than comparison against a number) gets falsely interpreted as HTML by this library and went on to rewrite the whole thing from scratch. Now it's leaner, cleaner and with the same and double extra more unit tests.
v.66
can't do that.opts.returnRangesOnly
package.lock
and .editorconfig
console.log
s in the source code — Rollup will remove from production code.opts.stripTogetherWithTheirContents
and done a lot of rebasing.opts.stripTogetherWithTheirContents