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

Support marked custom extensions #387

Closed
mhamern opened this issue Jun 7, 2022 · 5 comments
Closed

Support marked custom extensions #387

mhamern opened this issue Jun 7, 2022 · 5 comments

Comments

@mhamern
Copy link

mhamern commented Jun 7, 2022

I would like to propose a new feature that would support marked custom extensions. See marked docs.

Custom extensions can be used to define own rules (and renderer and tokenizer) for compiling markdown to html. Its useful for example for supporting tagging (like @ here on Github).

I tried to implement it in my local fork because I need it for something I'm wokin on, so I think I should be able to provide a PR.

However, there are some issues with my implementation, that I would like to discuss first.

  1. we need to extend MarkedOptions class by extensions attribute. The problem here is that marked does not export the MarkedExtension so we have to either use any, provide own type, or create an issue in marked repo to export this interface.

  2. We need to make some changes in MarkdownService because of the implementation of marked. In constructor and setter of options we need to pass the extensions to marked, like this marked.use({extensions: this.options.extensions}). In order to work correctly though we need to change the compile method in MarkdownService. Calling marked with options, as its done now, breaks the extensions. I debugged the marked code and found out, that after calling use, the extensions are processed by marked and its structure is changed a bit (renderer and tokenizer attributes are replace with renderers and tokenizers). Passing options directly to compile overrides the internal structure and extension renderers and tokenizers are not picked up by marked. I think, it would be better to call marked.setOptions (and marked.use if extensions are provided) in options setter and constructor and in compile method, just call marked without options.

As I said, this feature is important to me and I already made it work for my own use case, so I will gladly put a PR for it. @jfcere Whats your idea on the issues mentioned in points 1 and 2? Thanks

@Arxero
Copy link

Arxero commented Jul 3, 2022

I was just looking for this option (for mention people) if possible, and google brought me here, kind of stumped that it is not possible, looking forward to seeing this implemented.

@mike-pisman
Copy link

Hi, I am also want to create some custom extensions for my project. Any updates on this?
@mhamern could you elaborate how managed to implement it for your project?

@mhamern
Copy link
Author

mhamern commented Sep 11, 2023

@mike-pisman Hi, after no response to my issue, I implemented my own very lightweight component and service.

As for questions asked in the issue

  1. I defined my own MarkedOptions class with attribute extensions of type Array<TokenizerExtension | RendererExtension | (TokenizerExtension & RendererExtension)> | undefined

  2. I implemented service where providing marked options (in constructor or by method call) calls marked.use(options) and in compile method, marked is called without the options marked(markdow).

@mike-pisman
Copy link

@mike-pisman Hi, after no response to my issue, I implemented my own very lightweight component and service.

As for questions asked in the issue

1. I defined my own `MarkedOptions` class with attribute extensions of type `Array<TokenizerExtension | RendererExtension | (TokenizerExtension & RendererExtension)> | undefined`

2. I implemented service where providing marked options (in constructor or by method call) calls `marked.use(options)` and in `compile` method, marked is called without the options `marked(markdow)`.

Thank you I will try to do the same

@jfcere
Copy link
Owner

jfcere commented Nov 11, 2023

The update to marked v9 has been completed as part of the ngx-markdown v17.0.0 release and includes the support for marked extensions.

Please make sure to read the release notes as there are breaking changes.

@jfcere jfcere closed this as completed Nov 11, 2023
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

4 participants