diff options
author | Mario <mario@mariovavti.com> | 2021-06-05 08:55:32 +0000 |
---|---|---|
committer | Mario <mario@mariovavti.com> | 2021-06-05 08:55:32 +0000 |
commit | 14ab5801d2007165c0eaacd3b8c7f657efac213a (patch) | |
tree | 6bff29c5da5b275ff8e15eaa802734eb164830de /include/markdown.php | |
parent | fd8a5ff4c49fc1361f9928ea4d33e6d24d43a3a5 (diff) | |
download | volse-hubzilla-14ab5801d2007165c0eaacd3b8c7f657efac213a.tar.gz volse-hubzilla-14ab5801d2007165c0eaacd3b8c7f657efac213a.tar.bz2 volse-hubzilla-14ab5801d2007165c0eaacd3b8c7f657efac213a.zip |
league/html-to-markdown suports tables now
Diffstat (limited to 'include/markdown.php')
-rw-r--r-- | include/markdown.php | 74 |
1 files changed, 2 insertions, 72 deletions
diff --git a/include/markdown.php b/include/markdown.php index 013d57c29..b75613351 100644 --- a/include/markdown.php +++ b/include/markdown.php @@ -250,7 +250,7 @@ function bb_to_markdown($Text, $options = []) { call_hooks('bb_to_markdown_bb', $x); $Text = $x['bbcode']; - + // Replace spoiler tag before BBcode conversion $Text = preg_replace("/\[\/?spoiler\]/is", "\n--- " .t('spoiler') . " ---\n", $Text); @@ -271,7 +271,7 @@ function bb_to_markdown($Text, $options = []) { // Remove empty zrl links $Text = preg_replace("/\[zrl\=\].*?\[\/zrl\]/is", "", $Text); - + // Replace unprocessed <br> in code $Text = str_replace("<br></br>", "\n", $Text); @@ -325,73 +325,3 @@ function html2markdown($html, $options = []) { return $markdown; } - -// Tables are not an official part of the markdown specification. -// This interface was suggested as a workaround. -// author: Mark Hamstra -// https://github.com/Mark-H/Docs - - -class TableConverter implements ConverterInterface -{ - /** - * @param ElementInterface $element - * - * @return string - */ - public function convert(ElementInterface $element) - { - switch ($element->getTagName()) { - case 'tr': - $line = []; - $i = 1; - foreach ($element->getChildren() as $td) { - $i++; - $v = $td->getValue(); - $v = trim($v); - if ($i % 2 === 0 || $v !== '') { - $line[] = $v; - } - } - return '| ' . implode(' | ', $line) . " |\n"; - case 'td': - case 'th': - return trim($element->getValue()); - case 'tbody': - return trim($element->getValue()); - case 'thead': - $headerLine = reset($element->getChildren())->getValue(); - $headers = explode(' | ', trim(trim($headerLine, "\n"), '|')); - $hr = []; - foreach ($headers as $td) { - $length = strlen(trim($td)) + 2; - $hr[] = str_repeat('-', $length > 3 ? $length : 3); - } - $hr = '|' . implode('|', $hr) . '|'; - return $headerLine . $hr . "\n"; - case 'table': - $inner = $element->getValue(); - if (strpos($inner, '-----') === false) { - $inner = explode("\n", $inner); - $single = explode(' | ', trim($inner[0], '|')); - $hr = []; - foreach ($single as $td) { - $length = strlen(trim($td)) + 2; - $hr[] = str_repeat('-', $length > 3 ? $length : 3); - } - $hr = '|' . implode('|', $hr) . '|'; - array_splice($inner, 1, 0, $hr); - $inner = implode("\n", $inner); - } - return trim($inner) . "\n\n"; - } - return $element->getValue(); - } - /** - * @return string[] - */ - public function getSupportedTags() - { - return array('table', 'tr', 'thead', 'td', 'tbody'); - } -} |