Skip to content

Commit fea4310

Browse files
committed
feat(parser): quoteContext param parser.code
This new function parameter helps the code parsing function by indicating if it is currently operating in a quote context. This enables the removal of > inside of the code block parsing logic.
1 parent ccdc7c7 commit fea4310

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

parser/parser.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func (p *Parser) tag() Tag {
3838
return p.quote()
3939
return p.img()
4040
} else if p.check(scanner.BACKTICK) {
41-
return p.code()
41+
return p.code(false)
4242
} else if p.check(scanner.HASH) && (p.prev().Kind == scanner.EMPTYLINE || p.prev().Kind == 0) {
4343
return p.heading()
4444
} else {
@@ -257,7 +257,8 @@ func (p *Parser) emphasis() Tag {
257257
}
258258
}
259259

260-
func (p *Parser) code() Tag {
260+
// TODO: possible issue: if no language or type is specified the parser assumes the next line to be the content
261+
func (p *Parser) code(quoteContext bool) Tag {
261262
p.advance()
262263
if p.check(scanner.TEXT) {
263264
// inline code:
@@ -292,6 +293,14 @@ func (p *Parser) code() Tag {
292293

293294
b := strings.Builder{}
294295
for !p.check(scanner.BACKTICK) {
296+
if quoteContext && (p.prev().Kind == scanner.NEWLINE || p.prev().Kind == scanner.EMPTYLINE) {
297+
// skips the > and the space at the start of the line in a quoted context
298+
p.advance()
299+
if p.peek().Value == " " {
300+
p.advance()
301+
}
302+
continue
303+
}
295304
if p.check(scanner.TEXT) {
296305
b.WriteString(p.peek().Value)
297306
} else {
@@ -318,12 +327,11 @@ func (p *Parser) paragraph() Tag {
318327
children := make([]Tag, 0)
319328
// paragraph should only contain inline code, italic and bold or text
320329
for !p.check(scanner.EMPTYLINE) && !p.isAtEnd() {
321-
// TODO: add link case here
322330
switch p.peek().Kind {
323331
case scanner.STRAIGHTBRACEOPEN:
324332
children = append(children, p.link())
325333
case scanner.BACKTICK:
326-
children = append(children, p.code())
334+
children = append(children, p.code(false))
327335
case scanner.STAR, scanner.UNDERSCORE:
328336
children = append(children, p.emphasis())
329337
case scanner.TEXT:

0 commit comments

Comments
 (0)