pngwn / MDsveX

A markdown preprocessor for Svelte.
https://mdsvex.pngwn.io
MIT License
2.27k stars 96 forks source link

Importing `markdown-it` inside an MDsveX file spells doom #32

Closed happycollision closed 4 years ago

happycollision commented 4 years ago

That's pretty much it. Even if you try and import via a Svelte component that uses it, you are toast. So I just switched to using marked for my runtime Markdown renders.

pngwn commented 4 years ago

Do you get any errors specifically or does it just silently fail? I'm actually changing to a different parser in a current rewrite but I'd like to understand what is happening here.

happycollision commented 4 years ago

The only message in the terminal is the giant blob of json which seems to come from about line 6098 of node_modules/markdown-it/dist/markdown-it.js

✗ client
Unexpected token (Note that you need rollup-plugin-json to import JSON files)
1: {"Aacute":"\u00C1","aacute":"\u00E1","Abreve":"\u0102","abreve":"\u0103","ac":"\u223E","acd":"\u223F","acE":"\u223E\u0333","Acirc":"\u00C2","acirc":"\u00E2","acute":"\u00B4","Acy":"\u0410","acy":"\u0430","AElig":"\u00C6","aelig":"\u00E6","af":"\u2061", ETC, ETC, ETC}

(ETC is a placeholder for a lot more)

pngwn commented 4 years ago

You would get this error if you were just using markdown-it on its own. markdown-it uses some JSON files as well as javascript and rollup doesn't handle them by default.

The solution is in the message: Note that you need rollup-plugin-json to import JSON files if you install and apply rollup-plugin-json (which is now @rollup/plugin-json) then this error would go away.

You would, however, get another error regarding punycode and you'd have to provide an alternative for that in the browser.

The short version of all of this is that markdown-it is a pain to use in the browser and has a few quirks which are just some of the reasons I'm moving away from it.

happycollision commented 4 years ago

Actually, @pngwn, I was using markdown-it just fine when NOT using MDsveX. I could literally transcribe the MDsveX template to Svelte and the error disappeared and my markdown rendered. So, I don’t think it is a Rollup issue.

Or if it is, it is being surfaced by the combination of MDsveX and markdown-it together.

pngwn commented 4 years ago

If I install markdown-it and try to use it in a Svelte component without mdsvex i get the same errors and those errors are expected given the nature of markdown-it's dependencies, so I'm not sure why mdsvex would be causing these issues.