mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-02-08 01:43:59 +08:00
Merge branch 'fix/markdown-export' into development
Some checks failed
analyse-php / build (push) Has been cancelled
lint-php / build (push) Has been cancelled
test-migrations / build (8.1) (push) Has been cancelled
test-migrations / build (8.2) (push) Has been cancelled
test-migrations / build (8.3) (push) Has been cancelled
test-php / build (8.1) (push) Has been cancelled
test-php / build (8.2) (push) Has been cancelled
test-php / build (8.3) (push) Has been cancelled
Some checks failed
analyse-php / build (push) Has been cancelled
lint-php / build (push) Has been cancelled
test-migrations / build (8.1) (push) Has been cancelled
test-migrations / build (8.2) (push) Has been cancelled
test-migrations / build (8.3) (push) Has been cancelled
test-php / build (8.1) (push) Has been cancelled
test-php / build (8.2) (push) Has been cancelled
test-php / build (8.3) (push) Has been cancelled
This commit is contained in:
commit
18ab38a87b
|
@ -317,7 +317,12 @@ class ExportFormatter
|
||||||
public function chapterToMarkdown(Chapter $chapter): string
|
public function chapterToMarkdown(Chapter $chapter): string
|
||||||
{
|
{
|
||||||
$text = '# ' . $chapter->name . "\n\n";
|
$text = '# ' . $chapter->name . "\n\n";
|
||||||
$text .= $chapter->description . "\n\n";
|
|
||||||
|
$description = (new HtmlToMarkdown($chapter->descriptionHtml()))->convert();
|
||||||
|
if ($description) {
|
||||||
|
$text .= $description . "\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($chapter->pages as $page) {
|
foreach ($chapter->pages as $page) {
|
||||||
$text .= $this->pageToMarkdown($page) . "\n\n";
|
$text .= $this->pageToMarkdown($page) . "\n\n";
|
||||||
}
|
}
|
||||||
|
@ -332,6 +337,12 @@ class ExportFormatter
|
||||||
{
|
{
|
||||||
$bookTree = (new BookContents($book))->getTree(false, true);
|
$bookTree = (new BookContents($book))->getTree(false, true);
|
||||||
$text = '# ' . $book->name . "\n\n";
|
$text = '# ' . $book->name . "\n\n";
|
||||||
|
|
||||||
|
$description = (new HtmlToMarkdown($book->descriptionHtml()))->convert();
|
||||||
|
if ($description) {
|
||||||
|
$text .= $description . "\n\n";
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($bookTree as $bookChild) {
|
foreach ($bookTree as $bookChild) {
|
||||||
if ($bookChild instanceof Chapter) {
|
if ($bookChild instanceof Chapter) {
|
||||||
$text .= $this->chapterToMarkdown($bookChild) . "\n\n";
|
$text .= $this->chapterToMarkdown($bookChild) . "\n\n";
|
||||||
|
|
|
@ -45,23 +45,35 @@ class MarkdownExportTest extends TestCase
|
||||||
public function test_chapter_markdown_export()
|
public function test_chapter_markdown_export()
|
||||||
{
|
{
|
||||||
$chapter = $this->entities->chapter();
|
$chapter = $this->entities->chapter();
|
||||||
|
$chapter->description_html = '<p>My <strong>chapter</strong> description</p>';
|
||||||
|
$chapter->save();
|
||||||
$page = $chapter->pages()->first();
|
$page = $chapter->pages()->first();
|
||||||
|
|
||||||
$resp = $this->asEditor()->get($chapter->getUrl('/export/markdown'));
|
$resp = $this->asEditor()->get($chapter->getUrl('/export/markdown'));
|
||||||
|
|
||||||
$resp->assertSee('# ' . $chapter->name);
|
$resp->assertSee('# ' . $chapter->name);
|
||||||
$resp->assertSee('# ' . $page->name);
|
$resp->assertSee('# ' . $page->name);
|
||||||
|
$resp->assertSee('My **chapter** description');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_book_markdown_export()
|
public function test_book_markdown_export()
|
||||||
{
|
{
|
||||||
$book = Book::query()->whereHas('pages')->whereHas('chapters')->first();
|
$book = Book::query()->whereHas('pages')->whereHas('chapters')->first();
|
||||||
|
$book->description_html = '<p>My <strong>book</strong> description</p>';
|
||||||
|
$book->save();
|
||||||
|
|
||||||
$chapter = $book->chapters()->first();
|
$chapter = $book->chapters()->first();
|
||||||
|
$chapter->description_html = '<p>My <strong>chapter</strong> description</p>';
|
||||||
|
$chapter->save();
|
||||||
|
|
||||||
$page = $chapter->pages()->first();
|
$page = $chapter->pages()->first();
|
||||||
$resp = $this->asEditor()->get($book->getUrl('/export/markdown'));
|
$resp = $this->asEditor()->get($book->getUrl('/export/markdown'));
|
||||||
|
|
||||||
$resp->assertSee('# ' . $book->name);
|
$resp->assertSee('# ' . $book->name);
|
||||||
$resp->assertSee('# ' . $chapter->name);
|
$resp->assertSee('# ' . $chapter->name);
|
||||||
$resp->assertSee('# ' . $page->name);
|
$resp->assertSee('# ' . $page->name);
|
||||||
|
$resp->assertSee('My **book** description');
|
||||||
|
$resp->assertSee('My **chapter** description');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function test_book_markdown_export_concats_immediate_pages_with_newlines()
|
public function test_book_markdown_export_concats_immediate_pages_with_newlines()
|
||||||
|
|
Loading…
Reference in New Issue
Block a user