Pre Filter, Html and Markdown Issue

Hi there everyone.
I’m currently working on an improved version of this site but I’m facing a weird issue.
On the site there’s an interview section where I use divs to wrap the questions and answers.

In the old version (the one currently online) I used two custom tags (q: ) and (a: ) and everything was working almost fine except for the fact that we couldn’t use links inside the kirbytag. That seems to be a known issue though.

So to avoid that problem I decided to try a different solution.
I’m currently marking the beginning and end of each question and answer with two markers, something like this:

q: This is the actual text. :q

And I’m then using a pre filter to swap those markers with div tags.

The pre filter looks like this

// Pre filter to include the q and a blocks
kirbytext::$pre[] = function($kirbytext, $value) {
    
    $value = preg_replace('/^(q:\s?)/m', "<div class='q'>", $value);
    $value = preg_replace('/(\s?:q)/m', "</div>", $value);
    $value = preg_replace('/(\s?:a)/m', "</div>", $value);
    $value = preg_replace('/^(a:\s?)/m', "<div class='a'>", $value);

    // Return the content
    return $value;
};

Up to this point, everything works correctly, the divs are in place, I can use kirbytags inside the text which si awesome but I noticed that the markdown is no longer parsed.

Is there a known reason why this is happening?

Thanks

Your markdown then sits within HTML tags, that’s why it is no longer parsed. You have to parse the text within your HTML, like here: https://github.com/getkirby/getkirby.com/blob/master/site/plugins/since/since.php. Using custom HTML tags like in this example since tag might also be a solution for your use case.

That was very helpful. Ended up doing this, if anyone needs to do something similar:

// Find and replace the question tags
$value = preg_replace_callback('/(^q:\s?)(.+)(\s?:q)/m' , function($match){

    // Build the string
    return '<div class="q">' . kirbytext($match[2]) . '</div>';

} , $value);