russross / blackfriday

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

allow writing of user-specified <meta.../> tags to document header #541

Open gbmor opened 5 years ago

gbmor commented 5 years ago

Added a field to the Html struct that holds a map[string]string. HtmlRendererWithParameters() then returns an Html struct with the map initialized. The user may then specify <meta.../> tags to be included in the document header when the document is parsed (and HTML_COMPLETE_PAGE is flagged).

renderer := HtmlRenderer(HTML_COMPLETE_PAGE, "Title", "style.css")
renderer.meta["name=\"author\""] = "foo barrington"
renderer.meta["http-equiv=\"refresh\""] = "1; url=http://localhost"
etc...

With the key being the full attribute of name="..." or http-equiv="...", and value being the unquoted value of the attribute contents="..."

The reason for this was I needed a way to inject <meta.../> tags into a rendered document for one of my projects. I thought, "Doing it after the document is parsed doesn't seem right or efficient, so why not do it during the markdown->html/xhtml translation?".