Skip to content

Commit ad9debf

Browse files
committed
Add punctuation signs as replacements of some html tags for texts that are going to appear in ticket lists
1 parent d8bee64 commit ad9debf

1 file changed

Lines changed: 30 additions & 3 deletions

File tree

src/Traits/Purifiable.php

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ trait Purifiable
1616
*/
1717
public function purifyHtml($rawHtml)
1818
{
19-
$a_html['content'] = trim(Purifier::clean($this->getReplaced($rawHtml), ['HTML.Allowed' => '']), chr(0xC2).chr(0xA0)." \t\n\r\0\x0B");
19+
$a_html['content'] = trim(Purifier::clean($this->getInlineReady($this->getReplaced($rawHtml)), ['HTML.Allowed' => '']), chr(0xC2).chr(0xA0)." \t\n\r\0\x0B");
2020
$a_html['html'] = trim(Purifier::clean($this->getReplaced($rawHtml), Setting::grab('purifier_config')), chr(0xC2).chr(0xA0)." \t\n\r\0\x0B");
2121

2222
return $a_html;
@@ -31,14 +31,41 @@ public function purifyHtml($rawHtml)
3131
*/
3232
public function purifyInterventionHtml($rawHtml)
3333
{
34-
$a_html['intervention'] = trim(Purifier::clean($this->getReplaced($rawHtml), ['HTML.Allowed' => '']), chr(0xC2).chr(0xA0)." \t\n\r\0\x0B");
34+
$a_html['intervention'] = trim(Purifier::clean($this->getInlineReady($this->getReplaced($rawHtml)), ['HTML.Allowed' => '']), chr(0xC2).chr(0xA0)." \t\n\r\0\x0B");
3535
$a_html['intervention_html'] = trim(Purifier::clean($this->getReplaced($rawHtml), Setting::grab('purifier_config')), chr(0xC2).chr(0xA0)." \t\n\r\0\x0B");
3636

3737
return $a_html;
3838
}
39-
39+
40+
/**
41+
* Replace HTML input using html_replacements setting
42+
*
43+
* @param string $html
44+
*
45+
* @return string
46+
*/
4047
public function getReplaced($html)
4148
{
4249
return str_replace(array_keys(Setting::grab('html_replacements')), array_values(Setting::grab('html_replacements')), $html);
4350
}
51+
52+
/**
53+
* Add some punctuation signs to let the text be inline readable (in ticket list)
54+
* @param string $html
55+
*
56+
* @return string
57+
*/
58+
public function getInlineReady($html)
59+
{
60+
$a_adds = [
61+
'</p><p>' => '</p> <p>',
62+
'<ul>' => ' ',
63+
'<ol>' => ' ',
64+
'</li><li>' =>'</li>, <li>',
65+
'</ul>' => '. ',
66+
'</ol>' => '. '
67+
];
68+
69+
return str_replace(array_keys($a_adds), array_values($a_adds), $html);
70+
}
4471
}

0 commit comments

Comments
 (0)