]> git.mxchange.org Git - friendica.git/commitdiff
Strip HTML tags from content sent as Markdown
authorRandom Penguin <205060075+randompenguin1@users.noreply.github.com>
Sun, 20 Apr 2025 17:05:26 +0000 (12:05 -0500)
committerGitHub <noreply@github.com>
Sun, 20 Apr 2025 17:05:26 +0000 (12:05 -0500)
The "toMarkdown" function prepares content to be sent, primarily, to Diaspora.

The HTML to Markdown converter by default "preserves HTML tags without Markdown equivalents like `<span>` and `<div>.`" At least according to the README in _/friendica/vendor/league/html-to-markdown/_ - which also says "To strip HTML tags that don’t have a Markdown equivalent while preserving the content inside them, set strip_tags..."

Diaspora, however, does not appear to know what to DO with the HTML sent to it. It actually appears to _encode_ the HTML and displays the *code* in the post body rather than rendering it as HTML. In which case it would make more sense to strip out all tags that have no Markdown equivalents.

src/Content/Text/HTML.php

index f5cf2c6eca74e83fe06312addbd3e5c8e121e142..f29f4a148ebc8b843b29fcf9a292829b33379b6d 100644 (file)
@@ -689,7 +689,7 @@ class HTML
        public static function toMarkdown(string $html): string
        {
                DI::profiler()->startRecording('rendering');
-               $converter = new HtmlConverter(['hard_break' => true]);
+               $converter = new HtmlConverter(['hard_break' => true, ‘strip_tags’ => true]]);
                $markdown  = $converter->convert($html);
 
                DI::profiler()->stopRecording();