I am currently writing/extending a migration script for an old SMF-Forum to Flarum. In that process i want to transform some BBCodes to Markdown. Specifically the BBCode for [spoiler] as it gets rendered as HTML <details>-Element, which can be folded out. This is pretty weird if the Spoiler is used inline for a single word or short phrase. Therefore i want the Markdown Spoilers >!spoiler text!<, which work flawlessly inline.
So basically i want to do this in my script and save it to the database:
$str = preg_replace("/\[spoiler\](.*)\[\/spoiler\]/", ">!$1!<", $str);
But this is getting rendered out verbatim as >!some spoiler text!< and not transformed to the black bar over the text which disappears when clicking on it, like: Help me, Obi-Wan Kenobi. You're my only hope.
Even if i look at a "working" spoiler in the database an replace my string like so, it only gets rendered verbatim.
# not working either
$str = preg_replace("/\[spoiler\](.*)\[\/spoiler\]/", "<ISPOILER><s>>!</s>$1<e>!<</e></ISPOILER>", $str);
If i edit a post with the >!some spoiler text!< in the database, the preview immediately renders it correctly as Spoiler. So i guess i have to call some special function for Markdown before i save it to the database, have i? Any hints?