Skip to content

Commit

Permalink
Replace custom line breaks in ListBlockRenderer
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanzweifel committed Jul 30, 2023
1 parent e4ae133 commit 2aafd81
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Renderer/Block/ListBlockRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s
$content = $childRenderer->renderNodes($node->children());
$content = explode("\n", $content);

$content = array_map(fn ($item) => $this->replaceInternalLineBreakCharacter($item), $content);

if ($listData->type === ListBlock::TYPE_BULLET) {
$content = array_map(fn ($item) => "- {$item}", $content);
}
Expand All @@ -42,4 +44,16 @@ public function render(Node $node, ChildNodeRendererInterface $childRenderer): s

return implode("\n", $content) . "\n";
}

/**
* Replace custom line break character with _native_ line breaks.
* Whitespace is added so that other Markdown clients correctly
* render the list and its line breaks.
* @param string $content
* @return string
*/
private function replaceInternalLineBreakCharacter(string $content): string
{
return str_replace(ListItemRenderer::INLINE_LINE_BREAK, " \n ", $content);
}
}

0 comments on commit 2aafd81

Please sign in to comment.