russross / blackfriday

Blackfriday: a markdown processor for Go
Other
5.43k stars 598 forks source link

Proposal to extend blackfriday to allow HTML elements to be overridden #259

Open zxchris opened 8 years ago

zxchris commented 8 years ago

I've a project that has a theme'able presentation, which serves github flavoured markdown as well as other content. Since blackfriday contains hardcoded static HTML elements, its rendered output is not adjustable to match a theme without replacing most, if not all of https://github.com/russross/blackfriday/blob/master/html.go for each theme.

I propose to modify html.go to reference HTML elements from a map, perhaps exposed through the renderer instance. This allows applications to change any HTML elements used for rendering if, and as, they feel necessary. In my project, a theme would include an appropriate GFM->HTML mapping YAML/JSON file, which my application would parse and then modify the renderer map.

Of course I could just provide my own renderer methods which use a map as I have described, but I would effectively be duplicating the entire of html.go, which would need to be kept in sync with rusross/blackfriday.

I feel this feature would be a valuable addition to blackfriday. But is there another way?

Just wanted to check your thoughts on this before I do the work and submit a (hopeful) pull request ;-)

Chris

rtfb commented 8 years ago

It sounds like v2 might be much more mendable for this kind of customization. Here's an example of using v2: https://gist.github.com/rtfb/08babeb67d37514f5322722797a6bd6a. Can you give it a try?

It's still not final in the sense that I'm still willing to change public interface freely, but it's a good opportunity to chime in and influence that interface towards your needs.

kulak commented 7 years ago

I run into this issue and checked out gist referenced by rtfb. It is awesome. I've been looking into ability to assign a CSS class from UIKit to generated markdown elements. The gist does it!