I'm trying to write a little WordPress plugin to support some migrated content.
The syntax highlighter expects (for proper highlighting):
<pre lang='something'>
<code>
The code...
</code>
</pre>
However, my markdown code has the following:
<pre>
<code>
:::something
The code...
</code>
</pre>
I think you can see where this is going. What I want to achieve is this:
:::something
should be removed, and the<pre>
tag should be updated to<pre lang="something">
.- If
:::something
does not exist, the<pre>
tag should be<pre lang="plain">
- There may be multiple occurrences per page that need to be updated.
How would a PHP function achieving the above look like?
function set_syntax_lang($content) {
// Do stuff here
return $new_content;
}
What I gathered so far is this regex:
/<pre.*>\s*<code>\s*:::(\w)/
This even yields me, using preg_match
, the actual syntax indicator (something
), but I don't know how to update the pre
-tag correctly.
It's been a very long time since I coded PHP and regexes are not really my strong suit. So all help is appreciated.