remarkjs / remark

markdown processor powered by plugins part of the @unifiedjs collective
https://remark.js.org
MIT License
7.66k stars 358 forks source link

Add `remark-obsidian-callout` to list of plugins #1143

Closed escwxyz closed 1 year ago

escwxyz commented 1 year ago

Initial checklist

Description of changes

This PR adds the plugin remark-obsidian-callout to the list of plugins, also seen on npm.

codecov-commenter commented 1 year ago

Codecov Report

Merging #1143 (c00117f) into main (1e488d0) will not change coverage. The diff coverage is n/a.

:mega: This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files [![Impacted file tree graph](https://codecov.io/gh/remarkjs/remark/pull/1143/graphs/tree.svg?width=650&height=150&src=pr&token=tky2ILBZa0&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=remarkjs)](https://codecov.io/gh/remarkjs/remark/pull/1143?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=remarkjs) ```diff @@ Coverage Diff @@ ## main #1143 +/- ## ========================================= Coverage 100.00% 100.00% ========================================= Files 10 10 Lines 906 906 ========================================= Hits 906 906 ``` ------ [Continue to review full report in Codecov by Sentry](https://codecov.io/gh/remarkjs/remark/pull/1143?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=remarkjs). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=remarkjs) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://codecov.io/gh/remarkjs/remark/pull/1143?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=remarkjs). Last update [1e488d0...c00117f](https://codecov.io/gh/remarkjs/remark/pull/1143?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=remarkjs). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=remarkjs).
wooorm commented 1 year ago

Hi there!

This should be a rehype plugin. rehype is for HTML. remark is for markdown. You work with HTML. So you should work on the HTML AST. Some more info on this can be found here: https://github.com/remarkjs/remark-rehype#what-is-this

remark/rehype/rest of unified are also about ASTs. So, you have an object that represents a paragraph, with children, for example. You inject strings of HTML. Strings of HTML for the divs, strings of HTML for the icons. Injecting strings defeats the purpose of having ASTs. Other plugins can’t inspect them. They can’t be made safe. They don‘t work with MDX for example, or many other tools. There are many examples of rehype plugins that you can use as inspiration: https://github.com/rehypejs/rehype/blob/main/doc/plugins.md#list-of-plugins. One that looks somewhat like what you want to do is: https://github.com/rehypejs/rehype-picture/blob/main/index.js

You also use TypeScript, but don’t use the types for the AST. You can use specific types from @types/mdast / @types/hast, they subclass the abstract interfaces from @types/unist into interfaces that are actually used. If you then type your plugin, instead of accepting any, you will find a much better user experience, because everything will be typed. An example of how to type plugins is: https://github.com/remcohaszing/rehype-mdx-title/blob/6832b8c01097da83288319ddaa5d1e460d4e125a/index.ts#L23.

escwxyz commented 1 year ago

Other plugins can’t inspect them. They can’t be made safe. They don‘t work with MDX for example, or many other tools.

You're right, thanks for the detailed explanation and guidance! This was initially for the personal use with Astro, but as you have said, I would consider rewriting for rehype. Thanks!

github-actions[bot] commented 1 year ago

Hi! This was closed. Team: If this was merged, please describe when this is likely to be released. Otherwise, please add one of the no/* labels.

wooorm commented 1 year ago

Cool! :)

Let me know if you have any further questions, good luck!