mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-24 14:08:06 +08:00
support exporting WYSIWYG pages as Markdown
This commit is contained in:
parent
a34a07c610
commit
a7d9646b19
|
@ -6,6 +6,7 @@ use BookStack\Uploads\ImageService;
|
|||
use DomPDF;
|
||||
use Exception;
|
||||
use SnappyPDF;
|
||||
use League\HTMLToMarkdown\HtmlConverter;
|
||||
use Throwable;
|
||||
|
||||
class ExportService
|
||||
|
@ -232,11 +233,11 @@ class ExportService
|
|||
*/
|
||||
public function pageToMarkdown(Page $page)
|
||||
{
|
||||
if (property_exists($page, 'markdown') || $page->markdown != '') {
|
||||
return "#" . $page->name . "\n\n" . $page->markdown;
|
||||
if (property_exists($page, 'markdown') && $page->markdown != '') {
|
||||
return "# " . $page->name . "\n\n" . $page->markdown;
|
||||
} else {
|
||||
// TODO: Implement this feature.
|
||||
return "# Unimplemented Feature\nidk how to turn html into markdown";
|
||||
$converter = new HtmlConverter();
|
||||
return "# " . $page->name . "\n\n" . $converter->convert($page->html);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -246,7 +247,7 @@ class ExportService
|
|||
*/
|
||||
public function chapterToMarkdown(Chapter $chapter)
|
||||
{
|
||||
$text = "#" . $chapter->name . "\n\n";
|
||||
$text = "# " . $chapter->name . "\n\n";
|
||||
$text .= $chapter->description . "\n\n";
|
||||
foreach ($chapter->pages as $page) {
|
||||
$text .= $this->pageToMarkdown($page);
|
||||
|
@ -260,7 +261,7 @@ class ExportService
|
|||
public function bookToMarkdown(Book $book): string
|
||||
{
|
||||
$bookTree = (new BookContents($book))->getTree(false, true);
|
||||
$text = "#" . $book->name . "\n\n";
|
||||
$text = "# " . $book->name . "\n\n";
|
||||
foreach ($bookTree as $bookChild) {
|
||||
if ($bookChild->isA('chapter')) {
|
||||
$text .= $this->chapterToMarkdown($bookChild);
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
"laravel/socialite": "^4.3.2",
|
||||
"league/commonmark": "^1.4",
|
||||
"league/flysystem-aws-s3-v3": "^1.0",
|
||||
"league/html-to-markdown": "^4.9",
|
||||
"nunomaduro/collision": "^3.0",
|
||||
"onelogin/php-saml": "^3.3",
|
||||
"predis/predis": "^1.1",
|
||||
|
|
66
composer.lock
generated
66
composer.lock
generated
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "bbe47cff4f167fd6ce7047dff4602a78",
|
||||
"content-hash": "280a7e2fe2a6f65812594d73df2ccc0f",
|
||||
"packages": [
|
||||
{
|
||||
"name": "aws/aws-sdk-php",
|
||||
|
@ -2004,6 +2004,70 @@
|
|||
"description": "Flysystem adapter for the AWS S3 SDK v3.x",
|
||||
"time": "2020-02-23T13:31:58+00:00"
|
||||
},
|
||||
{
|
||||
"name": "league/html-to-markdown",
|
||||
"version": "4.9.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/thephpleague/html-to-markdown.git",
|
||||
"reference": "1dcd0f85de786f46a7f224a27cc3d709ddd2a68c"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/thephpleague/html-to-markdown/zipball/1dcd0f85de786f46a7f224a27cc3d709ddd2a68c",
|
||||
"reference": "1dcd0f85de786f46a7f224a27cc3d709ddd2a68c",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-dom": "*",
|
||||
"ext-xml": "*",
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"require-dev": {
|
||||
"mikehaertl/php-shellcommand": "~1.1.0",
|
||||
"phpunit/phpunit": "^4.8|^5.7",
|
||||
"scrutinizer/ocular": "~1.1"
|
||||
},
|
||||
"bin": [
|
||||
"bin/html-to-markdown"
|
||||
],
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "4.10-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"League\\HTMLToMarkdown\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Colin O'Dell",
|
||||
"email": "colinodell@gmail.com",
|
||||
"homepage": "https://www.colinodell.com",
|
||||
"role": "Lead Developer"
|
||||
},
|
||||
{
|
||||
"name": "Nick Cernis",
|
||||
"email": "nick@cern.is",
|
||||
"homepage": "http://modernnerd.net",
|
||||
"role": "Original Author"
|
||||
}
|
||||
],
|
||||
"description": "An HTML-to-markdown conversion helper for PHP",
|
||||
"homepage": "https://github.com/thephpleague/html-to-markdown",
|
||||
"keywords": [
|
||||
"html",
|
||||
"markdown"
|
||||
],
|
||||
"time": "2019-12-28T01:32:28+00:00"
|
||||
},
|
||||
{
|
||||
"name": "league/oauth1-client",
|
||||
"version": "1.7.0",
|
||||
|
|
Loading…
Reference in New Issue
Block a user