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

I have no idea how to make marked _actually_ ignore specified rules (feature request to turn off specified rules) #2849

Closed
vmarkoski02 opened this issue Jun 14, 2023 · 3 comments

Comments

@vmarkoski02
Copy link

What I want:

I want to be able to turn off specific marked rules so that the marked renderer ignores said rules and leaves the input as is:

  • "`This would be inline-code`" should turn into "`This would be inline-code`" (notice how the backticks and everything else is still there)
  • "# heading" should turn into "# heading" (notice how the hash is still there and it didn't turn into a <h1> tag)
  • ![Why do developers never include their Discord or have open DMs on Twitter?](discord.png) should turn into ![Why do developers never include their Discord or have open DMs on Twitter?](discord.png)
  • etc. I think you get the idea

Why it's necessary

Because some people do not want or need the full markdown feature set.

As an example, I don't want the user to be able to link images using markdown when I am already providing an image uploader feature on my site. I don't want my text to change colors when the user discovers backticks (also I don't want the user to wonder where his backticks went). The only thing I want is the user to be able to make his text bold italic and strikethrough.

What I have tried

I've dug through #420 and the related tickets and have found a few things that looked like they might work. They didn't:

  • "`This would be inline-code`" turned into "This would be inline-code" (notice how the backticks are missing)
  • "# heading" turned into "`heading" (notice how the hash is no longer there)
  • ![Why do developers never include their Discord or have open DMs on Twitter?](discord.png) turned into Why do developers never include their Discord or have open DMs on Twitter?
  • etc.

This almost isn't stupid but it still is stupid, because the user will look at this and wonder "Where have all my special characters gone"?

If there is a way to achieve what I am looking for, please enlighten me. I have done my research, even using AI, and couldn't find the solution to my issue. IMO, this should be something you can configure in the MarkedOptions.

I would greatly appreciate a TypeScript approach to my issue, by the way.

@dlatikaynen
Copy link

You're going to need hooks (https://marked.js.org/using_pro#hooks) or, if that is not sufficient, register extensions to achieve this level of customization.

@vmarkoski02
Copy link
Author

You're going to need hooks (https://marked.js.org/using_pro#hooks) or, if that is not sufficient, register extensions to achieve this level of customization.

I have read the documentation and came to the conclusion that I cannot achieve the desired result with hooks. Perhaps this is just a skill issue though. Would you mind providing an example?

@UziTech
Copy link
Member

UziTech commented Jun 15, 2023

You can see an example extension in the docs. You can also try just changing the tokenizer to return undefined for the tokens you don't want to create.

@UziTech UziTech closed this as completed Aug 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants