From 062b9ecbf3a3b315097428a6d608376055d4cae5 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Tue, 30 May 2017 18:22:48 -0700 Subject: bring back html2markdown which went away in the merge --- include/markdown.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'include/markdown.php') 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; +} -- cgit v1.2.3