gomarkdown / markdown

markdown parser and HTML renderer for Go
Other
1.34k stars 170 forks source link

Implement support for inline element attributes #278

Open aleybovich opened 1 year ago

aleybovich commented 1 year ago

I needed to add target="_blank" to my links, and I tried [text](url){:target="_blank"}. It doesn't work - it renders <a href="url">text</a>{:target="_blank"} so it doesn't recognize attributes in curly braces and treats them as just text

kjk commented 1 year ago

Please create and share full example showing the problem, e.g. starting with https://go.dev/play/p/5fCza6W-r_m

https://blog.kowalczyk.info/article/cxn3/advanced-markdown-processing-in-go.html#modify-ast-tree shows how you can do this by post-processing ast tree.

Also make sure you're using the right parser and html renderer flags:

weberc2 commented 3 months ago

I think I'm having a similar issue: it seems like the attributes are getting applied to a <p> tag which is wrapping the element, rather than being applied to the element itself. In this case, I'm trying to get the text to flow around the image like I would with <img ... align=left>:

image

The input markdown is:

{align="left" style="object-fit:scale-down"}
![Fallout cover art](/assets/posts/fallout-macos-install/fallout.jpg)Having

My extensions are: parser.CommonExtensions&^parser.MathJax | parser.Attributes