Raw Node Type #477
Replies: 4 comments 5 replies
-
Hi, I am another person who is a user of Commonmarker and request support for a Raw Node Type. I have two use cases where this feature would be beneficial: 1. Embedding Content from URLsWhen a link in Markdown points to embeddable content, I would like to convert it into embedded HTML. For example, given the following YouTube link: https://www.youtube.com/watch?v=lJIrF4YjHfQ I would like to transform it into: <iframe width="560" height="315" src="https://www.youtube.com/embed/lJIrF4YjHfQ?si=Faw28QGM0TGFxypA" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe> 2. Adding a Copy Button for Code BlocksSimilar to GitHub, I would like to add a "Copy" button to Markdown code blocks, as shown below. |
Beta Was this translation helpful? Give feedback.
-
I think
I don't think a raw HTML type really helps you here? You can find the generated link (or raw text, if not using
This is really not within Comrak's remit; that kind of thing doesn't really belong in your source document. |
Beta Was this translation helpful? Give feedback.
-
It's a while ago since I reported this, so my memory's not perfect. But I think I would have tried this. I tried a few different methods for a raw type, and either I wasn't able to edit the settings (as the package I'm using directly was doing this) or it didn't quite work, and eventually gave up and did it using regexes after writing back out again. I'll take a look again if I come back to this and see what I did. Also, for reference, I'm not rendering to HTML - just using the package to manipulate the document tree. So it'd need to be something that can render out in markdown again, not only for HTML. Thanks! |
Beta Was this translation helpful? Give feedback.
-
Thank you for the information and the code example. I'm developing a web application, and I need to safely escape Markdown text provided by users. However, the system should be able to manipulate the Markdown and insert nodes without escaping them. I believe that if Is there a good solution in the current version of Comrak? Could adding a raw node type be a viable solution? |
Beta Was this translation helpful? Give feedback.
-
Hi,
I'm not consuming Comrak directly but using it through Commonmarker in ruby. I took a look at the node type enum before though and didn't see a clear candidate.
Is it possible to add a node to the document tree that's completely raw text, never to be escaped? If not, would it be possible to add this as a type, and then disallow the adding of children and under no circumstances perform any escaping or processing when rendering?
I'm taking content from a visual editor and performing some processing before handing it off to Zola to generate a static site. Zola makes use of shortcodes, which are in syntax a bit like jinja/liquid. Unfortuately these sections therefore aren't markdown, and comrak is being strictly-compliant and escaping the underscores in some URLs that are within quotes. So right now I think the only sane option I have is to insert some UUIDs and just string-replace after I have written the document back out, which is horrible, but safe at this point.
Thanks
Beta Was this translation helpful? Give feedback.
All reactions