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

Feature: Rendering hooks #349

Open
sciurius opened this issue Jul 16, 2020 · 3 comments
Open

Feature: Rendering hooks #349

sciurius opened this issue Jul 16, 2020 · 3 comments

Comments

@sciurius
Copy link

GoldMark has a nice feature: you can define your own renderers for specific items, such as links and headings.

See e.g. how Hugo uses this: https://gist.github.com/killbus/f47efbd13d96b437b9d218334508bffb

It would be nice if cmark could do something similar.

@jgm
Copy link
Member

jgm commented Jul 16, 2020

IF you're using cmark as a library, you can do this by walking the AST and converting CMARK_NODE_HEADING blocks to CMARK_CUSTOM blocks. A custom block has an "on enter" and "on exit" text which you can construct from the heading AST element; this will be rendered verbatim in HTML output.

If you're using the command line program, then you might try my lcmark, a small lua wrapper which adds 'filters' that can do what I've just described.

@sciurius
Copy link
Author

sciurius commented Jul 16, 2020

I'm using the Perl bindings (CPAN module CommonMark). I can process the parsed document using the iterator.
Until now I haven't been able to modify (replace) the NODE_LINK node by a NODE_CUSTOM_BLOCK.

It's all very new...

UPDATE: Got it working! Thanks for the crucial pointers.

@sciurius
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants