Strip HTML comments from markdown content


We can add HTML comments <!-- Hello world! --> into markdown and it’s nice when we have copied something useful from the web that we want to base a page on. However, the comment it will be published as well, because it’s HTML, not PHP.

So I made a super small post filter to strip out HTML comments from the markdown content.

Regex source:

kirbytext::$post[] = function($kirbytext, $value) {
    return preg_replace('/<!--(.|\s)*?-->/', '', $value);

Then it will magically remove all HTML comments from all content when using like $page->text()->kt().