Skip to content

Commit

Permalink
Added support for multi word info string as in spec.
Browse files Browse the repository at this point in the history
Related issue: shurcooL/markdownfmt#58

Signed-off-by: Bartlomiej Plotka <bwplotka@gmail.com>
  • Loading branch information
bwplotka authored and Kunde21 committed Oct 28, 2020
1 parent cfdc058 commit 26e9006
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
32 changes: 11 additions & 21 deletions markdown/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
8 changes: 8 additions & 0 deletions markdown/testfiles/reference.same.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down

0 comments on commit 26e9006

Please sign in to comment.