jonschlinkert / remarkable

Markdown parser, done right. Commonmark support, extensions, syntax plugins, high speed - all in one. Gulp and metalsmith plugins available. Used by Facebook, Docusaurus and many others! Use https://github.com/breakdance/breakdance for HTML-to-markdown conversion. Use https://github.com/jonschlinkert/markdown-toc to generate a table of contents.
https://jonschlinkert.github.io/remarkable/demo/
MIT License
5.75k stars 373 forks source link

Plugin Documentation #364

Open xErik opened 5 years ago

xErik commented 5 years ago

Thank you for providing Remarkable.

I'd like to write plugins but the available documentation is more of an internal documentation.

I am also unsure whether every plugin is simply applied in a row during runtime - and then the plugin decides whether to process the input or not? As this means a plugin is not explicitly registered with a MARKDOWN-TAG like:

.addPlugin('MARKDOWN-TAG', isInlineOrBlock, function() {some-plugin-code})

It would be helpful to have a recipe for a simple BLOCK-Plugin with parsing and rendering from start to end:

@@@
la
la
la
@@@

As well as how to handle an INLINE-Plugin which overwrites an existing plugin, like code:

\`render me differently\`
antoniojps commented 4 years ago

I really wish the plugin documentation would have some examples.

I'm having some real hard time figuring out how to write my own plugin. I need to read the source code of the project + source codes of other plugins.

Don't take me wrong, I know writing documentation + maintaining is hard work and I thank the maintainers for doing this.

Here's a useful resource I've found. https://github.com/facebook/docusaurus/blob/master/admin/extending-remarkable.md

omenking commented 4 years ago

No matter the examples I find it hard to piece the most simple example.

bradhowes commented 4 years ago

FYI, I wrote my own plugin that handles embedded KaTex. The code is fairly straightforward I think: index.js

There are three basic components:

The first two push tokens onto the state stack when they find something interesting in the text range given to them by the state. They push an object that tells Remarkable rendering what the range of text to render with a named render function. The last function is just using the token pushed earlier to get to the content to use for rendering. In my case this content is KaTeX code that generates mathematical expressions.

My blog repo has additional customization examples. See https://github.com/bradhowes/keystrokecountdown (scroll down to Remarkable Customizations section). I show how I was able to customize fence block rendering to use Prism highlight. I also show how to handle async rendering which I needed when generating SVG files from Graphviz DOT specs.