mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-01-19 08:42:48 +08:00
Added tasklist support to markdown exporter
This commit is contained in:
parent
ea62fe6004
commit
c5aad29c72
28
app/Entities/Tools/Markdown/CheckboxConverter.php
Normal file
28
app/Entities/Tools/Markdown/CheckboxConverter.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
namespace BookStack\Entities\Tools\Markdown;
|
||||
|
||||
use League\HTMLToMarkdown\Converter\ConverterInterface;
|
||||
use League\HTMLToMarkdown\ElementInterface;
|
||||
|
||||
class CheckboxConverter implements ConverterInterface
|
||||
{
|
||||
|
||||
public function convert(ElementInterface $element): string
|
||||
{
|
||||
if (strtolower($element->getAttribute('type')) === 'checkbox') {
|
||||
$isChecked = $element->getAttribute('checked') === 'checked';
|
||||
return $isChecked ? ' [x] ' : ' [ ] ';
|
||||
}
|
||||
|
||||
return $element->getValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
public function getSupportedTags(): array
|
||||
{
|
||||
return ['input'];
|
||||
}
|
||||
}
|
|
@ -87,6 +87,7 @@ class HtmlToMarkdown
|
|||
$environment->addConverter(new CustomParagraphConverter());
|
||||
$environment->addConverter(new PreformattedConverter());
|
||||
$environment->addConverter(new TextConverter());
|
||||
$environment->addConverter(new CheckboxConverter());
|
||||
|
||||
return $environment;
|
||||
}
|
||||
|
|
|
@ -386,6 +386,18 @@ class ExportTest extends TestCase
|
|||
$resp->assertSee("# Dogcat\n\n```JavaScript\nvar a = 'cat';\n```\n\nAnother line", false);
|
||||
}
|
||||
|
||||
public function test_page_markdown_export_handles_tasklist_checkboxes()
|
||||
{
|
||||
$page = Page::query()->first()->forceFill([
|
||||
'markdown' => '',
|
||||
'html' => '<ul><li><input type="checkbox" checked="checked">Item A</li><li><input type="checkbox">Item B</li></ul>',
|
||||
]);
|
||||
$page->save();
|
||||
|
||||
$resp = $this->asEditor()->get($page->getUrl('/export/markdown'));
|
||||
$resp->assertSee("- [x] Item A\n- [ ] Item B", false);
|
||||
}
|
||||
|
||||
public function test_chapter_markdown_export()
|
||||
{
|
||||
$chapter = Chapter::query()->first();
|
||||
|
|
Loading…
Reference in New Issue
Block a user