-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support markdown descriptions (#18)
- Loading branch information
1 parent
9d98fd3
commit 22c440d
Showing
15 changed files
with
346 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,4 @@ MD013: | |
tables: false | ||
|
||
# MD033/no-inline-html - Inline HTML | ||
MD033: | ||
allowed_elements: | ||
- br | ||
MD033: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
internal/jsonschema/templates/markdown.tpl.md | ||
internal/markdown/testdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
#!/usr/bin/env bash | ||
set -o errexit -o errtrace -o nounset -o pipefail | ||
|
||
update="" | ||
if [[ "${UPDATE:-}" != "" ]]; then | ||
update="-update" | ||
fi | ||
|
||
go mod tidy | ||
go test --coverprofile=coverage.out ./... | ||
go test --coverprofile=coverage.out ./... "${update}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package markdown | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
|
||
"github.com/tdewolff/minify/v2" | ||
mhtml "github.com/tdewolff/minify/v2/html" | ||
"github.com/yuin/goldmark" | ||
"github.com/yuin/goldmark/extension" | ||
"github.com/yuin/goldmark/parser" | ||
"github.com/yuin/goldmark/renderer/html" | ||
) | ||
|
||
func newConverter() goldmark.Markdown { | ||
return goldmark.New( | ||
goldmark.WithExtensions( | ||
extension.GFM, | ||
extension.Footnote, | ||
), | ||
goldmark.WithParserOptions( | ||
parser.WithAutoHeadingID(), | ||
), | ||
goldmark.WithRendererOptions( | ||
// html.WithHardWraps(), | ||
html.WithXHTML(), | ||
), | ||
) | ||
} | ||
|
||
func newMinifier() *minify.M { | ||
// cspell: words mhtml | ||
m := minify.New() | ||
m.AddFunc("text/html", mhtml.Minify) | ||
m.Add("text/html", &mhtml.Minifier{ | ||
KeepQuotes: true, | ||
}) | ||
return m | ||
} | ||
|
||
// ToHTMLBytes converts the given byte array to HTML. | ||
func ToHTMLBytes(markdown []byte) ([]byte, error) { | ||
converted := &bytes.Buffer{} | ||
if err := newConverter().Convert(markdown, converted); err != nil { | ||
return nil, fmt.Errorf("convert error: %w", err) | ||
} | ||
minified := &bytes.Buffer{} | ||
if err := newMinifier().Minify("text/html", minified, converted); err != nil { | ||
return nil, fmt.Errorf("minify error: %w", err) | ||
} | ||
b := minified.Bytes() | ||
b = bytes.ReplaceAll(b, []byte("\n"), []byte(" ")) | ||
b = bytes.ReplaceAll(b, []byte("|"), []byte("|")) | ||
return b, nil | ||
} | ||
|
||
func ToHTMLString(markdown string) (string, error) { | ||
buf, err := ToHTMLBytes([]byte(markdown)) | ||
return string(buf), err | ||
} |
Oops, something went wrong.