On by default? And mermaid option not working
-
I’ve been playing with this plugin, and it’s very powerful and in many ways, exactly what I want out of a markdown plugin. Thank you!
I have one question (possibly complaint) and one bug report.
The bug I found is that the mermaid option isn’t currently working due to the fact that the
pre
tag has a childcode
tag, and that seems to be throwing mermaid.js off.If I add my hack to remove the
code
tag (and put thelanguage-mermaid
class on thepre
tag, it starts working (though there are some JS errors, more on that in a bit): https://a.supportally.com/i/iYih58Here is my hack to remove the code tag, so you can see for yourself:
add_filter( 'the_content', function( $content ) { while ( preg_match( '/<pre><code class="language-mermaid">/', $content ) ) { $location = strpos( $content, '<pre><code class="language-mermaid">' ); $end = strpos( $content, '</code></pre>', $location ); $code = substr( $content, $location, $end - $location + strlen( '</code></pre>' ) ); $code = str_replace( '<pre><code class="language-mermaid">', '<pre class="language-mermaid">', $code ); $code = str_replace( '</code></pre>', '</pre>', $code ); $content = substr_replace( $content, $code, $location, $end - $location + strlen( '</code></pre>' ) ); } return $content; }, 10, 1 );
Adding that to my theme functions file makes the charts render correctly. The JS error is related the Clipboard JS functionality in
front_print_footer_scripts
— it’s expecting thepre
->code
structure, so with my hack code above, the following error happens in the console,jQuery.Deferred exception: codeClass.indexOf is not a function TypeError: codeClass.indexOf is not a function
: https://a.supportally.com/i/yaBAPjThat’s pretty easy to fix. I changed
var codeClass = pre[i].children[0].className;
tovar codeClass = pre[i].className === "mermaid" ? "language-mermaid" : pre[i].children[0].className;
and it cleared up — I wonder if you could make it easier for devs to hook and modify that code… Right now, if I want to keep my hack to make this work, I also need a hack with output buffer to modify that one line of JS that’s hard-coded.
I don’t think my solution with the hack is great — it would be better to fix it at the source, but once I dove intoParsedown
, I gave up.As for the question/complaint — when I activate the plugin, instantly all posts/pages have this markdown editor on by default, despite the post-types being unselected (in the plugin settings) out of the box. My question was how to fix this so it’s off by default, but I just tested a theory by turning them on, saving the settings, then disabling them and saving, and now it seems to have the right default.
- The topic ‘On by default? And mermaid option not working’ is closed to new replies.