<?php namespace BookStack\Entities\Tools;
-use BookStack\Entities\Page;
+use BookStack\Entities\Models\Page;
+use BookStack\Entities\Tools\Markdown\CustomStrikeThroughExtension;
use DOMDocument;
use DOMNodeList;
use DOMXPath;
+use League\CommonMark\CommonMarkConverter;
+use League\CommonMark\Environment;
+use League\CommonMark\Extension\Table\TableExtension;
+use League\CommonMark\Extension\TaskList\TaskListExtension;
class PageContent
{
{
$this->page->html = $this->formatHtml($html);
$this->page->text = $this->toPlainText();
+ $this->page->markdown = '';
+ }
+
+ /**
+ * Update the content of the page with new provided Markdown content.
+ */
+ public function setNewMarkdown(string $markdown)
+ {
+ $this->page->markdown = $markdown;
+ $html = $this->markdownToHtml($markdown);
+ $this->page->html = $this->formatHtml($html);
+ $this->page->text = $this->toPlainText();
+ }
+
+ /**
+ * Convert the given Markdown content to a HTML string.
+ */
+ protected function markdownToHtml(string $markdown): string
+ {
+ $environment = Environment::createCommonMarkEnvironment();
+ $environment->addExtension(new TableExtension());
+ $environment->addExtension(new TaskListExtension());
+ $environment->addExtension(new CustomStrikeThroughExtension());
+ $converter = new CommonMarkConverter([], $environment);
+ return $converter->convertToHtml($markdown);
}
/**