markdown icon indicating copy to clipboard operation
markdown copied to clipboard

Implement support for inline element attributes

Open aleybovich opened this issue 2 years ago • 3 comments

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

aleybovich avatar Mar 14 '23 14:03 aleybovich

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:

  • https://pkg.go.dev/github.com/gomarkdown/markdown/html#Flags
  • https://pkg.go.dev/github.com/gomarkdown/markdown/parser#Extensions

kjk avatar Mar 14 '23 18:03 kjk

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

weberc2 avatar Apr 28 '24 13:04 weberc2

yes this is bug, iirc the attributes apply to to the next element, not sure if there is a clean solution (or rework the attributes entirely)

miekg avatar Jan 07 '25 15:01 miekg