const marked = require('marked');
const html = '<pre>\n<code class="language-mermaid">sequenceDiagram\n  A->>B: Hello\n</code>\n</pre>';
let parsed = html.replace(/<code class="language-mermaid">([\s\S]*?)<\/code>/g, '<div class="mermaid">$1</div>');
parsed = parsed.replace(/<pre>\s*<div class="mermaid">([\s\S]*?)<\/div>\s*<\/pre>/g, '<div class="mermaid">$1</div>');

// also need to decode HTML entities!
const he = require('html-entities');
// wait, we can just write a custom decoding logic or decode standard ones
parsed = parsed.replace(/<div class="mermaid">([\s\S]*?)<\/div>/g, function(match, p1) {
    let unescaped = p1.replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&#39;/g, "'");
    return '<div class="mermaid">' + unescaped + '</div>';
});
console.log('PARSED:', parsed);
