Skip to content

Commit

Permalink
fix(parser): code() dash parsing bug
Browse files Browse the repository at this point in the history
due to the architecture of the inline code element parsing the code() function failed to parse inline code elements containing any special markdown character at the start of the element. This issue occured due to the fact, that i assumed a BACKTICK (`) always has the TEXT as a follow element which was in fact not correct and in retroperspective seems dumb. Whatever, its fixed now!
  • Loading branch information
xNaCly committed Apr 14, 2023
1 parent fce4cd5 commit 15baeaf
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,26 +293,12 @@ func (p *Parser) emphasis() Tag {
}
}

// TODO: possible issue: if no language or type is specified the parser assumes the next line to be the content
// FIXED: inline code elements containing dashes (-) are not parsed correctly
// BUG: if no language or type is specified the parser assumes the next line to be the content
func (p *Parser) code(quoteContext bool) Tag {
p.advance()
if p.check(scanner.TEXT) {
// inline code:
b := strings.Builder{}
for !p.check(scanner.BACKTICK) && !p.check(scanner.NEWLINE) {
if p.check(scanner.TEXT) {
b.WriteString(p.peek().Value)
} else {
b.WriteRune(scanner.TOKEN_SYMBOL_MAP[p.peek().Kind])
}
p.advance()
}
// skip the `
p.advance()
return CodeInline{
text: b.String(),
}
} else if p.check(scanner.BACKTICK) {
scanner.PrintToken(p.peek())
if p.check(scanner.BACKTICK) {
// codeblock:
p.advance()
if !p.check(scanner.BACKTICK) {
Expand Down Expand Up @@ -355,8 +341,23 @@ func (p *Parser) code(quoteContext bool) Tag {
language: language,
text: b.String(),
}
} else {
// inline code:
b := strings.Builder{}
for !p.check(scanner.BACKTICK) && !p.check(scanner.NEWLINE) {
if p.check(scanner.TEXT) {
b.WriteString(p.peek().Value)
} else {
b.WriteRune(scanner.TOKEN_SYMBOL_MAP[p.peek().Kind])
}
p.advance()
}
// skip the `
p.advance()
return CodeInline{
text: b.String(),
}
}
return Text{}
}

func (p *Parser) paragraph() Tag {
Expand Down

0 comments on commit 15baeaf

Please sign in to comment.