--- /dev/null
+<?php namespace BookStack\Entities\Tools\Markdown;
+
+use League\HTMLToMarkdown\Converter\BlockquoteConverter;
+use League\HTMLToMarkdown\Converter\CodeConverter;
+use League\HTMLToMarkdown\Converter\CommentConverter;
+use League\HTMLToMarkdown\Converter\DivConverter;
+use League\HTMLToMarkdown\Converter\EmphasisConverter;
+use League\HTMLToMarkdown\Converter\HardBreakConverter;
+use League\HTMLToMarkdown\Converter\HeaderConverter;
+use League\HTMLToMarkdown\Converter\HorizontalRuleConverter;
+use League\HTMLToMarkdown\Converter\ImageConverter;
+use League\HTMLToMarkdown\Converter\LinkConverter;
+use League\HTMLToMarkdown\Converter\ListBlockConverter;
+use League\HTMLToMarkdown\Converter\ListItemConverter;
+use League\HTMLToMarkdown\Converter\PreformattedConverter;
+use League\HTMLToMarkdown\Converter\TextConverter;
+use League\HTMLToMarkdown\Environment;
+use League\HTMLToMarkdown\HtmlConverter;
+
+class HtmlToMarkdown
+{
+ protected $html;
+
+ public function __construct(string $html)
+ {
+ $this->html = $html;
+ }
+
+ /**
+ * Run the conversion
+ */
+ public function convert(): string
+ {
+ $converter = new HtmlConverter($this->getConverterEnvironment());
+ $html = $this->prepareHtml($this->html);
+ return $converter->convert($html);
+ }
+
+ /**
+ * Run any pre-processing to the HTML to clean it up manually before conversion.
+ */
+ protected function prepareHtml(string $html): string
+ {
+ // Carriage returns can cause whitespace issues in output
+ $html = str_replace("\r\n", "\n", $html);
+ // Attributes on the pre tag can cause issues with conversion
+ return preg_replace('/<pre .*?>/', '<pre>', $html);
+ }
+
+ /**
+ * Get the HTML to Markdown customized environment.
+ * Extends the default provided environment with some BookStack specific tweaks.
+ */
+ protected function getConverterEnvironment(): Environment
+ {
+ $environment = new Environment(['header_style' => 'atx']);
+
+ $environment->addConverter(new BlockquoteConverter());
+ $environment->addConverter(new CodeConverter());
+ $environment->addConverter(new CommentConverter());
+ $environment->addConverter(new DivConverter());
+ $environment->addConverter(new EmphasisConverter());
+ $environment->addConverter(new HardBreakConverter());
+ $environment->addConverter(new HeaderConverter());
+ $environment->addConverter(new HorizontalRuleConverter());
+ $environment->addConverter(new ImageConverter());
+ $environment->addConverter(new LinkConverter());
+ $environment->addConverter(new ListBlockConverter());
+ $environment->addConverter(new ListItemConverter());
+ $environment->addConverter(new CustomParagraphConverter());
+ $environment->addConverter(new PreformattedConverter());
+ $environment->addConverter(new TextConverter());
+
+ return $environment;
+ }
+}
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
- "content-hash": "eb3108f1a3a757df9b9a3a4f82b5db3b",
+ "content-hash": "70a290f0e2112361af4a0abe15148adc",
"packages": [
{
"name": "aws/aws-sdk-php",
- "version": "3.184.2",
+ "version": "3.184.7",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
- "reference": "78fe691ab466fecf195209672f6c00c5d4ed219a"
+ "reference": "d5d5fe5fdfca6c7a56f2f8364d09c3100d5c2149"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/78fe691ab466fecf195209672f6c00c5d4ed219a",
- "reference": "78fe691ab466fecf195209672f6c00c5d4ed219a",
+ "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/d5d5fe5fdfca6c7a56f2f8364d09c3100d5c2149",
+ "reference": "d5d5fe5fdfca6c7a56f2f8364d09c3100d5c2149",
"shasum": ""
},
"require": {
"support": {
"forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80",
"issues": "https://github.com/aws/aws-sdk-php/issues",
- "source": "https://github.com/aws/aws-sdk-php/tree/3.184.2"
+ "source": "https://github.com/aws/aws-sdk-php/tree/3.184.7"
},
- "time": "2021-06-11T18:20:15+00:00"
+ "time": "2021-06-21T18:37:16+00:00"
},
{
"name": "barryvdh/laravel-dompdf",
},
{
"name": "doctrine/cache",
- "version": "1.11.3",
+ "version": "2.0.3",
"source": {
"type": "git",
"url": "https://github.com/doctrine/cache.git",
- "reference": "3bb5588cec00a0268829cc4a518490df6741af9d"
+ "reference": "c9622c6820d3ede1e2315a6a377ea1076e421d88"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/cache/zipball/3bb5588cec00a0268829cc4a518490df6741af9d",
- "reference": "3bb5588cec00a0268829cc4a518490df6741af9d",
+ "url": "https://api.github.com/repos/doctrine/cache/zipball/c9622c6820d3ede1e2315a6a377ea1076e421d88",
+ "reference": "c9622c6820d3ede1e2315a6a377ea1076e421d88",
"shasum": ""
},
"require": {
],
"support": {
"issues": "https://github.com/doctrine/cache/issues",
- "source": "https://github.com/doctrine/cache/tree/1.11.3"
+ "source": "https://github.com/doctrine/cache/tree/2.0.3"
},
"funding": [
{
"type": "tidelift"
}
],
- "time": "2021-05-25T09:01:55+00:00"
+ "time": "2021-05-25T09:43:04+00:00"
},
{
"name": "doctrine/dbal",
- "version": "2.13.1",
+ "version": "2.13.2",
"source": {
"type": "git",
"url": "https://github.com/doctrine/dbal.git",
- "reference": "c800380457948e65bbd30ba92cc17cda108bf8c9"
+ "reference": "8dd39d2ead4409ce652fd4f02621060f009ea5e4"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/doctrine/dbal/zipball/c800380457948e65bbd30ba92cc17cda108bf8c9",
- "reference": "c800380457948e65bbd30ba92cc17cda108bf8c9",
+ "url": "https://api.github.com/repos/doctrine/dbal/zipball/8dd39d2ead4409ce652fd4f02621060f009ea5e4",
+ "reference": "8dd39d2ead4409ce652fd4f02621060f009ea5e4",
"shasum": ""
},
"require": {
- "doctrine/cache": "^1.0",
+ "doctrine/cache": "^1.0|^2.0",
"doctrine/deprecations": "^0.5.3",
"doctrine/event-manager": "^1.0",
"ext-pdo": "*",
"php": "^7.1 || ^8"
},
"require-dev": {
- "doctrine/coding-standard": "8.2.0",
+ "doctrine/coding-standard": "9.0.0",
"jetbrains/phpstorm-stubs": "2020.2",
"phpstan/phpstan": "0.12.81",
- "phpunit/phpunit": "^7.5.20|^8.5|9.5.0",
+ "phpunit/phpunit": "^7.5.20|^8.5|9.5.5",
"squizlabs/php_codesniffer": "3.6.0",
+ "symfony/cache": "^4.4",
"symfony/console": "^2.0.5|^3.0|^4.0|^5.0",
"vimeo/psalm": "4.6.4"
},
],
"support": {
"issues": "https://github.com/doctrine/dbal/issues",
- "source": "https://github.com/doctrine/dbal/tree/2.13.1"
+ "source": "https://github.com/doctrine/dbal/tree/2.13.2"
},
"funding": [
{
"type": "tidelift"
}
],
- "time": "2021-04-17T17:30:19+00:00"
+ "time": "2021-06-18T21:48:39+00:00"
},
{
"name": "doctrine/deprecations",
},
{
"name": "laravel/framework",
- "version": "v6.20.27",
+ "version": "v6.20.29",
"source": {
"type": "git",
"url": "https://github.com/laravel/framework.git",
- "reference": "92c0417e60efc39bc556ba5dfc9b20a56f7848fb"
+ "reference": "00fa9c04aed10d68481f5757b89da0e6798f53b3"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/laravel/framework/zipball/92c0417e60efc39bc556ba5dfc9b20a56f7848fb",
- "reference": "92c0417e60efc39bc556ba5dfc9b20a56f7848fb",
+ "url": "https://api.github.com/repos/laravel/framework/zipball/00fa9c04aed10d68481f5757b89da0e6798f53b3",
+ "reference": "00fa9c04aed10d68481f5757b89da0e6798f53b3",
"shasum": ""
},
"require": {
"issues": "https://github.com/laravel/framework/issues",
"source": "https://github.com/laravel/framework"
},
- "time": "2021-05-11T14:00:28+00:00"
+ "time": "2021-06-22T13:41:06+00:00"
},
{
"name": "laravel/socialite",
},
{
"name": "league/commonmark",
- "version": "1.6.2",
+ "version": "1.6.4",
"source": {
"type": "git",
"url": "https://github.com/thephpleague/commonmark.git",
- "reference": "7d70d2f19c84bcc16275ea47edabee24747352eb"
+ "reference": "c3c8b7217c52572fb42aaf84211abccf75a151b2"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/7d70d2f19c84bcc16275ea47edabee24747352eb",
- "reference": "7d70d2f19c84bcc16275ea47edabee24747352eb",
+ "url": "https://api.github.com/repos/thephpleague/commonmark/zipball/c3c8b7217c52572fb42aaf84211abccf75a151b2",
+ "reference": "c3c8b7217c52572fb42aaf84211abccf75a151b2",
"shasum": ""
},
"require": {
"github/gfm": "0.29.0",
"michelf/php-markdown": "~1.4",
"mikehaertl/php-shellcommand": "^1.4",
- "phpstan/phpstan": "^0.12",
+ "phpstan/phpstan": "^0.12.90",
"phpunit/phpunit": "^7.5 || ^8.5 || ^9.2",
"scrutinizer/ocular": "^1.5",
"symfony/finder": "^4.2"
"type": "tidelift"
}
],
- "time": "2021-05-12T11:39:41+00:00"
+ "time": "2021-06-19T20:08:14+00:00"
},
{
"name": "league/flysystem",
},
"time": "2020-10-08T18:58:37+00:00"
},
+ {
+ "name": "league/html-to-markdown",
+ "version": "5.0.0",
+ "source": {
+ "type": "git",
+ "url": "https://github.com/thephpleague/html-to-markdown.git",
+ "reference": "c4dbebbebe0fe454b6b38e6c683a977615bd7dc2"
+ },
+ "dist": {
+ "type": "zip",
+ "url": "https://api.github.com/repos/thephpleague/html-to-markdown/zipball/c4dbebbebe0fe454b6b38e6c683a977615bd7dc2",
+ "reference": "c4dbebbebe0fe454b6b38e6c683a977615bd7dc2",
+ "shasum": ""
+ },
+ "require": {
+ "ext-dom": "*",
+ "ext-xml": "*",
+ "php": "^7.2.5 || ^8.0"
+ },
+ "require-dev": {
+ "mikehaertl/php-shellcommand": "^1.1.0",
+ "phpstan/phpstan": "^0.12.82",
+ "phpunit/phpunit": "^8.5 || ^9.2",
+ "scrutinizer/ocular": "^1.6",
+ "unleashedtech/php-coding-standard": "^2.7",
+ "vimeo/psalm": "^4.6"
+ },
+ "bin": [
+ "bin/html-to-markdown"
+ ],
+ "type": "library",
+ "extra": {
+ "branch-alias": {
+ "dev-master": "5.1-dev"
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "League\\HTMLToMarkdown\\": "src/"
+ }
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Colin O'Dell",
+ "homepage": "https://www.colinodell.com",
+ "role": "Lead Developer"
+ },
+ {
+ "name": "Nick Cernis",
+ "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"
+ ],
+ "support": {
+ "issues": "https://github.com/thephpleague/html-to-markdown/issues",
+ "source": "https://github.com/thephpleague/html-to-markdown/tree/5.0.0"
+ },
+ "funding": [
+ {
+ "url": "https://www.colinodell.com/sponsor",
+ "type": "custom"
+ },
+ {
+ "url": "https://www.paypal.me/colinpodell/10.00",
+ "type": "custom"
+ },
+ {
+ "url": "https://github.com/colinodell",
+ "type": "github"
+ },
+ {
+ "url": "https://www.patreon.com/colinodell",
+ "type": "patreon"
+ }
+ ],
+ "time": "2021-03-29T01:29:08+00:00"
+ },
{
"name": "league/mime-type-detection",
"version": "1.7.0",
},
{
"name": "mtdowling/jmespath.php",
- "version": "2.6.0",
+ "version": "2.6.1",
"source": {
"type": "git",
"url": "https://github.com/jmespath/jmespath.php.git",
- "reference": "42dae2cbd13154083ca6d70099692fef8ca84bfb"
+ "reference": "9b87907a81b87bc76d19a7fb2d61e61486ee9edb"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/42dae2cbd13154083ca6d70099692fef8ca84bfb",
- "reference": "42dae2cbd13154083ca6d70099692fef8ca84bfb",
+ "url": "https://api.github.com/repos/jmespath/jmespath.php/zipball/9b87907a81b87bc76d19a7fb2d61e61486ee9edb",
+ "reference": "9b87907a81b87bc76d19a7fb2d61e61486ee9edb",
"shasum": ""
},
"require": {
"symfony/polyfill-mbstring": "^1.17"
},
"require-dev": {
- "composer/xdebug-handler": "^1.4",
+ "composer/xdebug-handler": "^1.4 || ^2.0",
"phpunit/phpunit": "^4.8.36 || ^7.5.15"
},
"bin": [
],
"support": {
"issues": "https://github.com/jmespath/jmespath.php/issues",
- "source": "https://github.com/jmespath/jmespath.php/tree/2.6.0"
+ "source": "https://github.com/jmespath/jmespath.php/tree/2.6.1"
},
- "time": "2020-07-31T21:01:56+00:00"
+ "time": "2021-06-14T00:11:39+00:00"
},
{
"name": "nesbot/carbon",
},
{
"name": "socialiteproviders/microsoft-azure",
- "version": "4.2.0",
+ "version": "4.2.1",
"source": {
"type": "git",
"url": "https://github.com/SocialiteProviders/Microsoft-Azure.git",
- "reference": "7808764f777a01df88be9ca6b14d683e50aaf88a"
+ "reference": "64779ec21db0bee3111039a67c0fa0ab550a3462"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/SocialiteProviders/Microsoft-Azure/zipball/7808764f777a01df88be9ca6b14d683e50aaf88a",
- "reference": "7808764f777a01df88be9ca6b14d683e50aaf88a",
+ "url": "https://api.github.com/repos/SocialiteProviders/Microsoft-Azure/zipball/64779ec21db0bee3111039a67c0fa0ab550a3462",
+ "reference": "64779ec21db0bee3111039a67c0fa0ab550a3462",
"shasum": ""
},
"require": {
],
"description": "Microsoft Azure OAuth2 Provider for Laravel Socialite",
"support": {
- "source": "https://github.com/SocialiteProviders/Microsoft-Azure/tree/4.2.0"
+ "source": "https://github.com/SocialiteProviders/Microsoft-Azure/tree/4.2.1"
},
- "time": "2020-12-01T23:10:59+00:00"
+ "time": "2021-06-14T22:51:38+00:00"
},
{
"name": "socialiteproviders/okta",
},
{
"name": "symfony/mime",
- "version": "v5.3.0",
+ "version": "v5.3.2",
"source": {
"type": "git",
"url": "https://github.com/symfony/mime.git",
- "reference": "ed710d297b181f6a7194d8172c9c2423d58e4852"
+ "reference": "47dd7912152b82d0d4c8d9040dbc93d6232d472a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/symfony/mime/zipball/ed710d297b181f6a7194d8172c9c2423d58e4852",
- "reference": "ed710d297b181f6a7194d8172c9c2423d58e4852",
+ "url": "https://api.github.com/repos/symfony/mime/zipball/47dd7912152b82d0d4c8d9040dbc93d6232d472a",
+ "reference": "47dd7912152b82d0d4c8d9040dbc93d6232d472a",
"shasum": ""
},
"require": {
"mime-type"
],
"support": {
- "source": "https://github.com/symfony/mime/tree/v5.3.0"
+ "source": "https://github.com/symfony/mime/tree/v5.3.2"
},
"funding": [
{
"type": "tidelift"
}
],
- "time": "2021-05-26T17:43:10+00:00"
+ "time": "2021-06-09T10:58:01+00:00"
},
{
"name": "symfony/polyfill-ctype",
"packages-dev": [
{
"name": "barryvdh/laravel-debugbar",
- "version": "v3.6.1",
+ "version": "v3.6.2",
"source": {
"type": "git",
"url": "https://github.com/barryvdh/laravel-debugbar.git",
- "reference": "f6f0f895a33cac801286a74355d146bb5384a5da"
+ "reference": "70b89754913fd89fef16d0170a91dbc2a5cd633a"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/f6f0f895a33cac801286a74355d146bb5384a5da",
- "reference": "f6f0f895a33cac801286a74355d146bb5384a5da",
+ "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/70b89754913fd89fef16d0170a91dbc2a5cd633a",
+ "reference": "70b89754913fd89fef16d0170a91dbc2a5cd633a",
"shasum": ""
},
"require": {
],
"support": {
"issues": "https://github.com/barryvdh/laravel-debugbar/issues",
- "source": "https://github.com/barryvdh/laravel-debugbar/tree/v3.6.1"
+ "source": "https://github.com/barryvdh/laravel-debugbar/tree/v3.6.2"
},
"funding": [
+ {
+ "url": "https://fruitcake.nl",
+ "type": "custom"
+ },
{
"url": "https://github.com/barryvdh",
"type": "github"
}
],
- "time": "2021-06-02T06:42:22+00:00"
+ "time": "2021-06-14T14:29:26+00:00"
},
{
"name": "barryvdh/laravel-ide-helper",
},
{
"name": "sebastian/type",
- "version": "2.3.2",
+ "version": "2.3.4",
"source": {
"type": "git",
"url": "https://github.com/sebastianbergmann/type.git",
- "reference": "0d1c587401514d17e8f9258a27e23527cb1b06c1"
+ "reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914"
},
"dist": {
"type": "zip",
- "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/0d1c587401514d17e8f9258a27e23527cb1b06c1",
- "reference": "0d1c587401514d17e8f9258a27e23527cb1b06c1",
+ "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/b8cd8a1c753c90bc1a0f5372170e3e489136f914",
+ "reference": "b8cd8a1c753c90bc1a0f5372170e3e489136f914",
"shasum": ""
},
"require": {
"homepage": "https://github.com/sebastianbergmann/type",
"support": {
"issues": "https://github.com/sebastianbergmann/type/issues",
- "source": "https://github.com/sebastianbergmann/type/tree/2.3.2"
+ "source": "https://github.com/sebastianbergmann/type/tree/2.3.4"
},
"funding": [
{
"type": "github"
}
],
- "time": "2021-06-04T13:02:07+00:00"
+ "time": "2021-06-15T12:49:02+00:00"
},
{
"name": "sebastian/version",