Closed outline4 closed 4 years ago
Ok, I've found a way around this problem: {{ text|replace({'</p>': '</p> '})|chop(limit=40, unit='w', append="…") }}
. But it would be nice if chopper could do this itself...
Stefan — Thanks for pointing this out.
Unfortunately, I think it'd be tricky to implement your remedy in a consistent way. For example, we would only consider adding whitespace between consecutive block elements; it would be incorrect to add extra space around inline elements. So now chop
needs to know/care about different HTML tags? (Seems kind of outside the scope of that method.) And, which whitespace character(s) would the user prefer? A space? A line break?
So, probably chop
is not the right place for this feature. I like to keep the mandate of individual methods as tight as possible.
...
However... Maybe we could add a asPlainText
method, to extract plain text from HTML, which could normalize whitespace around block elements... And then methods like chop
could lean on that asPlainText
functionality when a user wants to operate on plain text from an HTML passage.
Perhaps somebody would like to think through the params/implementation of such a method and strike up a FR/PR for it... 😇
If there is more then one paragraph, it should add a space after each paragraph
With this:
the output is the following:
You see, there should be a space after seashore and sure. etc.
If you separate the paragraphs like you did in your example, everything works fine:
Is this a bug?
Is there a way around it?
Cheers
Stefan