fix codeblock ending
This commit is contained in:
parent
496d9a21d8
commit
e1d454085a
|
@ -30,16 +30,16 @@ func NewCodeBlockFromTokens(p ReadUnreader) (ParseResult, bool) {
|
|||
return ParseResult{}, false
|
||||
}
|
||||
for {
|
||||
ntoks, ok := p.Read(1)
|
||||
ntoks, ok := p.Read(2)
|
||||
if !ok {
|
||||
p.Unread(len(toks))
|
||||
return ParseResult{}, false
|
||||
}
|
||||
tok := ntoks[0]
|
||||
if tok.Equal(delimiter) {
|
||||
if ntoks[0].Equal(delimiter) && (ntoks[1].Type == token.TYPE_NEWLINE || ntoks[1].Equal(token.TOKEN_EOF)) {
|
||||
break
|
||||
}
|
||||
toks = append(toks, tok)
|
||||
p.Unread(1)
|
||||
toks = append(toks, ntoks[0])
|
||||
}
|
||||
|
||||
cb := CodeBlock{}
|
||||
|
|
|
@ -42,6 +42,20 @@ more
|
|||
}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "with newline at end",
|
||||
input: `----
|
||||
code
|
||||
----
|
||||
`,
|
||||
exp: &adoc.ADoc{
|
||||
Attributes: map[string]string{},
|
||||
Content: []element.Element{element.CodeBlock{
|
||||
element.Word("code"),
|
||||
element.WhiteSpace("\n"),
|
||||
}},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "missing end",
|
||||
input: `----
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"ewintr.nl/adoc"
|
||||
"ewintr.nl/adoc/element"
|
||||
"ewintr.nl/adoc/parser"
|
||||
"ewintr.nl/go-kit/test"
|
||||
)
|
||||
|
@ -19,6 +20,41 @@ func TestParser(t *testing.T) {
|
|||
name: "empty",
|
||||
exp: adoc.New(),
|
||||
},
|
||||
{
|
||||
name: "codeblock paragraph edge",
|
||||
input: `= some title
|
||||
|
||||
----
|
||||
a code block
|
||||
----
|
||||
|
||||
And then some text`,
|
||||
exp: &adoc.ADoc{
|
||||
Title: "some title",
|
||||
Attributes: map[string]string{},
|
||||
Content: []element.Element{
|
||||
element.CodeBlock{
|
||||
element.Word("a"),
|
||||
element.WhiteSpace(" "),
|
||||
element.Word("code"),
|
||||
element.WhiteSpace(" "),
|
||||
element.Word("block"),
|
||||
element.WhiteSpace("\n"),
|
||||
},
|
||||
element.Paragraph{
|
||||
Elements: []element.Element{
|
||||
element.Word("And"),
|
||||
element.WhiteSpace(" "),
|
||||
element.Word("then"),
|
||||
element.WhiteSpace(" "),
|
||||
element.Word("some"),
|
||||
element.WhiteSpace(" "),
|
||||
element.Word("text"),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
par := parser.New(strings.NewReader(tc.input))
|
||||
|
|
Loading…
Reference in New Issue