Chng: Changed OPTIONS_PRESERVE_SPACES to OPTION_PRESERVE_SPACES (#4897)

This commit is contained in:
buddh4 2021-02-19 12:19:40 +01:00 committed by GitHub
parent 68e64bf2a1
commit 4fefcfcbc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 5 deletions

View File

@ -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()

View File

@ -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;
}
}