pablo-abc / svelte-markdown

Markdown parser to svelte components
MIT License
359 stars 50 forks source link

code formatting #24

Closed magick93 closed 3 years ago

magick93 commented 3 years ago

Is there anything additional I need to do to get code formating to work?

The markdown I'm using is (the \ only to the below so the code can be rendered in GH):

\```
const getAdapters = (adapt) => {
    // eslint-disable-next-line no-console
    console.log(`adapter is ${adapt}`);
    switch (adapt) {
        case 'node':
            return nodeAdapter;
        case 'static':
            return staticAdapter;
        case 'netlify':
            return netlifyAdapter;
        case 'vercel':
            return vercelAdapter;
        default:
            return nodeAdapter;
    }
};
\```

When rendered, the output is exactly as the input.

Thanks

pablo-abc commented 3 years ago

Hi! Nope, that's it. marked (and thus svelte-markdown) just put that in a <pre><code> block. <pre> should keep the formatting just as-is unless your CSS is somehow messing with that.

magick93 commented 3 years ago

Ok.

This is what is being rendered: - while the <pre> and <code> tags are there, notice the 3 ticks at the beginning and ending are preserved. Whereas in Github the <pre> and <code> replace the ticks.

<pre class=""><code>```
const getAdapters = (adapt) =&gt; {
    // eslint-disable-next-line no-console
    console.log(`adapter is ${adapt}`);
    switch (adapt) {
        case 'node':
            return nodeAdapter;
        case 'static':
            return staticAdapter;
        case 'netlify':
            return netlifyAdapter;
        case 'vercel':
            return vercelAdapter;
        default:
            return nodeAdapter;
    }
};
```</code></pre>
pablo-abc commented 3 years ago

~Do you have an example of how you're rendering it? Depending on how you're obtaining the code, you might need to escape the back-ticks.~ Nevermind. I managed to reproduce this. Let me check why this is happening!

pablo-abc commented 3 years ago

Fixed in 0.1.12, feel free to close this if it's working for you as well

pablo-abc commented 3 years ago

I'm closing this since there was no further follow ups. If this still does not work for you somehow, feel free to reopen it.