gomarkdown / markdown

markdown parser and HTML renderer for Go
Other
1.42k stars 176 forks source link

Code blocks support `meta` fields #320

Closed tylermmorton closed 3 weeks ago

tylermmorton commented 3 weeks ago

Code blocks in markdown can have an optional meta field directly after the lang option:

```go <meta>
package main

func main() {
   ...
}

Currently the gomarkdown parser fails to parse this and bails early. It would be useful if support for this meta value could be added to the parser and AST node.

My use case is being able to name files using the meta key:
package main

func main() {
   ...
}

Or provide a comma separated array of data:
package main

func main() {
   ...
}
kjk commented 3 weeks ago

Fixed with https://github.com/gomarkdown/markdown/commit/6bc1ffdc6e8c00d315151dead024d04d45421384

Now CodeBlock.Info will contain the whole line e.g. go main.go,readonly (was parsing up to space, so before it would only be go).

It's up to you to do further processing and e.g. split it into go lang and main.go, readonly meta values.