aboutsummaryrefslogtreecommitdiffstats
path: root/include/markdown.php
diff options
context:
space:
mode:
Diffstat (limited to 'include/markdown.php')
-rw-r--r--include/markdown.php30
1 files changed, 30 insertions, 0 deletions
diff --git a/include/markdown.php b/include/markdown.php
index 1c42937b3..947b5c5e3 100644
--- a/include/markdown.php
+++ b/include/markdown.php
@@ -204,3 +204,33 @@ function bb_to_markdown($Text) {
return $Text;
}
+
+
+
+/**
+ * @brief Convert a HTML text into Markdown.
+ *
+ * This function uses the library league/html-to-markdown for this task.
+ *
+ * If the HTML text can not get parsed it will return an empty string.
+ *
+ * @see HTMLToMarkdown
+ *
+ * @param string $html The HTML code to convert
+ * @return string Markdown representation of the given HTML text, empty on error
+ */
+function html2markdown($html) {
+ $markdown = '';
+ $converter = new HtmlConverter();
+
+ try {
+ $markdown = $converter->convert($html);
+ } catch (InvalidArgumentException $e) {
+ logger("Invalid HTML. HTMLToMarkdown library threw an exception.");
+ }
+
+ // The old html 2 markdown library "pixel418/markdownify": "^2.2",
+ //$md = new HtmlConverter();
+ //$markdown = $md->convert($Text);
+ return $markdown;
+}