mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-10-01 01:36:00 -04:00
4fd5dbcfdd
- Numbered and bullet list margins have been made consistent - Numbered lists margins were increase at some point to handle 3-digit numbers, Normal bullet margins updated to match this. - Consistent margin for sub-lists. - System back-end markdown renderer (For pages) updated with a custom list item renderer to apply class for to align with front-end renderer. - This means that task list items will be consistent with the preview and not render a number/bullet. - Indentation styles for task list items fixed to be visually indented. For #2854 and #2837
43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace BookStack\Entities\Tools\Markdown;
|
|
|
|
use League\CommonMark\Block\Element\AbstractBlock;
|
|
use League\CommonMark\Block\Element\ListItem;
|
|
use League\CommonMark\Block\Element\Paragraph;
|
|
use League\CommonMark\Block\Renderer\BlockRendererInterface;
|
|
use League\CommonMark\Block\Renderer\ListItemRenderer;
|
|
use League\CommonMark\ElementRendererInterface;
|
|
use League\CommonMark\Extension\TaskList\TaskListItemMarker;
|
|
use League\CommonMark\HtmlElement;
|
|
|
|
class CustomListItemRenderer implements BlockRendererInterface
|
|
{
|
|
protected $baseRenderer;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->baseRenderer = new ListItemRenderer();
|
|
}
|
|
|
|
/**
|
|
* @return HtmlElement|string|null
|
|
*/
|
|
public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, bool $inTightList = false)
|
|
{
|
|
$listItem = $this->baseRenderer->render($block, $htmlRenderer, $inTightList);
|
|
|
|
if ($this->startsTaskListItem($block)) {
|
|
$listItem->setAttribute('class', 'task-list-item');
|
|
}
|
|
|
|
return $listItem;
|
|
}
|
|
|
|
private function startsTaskListItem(ListItem $block): bool
|
|
{
|
|
$firstChild = $block->firstChild();
|
|
|
|
return $firstChild instanceof Paragraph && $firstChild->firstChild() instanceof TaskListItemMarker;
|
|
}
|
|
} |