Klenkes Posted October 29, 2019 Share Posted October 29, 2019 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: 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: 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 More sharing options...
Klenkes Posted October 29, 2019 Author Share Posted October 29, 2019 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 More sharing options...
matjazp Posted October 29, 2019 Share Posted October 29, 2019 Try (untested): $text = wire('sanitizer')->truncate($item->body, 200, array('underlineHeadlines' => false)); 1 Link to comment Share on other sites More sharing options...
Klenkes Posted October 29, 2019 Author Share Posted October 29, 2019 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 More sharing options...
matjazp Posted October 29, 2019 Share Posted October 29, 2019 Yeah, your' right, it calls collapse() that in turn calls markupToText() but with own options. Would it help if you try keepTags/keepFormatTags option? Link to comment Share on other sites More sharing options...
Klenkes Posted October 29, 2019 Author Share Posted October 29, 2019 16 minutes ago, matjazp said: ... Would it help if you try keepTags/keepFormatTags option? No. No parameter is respected. Link to comment Share on other sites More sharing options...
Lutz Posted October 29, 2019 Share Posted October 29, 2019 There's another thread regarding this issue, 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). Or use this simple function: Link to comment Share on other sites More sharing options...
matjazp Posted October 30, 2019 Share Posted October 30, 2019 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 More sharing options...
Klenkes Posted October 30, 2019 Author Share Posted October 30, 2019 Yes, this would work. Everything works as it should and respects all parameters. But what does that mean? Link to comment Share on other sites More sharing options...
Klenkes Posted October 30, 2019 Author Share Posted October 30, 2019 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. 1 Link to comment Share on other sites More sharing options...
Klenkes Posted October 30, 2019 Author Share Posted October 30, 2019 Bug report filed here:https://github.com/processwire/processwire-issues/issues/1015 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now