Build clean text message only once
This commit is contained in:
parent
162b801839
commit
d19c00faab
@ -24,10 +24,7 @@ function sortParts(a, b) {
|
|||||||
// different styles, the first resulting part will contain fragments "fo" and
|
// different styles, the first resulting part will contain fragments "fo" and
|
||||||
// "o", and the second resulting part will contain "b" and "ar". "o" and "b"
|
// "o", and the second resulting part will contain "b" and "ar". "o" and "b"
|
||||||
// fragments will contain duplicate styling attributes.
|
// fragments will contain duplicate styling attributes.
|
||||||
function merge(textParts, styleFragments) {
|
function merge(textParts, styleFragments, cleanText) {
|
||||||
// Re-build the overall text (without control codes) from the style fragments
|
|
||||||
const cleanText = styleFragments.reduce((acc, frag) => acc + frag.text, "");
|
|
||||||
|
|
||||||
// Every section of the original text that has not been captured in a "part"
|
// Every section of the original text that has not been captured in a "part"
|
||||||
// is filled with "text" parts, dummy objects with start/end but no extra
|
// is filled with "text" parts, dummy objects with start/end but no extra
|
||||||
// metadata.
|
// metadata.
|
||||||
|
@ -91,7 +91,7 @@ module.exports = function parse(text, users) {
|
|||||||
|
|
||||||
// Merge the styling information with the channels / URLs / nicks / text objects and
|
// Merge the styling information with the channels / URLs / nicks / text objects and
|
||||||
// generate HTML strings with the resulting fragments
|
// generate HTML strings with the resulting fragments
|
||||||
return merge(parts, styleFragments).map((textPart) => {
|
return merge(parts, styleFragments, cleanText).map((textPart) => {
|
||||||
// Create HTML strings with styling information
|
// Create HTML strings with styling information
|
||||||
const fragments = textPart.fragments.map(createFragment).join("");
|
const fragments = textPart.fragments.map(createFragment).join("");
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ describe("merge", () => {
|
|||||||
}],
|
}],
|
||||||
}];
|
}];
|
||||||
|
|
||||||
const actual = merge(textParts, styleFragments);
|
const actual = merge(textParts, styleFragments, styleFragments.map((fragment) => fragment.text).join(""));
|
||||||
|
|
||||||
expect(actual).to.deep.equal(expected);
|
expect(actual).to.deep.equal(expected);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user