You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the feature
Publish standard JS modules to npm, instead of UMD.
Why is this feature necessary?
All major browsers can load standard JS modules now, so importing this library becomes much easier.
Reacted by TANIGUCHI Masaya, David Lukava, Russell Bicknell, Steven, Jacob Pratt, István Szmozsánszky, Aki Rodić, dima117, Fabio Spampinato, Charl and 4 more
Some squibbles: If I'm reading this right... if it's used in tandem with UMD (AMD+CJS) I wouldn't mind... however if marked goes JSM/ESM only and distributes on npmjs.com as a CDN only(love all these acronyms) then we'll have to reconsider. We currently use it server side and we aren't going to rely on a CDN being up or down. Already been down that road before and it's very bad. :)
A good way of doing this, might be to leave the IIFE version in tact, but to refactor that same IIFE into modules and classes. I've already done much of the heavy lifting locally. But I'll go ahead and fork this over in my repos to show you what I'm talking about.
Here is my version, this is just a first pass to demonstrate what I'm talking about. https://github.com/telepathic-elements/marked
As you can see, we keep the IIFE, but it's now loading the refactored ES6 modules. I've broken everything out into .mjs files for maintainability purposes. But the usage for existing users would be the same way, while new users should be able to just
import {Marked} from 'marked/libs/marked-class.mjs'
marked = new Marked();
just for people having trouble how to use it: import marked from "marked";
works now fine.
I use it sucessfully in a sveltekit endpoint:
const options = {
mangle: false //do only use this option if you know what you are doing (it preserves email addresses in cleartext
};
const html = marked(page.main, options);
page.main = html;
Activity
UziTech commentedon Jun 10, 2018
A PR would be welcome
Martii commentedon Jun 11, 2018
Some squibbles: If I'm reading this right... if it's used in tandem with UMD (AMD+CJS) I wouldn't mind... however if marked goes JSM/ESM only and distributes on npmjs.com as a CDN only (love all these acronyms) then we'll have to reconsider. We currently use it server side and we aren't going to rely on a CDN being up or down. Already been down that road before and it's very bad. :)
styfle commentedon Jun 13, 2018
I think we would need a build step to support this because AFAIK, detecting ESM at runtime is not possible.
I've used TypeScript + Rollup to support multiple builds with my project: copee
But there was hesitation to add TS to marked 🤔
[-]Standard JS module distribution[/-][+]ESM (ES6 module) distribution[/+]saragarmee commentedon Sep 27, 2018
A good way of doing this, might be to leave the IIFE version in tact, but to refactor that same IIFE into modules and classes. I've already done much of the heavy lifting locally. But I'll go ahead and fork this over in my repos to show you what I'm talking about.
saragarmee commentedon Sep 27, 2018
Here is my version, this is just a first pass to demonstrate what I'm talking about.
https://github.com/telepathic-elements/marked
As you can see, we keep the IIFE, but it's now loading the refactored ES6 modules. I've broken everything out into .mjs files for maintainability purposes. But the usage for existing users would be the same way, while new users should be able to just
To get ES6 class based functionality
styfle commentedon Oct 4, 2018
FYI, for anyone following along: work is being done in PR #1349
It would be good to get more eyes on it.
keywan-ghadami commentedon Sep 4, 2021
just for people having trouble how to use it:
import marked from "marked";works now fine.
I use it sucessfully in a sveltekit endpoint: