Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Marked's extension system #31

Open
kazk opened this issue Oct 21, 2021 · 3 comments
Open

Compatibility with Marked's extension system #31

kazk opened this issue Oct 21, 2021 · 3 comments
Assignees
Milestone

Comments

@kazk
Copy link
Member

kazk commented Oct 21, 2021

Export the extension as a custom Renderer class (or a function that returns an object with Renderer interface) so that it's compatible with Marked's extension system.

Instead of

process(marked, markdown, { language: 'javascript' });

do

marked(markdown, { renderer: new Renderer({ language: 'javascript' }) });
marked(markdown, { renderer: renderer({ language: 'javascript' }) });

This way, we can override or adjust something when necessary in our apps, or experiment before including it here. This also makes some options like extensions unnecessary.

@kazk kazk added this to the v1 milestone Oct 21, 2021
This was referenced Oct 21, 2021
@jhoffner
Copy link
Member

We might want to rename extensions to something else, like blockExtensions – since they are really about extending the block syntax and we need to know the extension name (otherwise we will assume it is a language).

@kazk
Copy link
Member Author

kazk commented Oct 21, 2021

extensions shouldn't be necessary if we make it compatible. This extension shouldn't be handling them.

If I'm understanding how Marked's extension works correctly, users can either:

  • do marked.use(thisExtension, customExtension). customExtension provides new %foo, then fall backs to this extension for anything else.
  • create CustomRenderer that inherits from this extension's Renderer that handles anything new and fall backs to this extension.

If the extension needs something like afterRender. It can be exposed from the custom renderer that extends this one.

const renderer = new CustomRenderer(options); // inherits from this extension's
const html = marked(markdown, { renderer });
// After inserting to document
renderer.afterRender();

@JulianLang
Copy link

I like the idea for the given reasons, too. Are there any updates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants