diff --git a/common.go b/common.go index 63ae985..62f39d6 100644 --- a/common.go +++ b/common.go @@ -22,7 +22,7 @@ func validStart(pos int, input []rune) bool { } func validEnd(pos int, input []rune) bool { - // First char is not a valid end char. + // First char is not a valid end char; we do NOT allow empty entities. // If the end char has a space before it, its not valid either. if pos == 0 || unicode.IsSpace(input[pos-1]) { return false diff --git a/commonV2.go b/commonV2.go index 8bc9173..355cdca 100644 --- a/commonV2.go +++ b/commonV2.go @@ -148,7 +148,7 @@ func isClosingTag(in []rune, pos int) bool { return false } -func getClosingTag(in []rune, tag string) (int, int) { +func getClosingTag(in []rune, openingTag string, closingTag string) (int, int) { offset := 0 subtags := 0 for offset < len(in) { @@ -164,9 +164,9 @@ func getClosingTag(in []rune, tag string) (int, int) { } closingTagIdx := openingTagIdx + 2 + c - if string(in[openingTagIdx+1:closingTagIdx]) == tag { // found a nested tag, this is annoying + if string(in[openingTagIdx+1:closingTagIdx]) == openingTag { // found a nested tag, this is annoying subtags++ - } else if isClosingTag(in, openingTagIdx) && string(in[openingTagIdx+2:closingTagIdx]) == tag { + } else if isClosingTag(in, openingTagIdx) && string(in[openingTagIdx+2:closingTagIdx]) == closingTag { if subtags == 0 { return openingTagIdx, closingTagIdx } diff --git a/common_test.go b/common_test.go new file mode 100644 index 0000000..11c66c3 --- /dev/null +++ b/common_test.go @@ -0,0 +1,14 @@ +package tg_md2html_test + +import "github.com/PaulSonOfLars/gotg_md2html" + +func testConverter() *tg_md2html.ConverterV2 { + return tg_md2html.NewV2(map[string]string{ + "url": "buttonurl", + "text": "buttontext", + }, map[string]string{ + "primary": "primary", + "success": "success", + "danger": "danger", + }) +} diff --git a/go.mod b/go.mod index 77b6cd7..ac44284 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/PaulSonOfLars/gotg_md2html go 1.19 -require github.com/stretchr/testify v1.8.4 +require github.com/stretchr/testify v1.11.1 require ( github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index fa4b6e6..c4c1710 100644 --- a/go.sum +++ b/go.sum @@ -2,8 +2,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= +github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= diff --git a/md2htmlV2.go b/md2htmlV2.go index 56d3a5a..a750080 100644 --- a/md2htmlV2.go +++ b/md2htmlV2.go @@ -4,31 +4,61 @@ import ( "html" "sort" "strings" + "unicode" ) var defaultConverterV2 = ConverterV2{ Prefixes: map[string]string{ - "url": "buttonurl:", + "url": "buttonurl", + }, + Styles: map[string]string{ + "primary": "primary", + "success": "success", + "danger": "danger", }, SameLineSuffix: sameLineSuffix, } -// ButtonV2 identifies a button. It can contain either a URL, or Text, depending on whether it is a buttonURL: or a buttonText: +// ButtonV2 identifies a button. +// The markdown syntax for a button is as such (where <> represents fields) +// [](:) +// [](::) +// [](#