NOW MANAGED ON CODEBERG
support exporting WYSIWYG pages as Markdown
Nikhil Jhaa7d9646b19cd
diff --git a/app/Entities/ExportService.php b/app/Entities/ExportService.phpindex 29df1e82d..1b294d8b1 100644--- a/app/Entities/ExportService.php+++ b/app/Entities/ExportService.php@@ -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 ExportServicepublic 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);diff --git a/composer.json b/composer.jsonindex 80e8b0a61..68802e935 100644--- a/composer.json+++ b/composer.json@@ -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",diff --git a/composer.lock b/composer.lockindex 3ddd28e5a..7f58ffaee 100644--- a/composer.lock+++ b/composer.lock@@ -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": "[email protected]",+ "homepage": "https://www.colinodell.com",+ "role": "Lead Developer"+ },+ {+ "name": "Nick Cernis",+ "email": "[email protected]",+ "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",