mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 14:18:27 +01:00
Chng: Changed OPTIONS_PRESERVE_SPACES to OPTION_PRESERVE_SPACES (#4897)
This commit is contained in:
parent
68e64bf2a1
commit
4fefcfcbc5
@ -672,7 +672,17 @@ class RichTextShortTextConverterTest extends HumHubDbTestCase
|
||||
{
|
||||
$this->assertConversionResult(
|
||||
"Test\\\nBreak",
|
||||
"Test\nBreak", [RichTextToShortTextConverter::OPTIONS_PRESERVE_SPACES => true]);
|
||||
"Test\nBreak", [RichTextToShortTextConverter::OPTION_PRESERVE_SPACES => true]);
|
||||
}
|
||||
|
||||
public function testHardBreakWithPreserveAndNL2BROption()
|
||||
{
|
||||
$this->assertConversionResult(
|
||||
"Test\\\nBreak",
|
||||
"Test<br>\nBreak", [
|
||||
RichTextToShortTextConverter::OPTION_PRESERVE_SPACES => true,
|
||||
RichTextToShortTextConverter::OPTION_NL2BR => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function testHardBreakWithoutNewLine()
|
||||
@ -694,7 +704,7 @@ class RichTextShortTextConverterTest extends HumHubDbTestCase
|
||||
{
|
||||
$this->assertConversionResult(
|
||||
"This is <br> was a hard line break",
|
||||
"This is \n was a hard line break", [RichTextToShortTextConverter::OPTIONS_PRESERVE_SPACES => true]);
|
||||
"This is \n was a hard line break", [RichTextToShortTextConverter::OPTION_PRESERVE_SPACES => true]);
|
||||
}
|
||||
|
||||
public function testMultipleHtmlBreak()
|
||||
|
@ -17,7 +17,12 @@ class RichTextToShortTextConverter extends RichTextToPlainTextConverter
|
||||
* Option can be used to preserve spaces and new lines in the converter result (default false).
|
||||
* Note, this option will not affect cached results and therefore does not require a special cache key.
|
||||
*/
|
||||
public const OPTIONS_PRESERVE_SPACES = 'preserveNewlines';
|
||||
public const OPTION_PRESERVE_SPACES = 'preserveNewlines';
|
||||
|
||||
/**
|
||||
* Option can be used in combination with OPTIONS_PRESERVE_SPACES in order to allow breaks inside the short text
|
||||
*/
|
||||
public const OPTION_NL2BR = 'nl2br';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@ -104,12 +109,17 @@ class RichTextToShortTextConverter extends RichTextToPlainTextConverter
|
||||
{
|
||||
$result = $text;
|
||||
|
||||
if(!$this->getOption(static::OPTIONS_PRESERVE_SPACES, false)) {
|
||||
if(!$this->getOption(static::OPTION_PRESERVE_SPACES, false)) {
|
||||
$result = trim(preg_replace('/\s+/', ' ', $result));
|
||||
}
|
||||
|
||||
$result = parent::onAfterParse($result);
|
||||
$result = Html::encode($result);
|
||||
|
||||
return Html::encode($result);
|
||||
if($this->getOption(static::OPTION_NL2BR, false)) {
|
||||
$result = nl2br($result, false);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user