aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorzotlabs <mike@macgirvin.com>2017-05-30 18:22:48 -0700
committerzotlabs <mike@macgirvin.com>2017-05-30 18:22:48 -0700
commit062b9ecbf3a3b315097428a6d608376055d4cae5 (patch)
tree87e6051b5ddf25dfcc6a5b3532c367291c65133c /include
parentd3cad5a651d32557d92457b347c0d67372d2482c (diff)
downloadvolse-hubzilla-062b9ecbf3a3b315097428a6d608376055d4cae5.tar.gz
volse-hubzilla-062b9ecbf3a3b315097428a6d608376055d4cae5.tar.bz2
volse-hubzilla-062b9ecbf3a3b315097428a6d608376055d4cae5.zip
bring back html2markdown which went away in the merge
Diffstat (limited to 'include')
-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;
+}