Fix numerated lists in mail summary content (#5828)

* Fix numerated lists in mail summary content

* Fix numerated lists in mail summary content

* Test for numerated list in preview/short rich text

* Test for numerated list in preview/short rich text
This commit is contained in:
Yuriy Bakhtin 2022-08-08 12:38:52 +03:00 committed by GitHub
parent 965d3b87a4
commit df64d6de4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 2 deletions

View File

@ -5,6 +5,7 @@ HumHub Changelog
----------------------
- Fix #5822: Fix content width in mobile view
- Fix #5825: Fix format date to mysql on date stream filter
- Fix #5814: Fix numerated lists in mail summary content
- Fix #5830: Fix cron job of search index rebuilding
1.12.0 (July 27, 2022)

View File

@ -522,6 +522,17 @@ class RichTextShortTextConverterTest extends HumHubDbTestCase
"This is a list 1. First Element 2. Second Element");
}
public function testConvertOrderedListWithCustomNumbers()
{
$this->assertConversionResult(
"This is a list\n\n21. November - First line\n22. November - Second line\n23. November - Third line",
'This is a list 21. November - First line 22. November - Second line 23. November - Third line');
$this->assertConversionResult(
"This is a list\n\n29. November - First line\n24. November - Second line\n15. November - Third line",
'This is a list 29. November - First line 24. November - Second line 15. November - Third line');
}
public function testConvertOrderedSubList()
{
$this->assertConversionResult(

View File

@ -539,4 +539,24 @@ REGEXP;
{
return preg_replace('/\<br(\s*)?\/?\>/i', "\n", $text);
}
}
/**
* @inheritdoc
*/
protected function consumeOl($lines, $current)
{
$result = parent::consumeOl($lines, $current);
if (is_array($lines) && count($lines) > 0 && !empty($result[0]['items'])) {
$result[0]['origNums'] = [];
$i = array_keys($result[0]['items'])[0];
foreach ($lines as $line) {
if (preg_match('/^(\d+)\./', $line, $num)) {
$result[0]['origNums'][$i++] = $num[1];
}
}
}
return $result;
}
}

View File

@ -178,7 +178,7 @@ class RichTextToMarkdownConverter extends BaseRichTextConverter
unset( $line );
$output .= $level !== 0 ? "\n".str_repeat(' ', $level * 3) : '';
$output .= $block['list'] === 'ol' ? ++$count.'. ' : '- ';
$output .= $block['list'] === 'ol' ? (isset($block['origNums'][$item]) ? $block['origNums'][$item] : ++$count).'. ' : '- ';
$output .= $this->renderAbsy($itemLines). ($level === 0 ? "\n" : '');
}