Jump to content

sanitizer truncate inserts === as breaks


Klenkes
 Share

Recommended Posts

In my current project I wanted to use the sanitizer->truncate method instead of my own functions, because PWs has more features.

But now I notice that al lot of ============= are inserted in the output and I couldn't explain why, at first... But now it seems that PW replaces some HTML tags like headings and paragraphs with equal signs, which looks like that:

truncated-text.PNG.29e45829e694608e820cf57043093305.PNG

The corresponding code:

$text = wire('sanitizer')->truncate($item->body, $maxLength=200);

This would be a heading-2: Keyword boards and planks:
and the following text just a paragraph, nothing fancy.

It can get even weirder:

truncated-text-2.PNG.7a46dc4c3ed05bba564f82bc79d0d112.PNG

Is there a non-documented option switch? Or even a bug?
As always grateful for any help.

PW: 3.0.143
Didn't happen in PW 3.0.123

Link to comment
Share on other sites

Just noticed that the amount of = is equal(pun intended) to the amount of characters in the heading before.
This can't be right.

Quote

Promotion of the reuse of historical building materials
=======================================================

Keyword lumber:
===============

 

Link to comment
Share on other sites

Good catch... but unfortunately no, it didn't change anything, but it should have!

I don't think the function markupToText is called, because I tried:

$text = wire('sanitizer')->truncate($item->body, 200, array('underlineHeadlines' => false, 'uppercaseHeadlines' => true));

and other options and nothing changed.

EDIT:
If I temporarily change the function markupToText in WireTextTools.php and set 'underlineHeadlines' => false, output is okay! But I don't want to edit a core file.

Link to comment
Share on other sites

Would this work?

$options = array('keepTags' => array('h2'), 'underlineHeadlines' => false, 'stripTags' => false);
d ($sanitizer->truncate("<h2>header</h2><p>test1 test2 test3</p>", 30, $options));
"<h2>header</h2>test1 test2…" (29)
Link to comment
Share on other sites

11 hours ago, Lutz said:

As a fast workaround you could try to use $sanitizer->textarea() instead, https://processwire.com/api/ref/sanitizer/textarea/ (maxLength to 200, stripTags defaults to true). 

Thanks. sanitizer->textarea would be an option, (but it is without mercy when it comes to cut off words)

11 hours ago, Lutz said:

There's another thread regarding this issue,

This forum thread didn't continue and no bug report was made.
I will.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...