Skip to content

Max length to determine the resulting string #22

@synth

Description

@synth

We have noticed that Truncato does not truncate so the final string results in max length, but rather max length calculates on the original string. This means the final result is affected by the quality of the markup. This can be seen with two content blocks that are identical in content, but different in markup.

Truncato

str1 = "Hello, How is the weather"
str2 = "Hello, <div style=\"color: #green,background-color:#yellow;overflow:auto\">How is the weather"

[36] pry(main)> Truncato.truncate(str1, max_length: 22)
=> "Hello, How is the weat..."
[37] pry(main)> Truncato.truncate(str2, max_length: 22)
=> "Hello, <div style='color: #green,background-color:#yellow;overflow:auto'>...</div>"

For addititional reference, there is a js function that truncates and preserves markup and results in this behavior of resulting in a string of a desired content length (without markup).

truncation.js

str1 = "Hello, How is the weather"
str2 = "Hello, <div style=\"color: #green,background-color:#yellow;overflow:auto\">How is the weather"
truncate(str1, 22)
'Hello, How is the weat...'
truncate(str2, 22)
'Hello, <div style="color: #green,background-color:#yellow;overflow:auto">How is the weat...</div>'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions