diff --git a/app/Entities/Tools/Markdown/CheckboxConverter.php b/app/Entities/Tools/Markdown/CheckboxConverter.php new file mode 100644 index 000000000..e4666d666 --- /dev/null +++ b/app/Entities/Tools/Markdown/CheckboxConverter.php @@ -0,0 +1,28 @@ +getAttribute('type')) === 'checkbox') { + $isChecked = $element->getAttribute('checked') === 'checked'; + return $isChecked ? ' [x] ' : ' [ ] '; + } + + return $element->getValue(); + } + + /** + * @return string[] + */ + public function getSupportedTags(): array + { + return ['input']; + } +} \ No newline at end of file diff --git a/app/Entities/Tools/Markdown/HtmlToMarkdown.php b/app/Entities/Tools/Markdown/HtmlToMarkdown.php index e8804690c..51366705c 100644 --- a/app/Entities/Tools/Markdown/HtmlToMarkdown.php +++ b/app/Entities/Tools/Markdown/HtmlToMarkdown.php @@ -87,6 +87,7 @@ class HtmlToMarkdown $environment->addConverter(new CustomParagraphConverter()); $environment->addConverter(new PreformattedConverter()); $environment->addConverter(new TextConverter()); + $environment->addConverter(new CheckboxConverter()); return $environment; } diff --git a/tests/Entity/ExportTest.php b/tests/Entity/ExportTest.php index fc15bb8f3..2841175ad 100644 --- a/tests/Entity/ExportTest.php +++ b/tests/Entity/ExportTest.php @@ -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' => '', + ]); + $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();