From 15baeaf5985c4980e204200707bafea6ab452c89 Mon Sep 17 00:00:00 2001 From: xnacly <47723417+xNaCly@users.noreply.github.com> Date: Fri, 14 Apr 2023 08:55:03 +0200 Subject: [PATCH] fix(parser): code() dash parsing bug 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! --- parser/parser.go | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/parser/parser.go b/parser/parser.go index 46c338e..32faec8 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -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) { @@ -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 {