diff options
author | 2020-10-09 20:29:02 +0200 | |
---|---|---|
committer | 2020-10-09 23:29:02 +0500 | |
commit | ff98efe8dc13c978be3a715da44f825af194513c (patch) | |
tree | af05c3d3f6e82c4ea6a41af22fc80d9ceb21ac65 /lib/html.php | |
parent | fe166d0216683754e85d32f48cd78a2ac4b8a7e3 (diff) | |
download | rss-bridge-ff98efe8dc13c978be3a715da44f825af194513c.tar.gz rss-bridge-ff98efe8dc13c978be3a715da44f825af194513c.tar.zst rss-bridge-ff98efe8dc13c978be3a715da44f825af194513c.zip |
[core] Use Parsedown for Markdown parsing (#1783)
Diffstat (limited to 'lib/html.php')
-rw-r--r-- | lib/html.php | 40 |
1 files changed, 3 insertions, 37 deletions
diff --git a/lib/html.php b/lib/html.php index c56140bf..892ecb17 100644 --- a/lib/html.php +++ b/lib/html.php @@ -195,7 +195,7 @@ function stripRecursiveHTMLSection($string, $tag_name, $tag_start){ } /** - * Convert Markdown into HTML. Only a subset of the Markdown syntax is implemented. + * Convert Markdown into HTML with Parsedown. * * @link https://daringfireball.net/projects/markdown/ Markdown * @link https://github.github.com/gfm/ GitHub Flavored Markdown Spec @@ -205,40 +205,6 @@ function stripRecursiveHTMLSection($string, $tag_name, $tag_start){ */ function markdownToHtml($string) { - //For more details about how these regex work: - // https://github.com/RSS-Bridge/rss-bridge/pull/802#discussion_r216138702 - // Images: https://regex101.com/r/JW9Evr/2 - // Links: https://regex101.com/r/eRGVe7/1 - // Bold: https://regex101.com/r/2p40Y0/1 - // Italic: https://regex101.com/r/xJkET9/1 - // Separator: https://regex101.com/r/ZBEqFP/1 - // Plain URL: https://regex101.com/r/2JHYwb/1 - // Site name: https://regex101.com/r/qIuKYE/1 - - $string = preg_replace('/\!\[([^\]]*)\]\(([^\) ]+)(?: [^\)]+)?\)/', '<img src="$2" alt="$1" />', $string); - $string = preg_replace('/\[([^\]]+)\]\(([^\)]+)\)/', '<a href="$2">$1</a>', $string); - $string = preg_replace('/\*\*(.*)\*\*/U', '<b>$1</b>', $string); - $string = preg_replace('/\*(.*)\*/U', '<i>$1</i>', $string); - $string = preg_replace('/__(.*)__/U', '<b>$1</b>', $string); - $string = preg_replace('/_(.*)_/U', '<i>$1</i>', $string); - $string = preg_replace('/[-]{6,99}/', '<hr />', $string); - $string = str_replace(' ', '<br />', $string); - $string = preg_replace('/([^"])(https?:\/\/[^ "<]+)([^"])/', '$1<a href="$2">$2</a>$3', $string . ' '); - $string = preg_replace('/([^"\/])(www\.[^ "<]+)([^"])/', '$1<a href="http://$2">$2</a>$3', $string . ' '); - - //As the regex are not perfect, we need to fix <i> and </i> that are introduced in URLs - // Fixup regex <i>: https://regex101.com/r/NTRPf6/1 - // Fixup regex </i>: https://regex101.com/r/aNklRp/1 - - $count = 1; - while($count > 0) { - $string = preg_replace('/ (src|href)="([^"]+)<i>([^"]+)"/U', ' $1="$2_$3"', $string, -1, $count); - } - - $count = 1; - while($count > 0) { - $string = preg_replace('/ (src|href)="([^"]+)<\/i>([^"]+)"/U', ' $1="$2_$3"', $string, -1, $count); - } - - return '<div>' . trim($string) . '</div>'; + $Parsedown = new Parsedown(); + return $Parsedown->text($string); } |