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

Parse only nodeTypes and output remainder unchanged #408

Closed
justrealmilk opened this issue Apr 3, 2020 · 14 comments
Closed

Parse only nodeTypes and output remainder unchanged #408

justrealmilk opened this issue Apr 3, 2020 · 14 comments
Labels
👀 no/external This makes more sense somewhere else 🙋 no/question This does not need any changes

Comments

@justrealmilk
Copy link

Hi! Weird request... Maybe.

I'd like to parse some text as markdown and only convert for paragraphs, leaving the remainder as is.

The text, in places, uses characters shared by markdown syntax, but I don't wish to parse them as such - just paragraphs.

allowedTypes={['text', 'paragraph']} achieves part of this but removes other nodes that match markdown syntax.

I'm unsure of exactly how plugins work and how I could use one to achieve this, if it's even possible.

I wrote a render helper to conditionally turn links into react-router Link components but this would require some sort of catch-all and again I'm unsure if the input would get to this point if it matched disallowed markdown syntax

@johndetlefs
Copy link

I have exactly the same issue... basically looking for a "renderDisallowedTypesAsText" option.

@gnapse
Copy link

gnapse commented Jun 9, 2020

One more request for this feature here. We basically need to use markdown only for non-block elements (links, bold, italics, strike-through) but we don't want any other syntax to be processed or even removed. We're processing in a certain context text that is not meant to be multi-line. Hence, if the user types "> is the greater-than symbol" we want that to appear as is. Same for heading syntax, list item syntax, etc.

I started achieving this with custom renderers for most block element types. But for cases like list items, I have no way of knowing the character used (-, +, *). It worked for blockquote and heading though.

@henrik-d
Copy link

Instead of using allowedTypes I ended up using the remark-disable-tokenizers plugin, to set types that should be ignored by the underlaying markdown-parser.

See this comment for an example.

@gnapse
Copy link

gnapse commented Jun 11, 2020

Indeed. I came here to say the same thing, as a colleague in our team also found out about this and suggested it. It worked like a charm for us.

@ChristianMurphy ChristianMurphy added 👀 no/external This makes more sense somewhere else 🙋 no/question This does not need any changes labels Oct 8, 2020
@ChristianMurphy
Copy link
Member

using a remark plugin is the preferred solution, see #408 (comment)

@janpe
Copy link

janpe commented Jun 18, 2021

Is there a way of doing this in v6? The plugin doesn't seem to work anymore.

@janpe
Copy link

janpe commented Jun 18, 2021

@ChristianMurphy maybe this could be reopened since it doesn't seem to be possible with the current react-markdown version.

@ChristianMurphy
Copy link
Member

@janpe how to migrate allow types to the v6 equivalent is documented in the changelog https://github.com/remarkjs/react-markdown/blob/main/changelog.md#replace-allownode-allowedtypes-and-disallowedtypes

@janpe
Copy link

janpe commented Jun 21, 2021

But I want to achieve the same thing as this issue describes. I want to skip parsing certain nodes as markdown and just render them as paragraphs. For example I would like for - One to output that as paragraph instead of unordered list. Disallowed elements are removed altogether.

@ChristianMurphy
Copy link
Member

But I want to achieve the same thing as this issue describes.

If you want to use the exact solution described previously feel free to contribute to zestedesavoir/zmarkdown#416

Disallowed elements are removed altogether.

Not necessarily, unwrapDisallowed can be used to keep/unwrap the content.

@janpe
Copy link

janpe commented Jun 21, 2021

unwrapDisallowed strips the - character (in my example) and outputs the rest raw, doesn't it? I don't prefer any solution over another, but I'm just interested if this is currently achievable in any way altogether. I migrated from v4 to v6 and I now have this problem and wouldn't prefer to downgrade back to v4. Thanks for your quick replies!

@ChristianMurphy
Copy link
Member

outputs the rest raw, doesn't it?

I'd highly recommend reading the Readme and particularly the description of the option.
The answer is there.

achievable in any way altogether

It is, a few options have been outlined above.
If you are interested in more options or have further questions https://github.com/remarkjs/remark/discussions is a better venue than a closed issue.

@janpe
Copy link

janpe commented Jun 21, 2021

I'd highly recommend reading the Readme and particularly the description of the option.
The answer is there.

Sorry if I'm misunderstading something. I have read the readme and the descriptions of all the options and tried them out in code as well. That particular option seems to be doing what I just described above. If again I'm not misunderstading something.

It is, a few options have been outlined above.

I'm not certain about what you are referring to here. I'm not seeing any options that seem to be working and I'm not seeing a way of achieving this now that remark-disable-tokenizers is broken. Or are you referring to the fact that I could contribute to the issue that you mentioned?

Are there ways of having custom remark plugins in my codebase and using those with react-markdown? If so is there documentation on how to go about doing that?

Thanks again!

@ChristianMurphy
Copy link
Member

ChristianMurphy commented Jun 21, 2021

There seems to be some confusion, let's back up a bit.
remark and react-markdown are part of Unified https://unifiedjs.com, which provides a consistent way of interacting with content ASTs.
There is documentation on working with ASTs, creating plugins, and recipes for common use cases at https://unifiedjs.com/learn
As part of unified it also follows unified's contributing guidelines, including recommendations on how to get support and ask questions which can effectively answered https://github.com/remarkjs/.github/blob/main/support.md, as well as the guideline that the issue tracker is used for bugs and features for that specific repository (https://github.com/remarkjs/.github/blob/main/.github/ISSUE_TEMPLATE/1-bug.md, questions should be directed to https://github.com/remarkjs/remark/discussions, and bugs in a specific repo should be directed to that repo.

react-markdown itself is a utility for going from markdown to react.
It supports commonmark markdown.
If kind-markdown-like syntax, or extensions are needed those go into plugins.

Hence this is marked as a question and external, and is closed.


The answer is there.

... particular option seems to be doing what I just described above

yes, what you described and what is documented match up.
That's what it does.

I'm not certain about what you are referring to here. I'm not seeing any options that seem to be working and I'm not seeing a way of achieving this now that remark-disable-tokenizers is broken. Or are you referring to the fact that I could contribute to the issue that you mentioned?

Let me spell this out more explicitly.

  1. remark-disable-tokenizers is not broken, it works fine with react-markdown 4
  2. if you want to use remark-disable-tokenizers with react-markdown 6, contribute to remark@next (13) zestedesavoir/zmarkdown#416
  3. if you are looking for alternatives, continue the discussion on Github Discussions remark-disable-tokenizers not working with remark 13, options? remark#757

Are there ways of having custom remark plugins in my codebase and using those with react-markdown? If so is there documentation on how to go about doing that?

Yes, https://unifiedjs.com/learn documents working with plugins.
react-markdown 6 supports both remark and rehype plugins, there is an example of this in the readme https://github.com/remarkjs/react-markdown#use-a-plugin
Any code which can be imported/required and matches the plugin interface can be used, whether it is local, hosted on NPM, or provided though another package manager.

@remarkjs remarkjs locked as resolved and limited conversation to collaborators Jun 21, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
👀 no/external This makes more sense somewhere else 🙋 no/question This does not need any changes
Development

No branches or pull requests

6 participants