Skip to content

Commit

Permalink
markdown link with square braces fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sdfsdhgjkbmnmxc committed May 17, 2021
1 parent 2a57185 commit fadd76c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
9 changes: 3 additions & 6 deletions tdmarkup/markup_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,6 @@ func (s *MarkupScanner) scanChilds(text string) (res []tdproto.MarkupEntity) {
for scanner.Rest() > 0 {
t, e := scanner.Scan(nil)
if e != nil {
if res == nil {
res = make([]tdproto.MarkupEntity, 0)
}
res = append(res, *e)
}
if t == "" {
Expand Down Expand Up @@ -396,7 +393,7 @@ func (s *MarkupScanner) scanMarkdownLinks() (string, *tdproto.MarkupEntity) {

findRepl:
for {
ch := s.TakeNext()
ch = s.TakeNext()
b.WriteRune(ch)
switch ch {
case ']':
Expand All @@ -417,8 +414,8 @@ findRepl:
}

if s.Next() != '(' {
s.Rewind(start)
return "", nil
replBuilder.WriteRune(ch)
goto findRepl
}

ch = s.TakeNext()
Expand Down
1 change: 1 addition & 0 deletions tdmarkup/markup_scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func TestToPlainNoQuotes(t *testing.T) {
})
}
}

func TestParse(t *testing.T) {
for _, v := range MarkupTestCases {
t.Run(v.Title, func(t *testing.T) {
Expand Down
21 changes: 13 additions & 8 deletions tdmarkup/testdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ var MarkupTestCases = []struct {
},
{
Title: "markdown link with smile",
Raw: `[=(](app://path)`,
Raw: `[ =( ](app://path)`,
Html: `<a href="app://path">=(</a>`,
Plain: "=(",
},
Expand All @@ -450,11 +450,16 @@ var MarkupTestCases = []struct {
Html: `[ ](https://ya.ru)`,
Plain: `[ ](https://ya.ru)`,
},
// TODO:
//{
// Title: "markdown link with square brace",
// Raw: `[[x]](app://path)`,
// Html: `<a href="app://path">[x]</a>`,
// Plain: "[x]",
//},
{
Title: "markdown link with square braces",
Raw: `[[x]](app://path)`,
Html: `<a href="app://path">[x]</a>`,
Plain: "[x]",
},
{
Title: "markdown link with one square brace",
Raw: `[x]y](app://path)`,
Html: `<a href="app://path">x]y</a>`,
Plain: "x]y",
},
}

0 comments on commit fadd76c

Please sign in to comment.