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
317
317
public function chapterToMarkdown (Chapter $ chapter ): string
318
318
{
319
319
$ 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
+
321
326
foreach ($ chapter ->pages as $ page ) {
322
327
$ text .= $ this ->pageToMarkdown ($ page ) . "\n\n" ;
323
328
}
@@ -332,6 +337,12 @@ public function bookToMarkdown(Book $book): string
332
337
{
333
338
$ bookTree = (new BookContents ($ book ))->getTree (false , true );
334
339
$ text = '# ' . $ book ->name . "\n\n" ;
340
+
341
+ $ description = (new HtmlToMarkdown ($ book ->descriptionHtml ()))->convert ();
342
+ if ($ description ) {
343
+ $ text .= $ description . "\n\n" ;
344
+ }
345
+
335
346
foreach ($ bookTree as $ bookChild ) {
336
347
if ($ bookChild instanceof Chapter) {
337
348
$ 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()
45
45
public function test_chapter_markdown_export ()
46
46
{
47
47
$ chapter = $ this ->entities ->chapter ();
48
+ $ chapter ->description_html = '<p>My <strong>chapter</strong> description</p> ' ;
49
+ $ chapter ->save ();
48
50
$ page = $ chapter ->pages ()->first ();
51
+
49
52
$ resp = $ this ->asEditor ()->get ($ chapter ->getUrl ('/export/markdown ' ));
50
53
51
54
$ resp ->assertSee ('# ' . $ chapter ->name );
52
55
$ resp ->assertSee ('# ' . $ page ->name );
56
+ $ resp ->assertSee ('My **chapter** description ' );
53
57
}
54
58
55
59
public function test_book_markdown_export ()
56
60
{
57
61
$ book = Book::query ()->whereHas ('pages ' )->whereHas ('chapters ' )->first ();
62
+ $ book ->description_html = '<p>My <strong>book</strong> description</p> ' ;
63
+ $ book ->save ();
64
+
58
65
$ chapter = $ book ->chapters ()->first ();
66
+ $ chapter ->description_html = '<p>My <strong>chapter</strong> description</p> ' ;
67
+ $ chapter ->save ();
68
+
59
69
$ page = $ chapter ->pages ()->first ();
60
70
$ resp = $ this ->asEditor ()->get ($ book ->getUrl ('/export/markdown ' ));
61
71
62
72
$ resp ->assertSee ('# ' . $ book ->name );
63
73
$ resp ->assertSee ('# ' . $ chapter ->name );
64
74
$ resp ->assertSee ('# ' . $ page ->name );
75
+ $ resp ->assertSee ('My **book** description ' );
76
+ $ resp ->assertSee ('My **chapter** description ' );
65
77
}
66
78
67
79
public function test_book_markdown_export_concats_immediate_pages_with_newlines ()
You can’t perform that action at this time.
0 commit comments