[Publish] I found a way to force markdown inside code blocks

Okay, so, for two month, I test Publish to help my classmate during our revision and examen.

As I use a lot Admonition, I use the publish.js to render my admonition. Unfortunately, It doesn’t support markdown…
Until I work a day on it.
(A day because I forgot to edit one word)

So, how can I do that ?

I first add :

function injectScript(src) {
        return new Promise((resolve, reject) => {
        const script = document.createElement('script');
        script.src = src;
        script.addEventListener('load', resolve);
        script.addEventListener('error', e => reject(e.error));
        document.body.appendChild(script);
    });
}


injectScript('https://cdn.jsdelivr.net/npm/marked/marked.min.js')
    .then(() => {
        console.log("script loaded");
    }).catch(error  => {
    console.log(error);
    });

In the start of my publish.js file.

After, I looking for a lot and edit the admonitionContent.innerHTML = content; in processAdmonitionBlock.
The new line is admonitionContent.innerHTML = marked.parse(content);

And I do some… Try.

Also, note : it doesn’t work with Wikilinks (obviously).

image

You can see here the live rendering :
Live rendering

For the moment my problem is around the way Obsidian charge the JavaScript, but I think this trick can help on some Jekyll template, to force admonition view.

It is possible that you need to reload two times to get the parser to work.