File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -317,7 +317,12 @@ public function pageToMarkdown(Page $page): string
317317 public function chapterToMarkdown (Chapter $ chapter ): string
318318 {
319319 $ text = '# ' . $ chapter ->name . "\n\n" ;
320- $ text .= $ chapter ->description . "\n\n" ;
320+
321+ $ description = (new HtmlToMarkdown ($ chapter ->descriptionHtml ()))->convert ();
322+ if ($ description ) {
323+ $ text .= $ description . "\n\n" ;
324+ }
325+
321326 foreach ($ chapter ->pages as $ page ) {
322327 $ text .= $ this ->pageToMarkdown ($ page ) . "\n\n" ;
323328 }
@@ -332,6 +337,12 @@ public function bookToMarkdown(Book $book): string
332337 {
333338 $ bookTree = (new BookContents ($ book ))->getTree (false , true );
334339 $ text = '# ' . $ book ->name . "\n\n" ;
340+
341+ $ description = (new HtmlToMarkdown ($ book ->descriptionHtml ()))->convert ();
342+ if ($ description ) {
343+ $ text .= $ description . "\n\n" ;
344+ }
345+
335346 foreach ($ bookTree as $ bookChild ) {
336347 if ($ bookChild instanceof Chapter) {
337348 $ text .= $ this ->chapterToMarkdown ($ bookChild ) . "\n\n" ;
Original file line number Diff line number Diff line change @@ -45,23 +45,35 @@ public function test_page_markdown_export_converts_html_where_no_markdown()
4545 public function test_chapter_markdown_export ()
4646 {
4747 $ chapter = $ this ->entities ->chapter ();
48+ $ chapter ->description_html = '<p>My <strong>chapter</strong> description</p> ' ;
49+ $ chapter ->save ();
4850 $ page = $ chapter ->pages ()->first ();
51+
4952 $ resp = $ this ->asEditor ()->get ($ chapter ->getUrl ('/export/markdown ' ));
5053
5154 $ resp ->assertSee ('# ' . $ chapter ->name );
5255 $ resp ->assertSee ('# ' . $ page ->name );
56+ $ resp ->assertSee ('My **chapter** description ' );
5357 }
5458
5559 public function test_book_markdown_export ()
5660 {
5761 $ book = Book::query ()->whereHas ('pages ' )->whereHas ('chapters ' )->first ();
62+ $ book ->description_html = '<p>My <strong>book</strong> description</p> ' ;
63+ $ book ->save ();
64+
5865 $ chapter = $ book ->chapters ()->first ();
66+ $ chapter ->description_html = '<p>My <strong>chapter</strong> description</p> ' ;
67+ $ chapter ->save ();
68+
5969 $ page = $ chapter ->pages ()->first ();
6070 $ resp = $ this ->asEditor ()->get ($ book ->getUrl ('/export/markdown ' ));
6171
6272 $ resp ->assertSee ('# ' . $ book ->name );
6373 $ resp ->assertSee ('# ' . $ chapter ->name );
6474 $ resp ->assertSee ('# ' . $ page ->name );
75+ $ resp ->assertSee ('My **book** description ' );
76+ $ resp ->assertSee ('My **chapter** description ' );
6577 }
6678
6779 public function test_book_markdown_export_concats_immediate_pages_with_newlines ()
You can’t perform that action at this time.
0 commit comments