diff --git a/README.md b/README.md index b214599..12f6a8c 100644 --- a/README.md +++ b/README.md @@ -1,13 +1,12 @@ markdownfmt =========== -Fork of github.com/shurcooL/markdownfmt that targets: +Fork of github.com/shurcooL/markdownfmt that targets following additions: -* Goldmark to render from parsed markdown AST. +* Goldmark used instead of blackfriday to render from parsed markdown AST +* Full info string support for Fenced Code Block (see [issue](https://github.com/shurcooL/markdownfmt/issues/58)) * Hash-based headers only. - - [![Build Status](https://travis-ci.org/Kunde21/markdownfmt.svg?branch=master)](https://travis-ci.org/Kunde21/markdownfmt) [![GoDoc](https://godoc.org/github.com/Kunde21/markdownfmt?status.svg)](https://godoc.org/github.com/Kunde21/markdownfmt) Like `gofmt`, but for Markdown. diff --git a/markdown/main.go b/markdown/main.go index fab7adc..9fd2268 100644 --- a/markdown/main.go +++ b/markdown/main.go @@ -80,30 +80,20 @@ func (mr *MarkdownFmtRenderer) blockCode(node ast.Node, source []byte) { lang := "" tnode, isFenced := node.(*ast.FencedCodeBlock) - if isFenced { - info := tnode.Info - if info != nil { - lang = string(info.Text(source)) - } - } - // Parse out the language name. - count := 0 - for _, elt := range strings.Fields(lang) { - if elt[0] == '.' { - elt = elt[1:] - } - if len(elt) == 0 { - continue + mr.buf.WriteString("```") + if isFenced && tnode.Info != nil { + mr.buf.Write(tnode.Info.Text(source)) + + for _, elt := range strings.Fields(lang) { + elt = strings.TrimSpace(strings.TrimLeft(elt, ". ")) + if len(elt) == 0 { + continue + } + lang = elt + break } - mr.buf.WriteString("```") - mr.buf.WriteString(elt) - count++ - break } - if count == 0 { - mr.buf.WriteString("```") - } mr.buf.WriteString("\n") mr.buf.Write(mr.leader()) diff --git a/markdown/testfiles/reference.same.md b/markdown/testfiles/reference.same.md index 7728c53..3d6fdd2 100644 --- a/markdown/testfiles/reference.same.md +++ b/markdown/testfiles/reference.same.md @@ -76,6 +76,14 @@ func main() { } ``` +With language and some tags. + +```Go some tags = whatever, but should be preserved. +func main() { + println("Hi.") +} +``` + Here's a table. | Name | Age |