Merge pull request #86 from mmarkdown/index-out-of-range

super-subscript: fix index out of range
This commit is contained in:
Miek Gieben 2018-08-25 16:41:52 +01:00 committed by GitHub
commit 0b2c287f3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -22,7 +22,7 @@ func TestMmark(t *testing.T) {
t.Fatalf("odd test tuples: %d", len(testdata))
}
ext := parser.CommonExtensions | parser.Attributes | parser.OrderedListStart | parser.Mmark
ext := parser.CommonExtensions | parser.Attributes | parser.OrderedListStart | parser.SuperSubscript | parser.Mmark
for i := 0; i < len(testdata); i += 2 {
p := parser.NewWithExtensions(ext)

View File

@ -79,7 +79,7 @@ func emphasis(p *Parser, data []byte, offset int) (int, ast.Node) {
return 0, nil
}
ret++ // we started with data[1:] above.
for i := 1; i < ret+1; i++ {
for i := 1; i < ret; i++ {
if isSpace(data[i]) && !isEscape(data, i) {
return 0, nil
}
@ -221,7 +221,7 @@ func maybeInlineFootnoteOrSuper(p *Parser, data []byte, offset int) (int, ast.No
if ret == 0 {
return 0, nil
}
for i := offset; i < offset+ret+1; i++ {
for i := offset; i < offset+ret; i++ {
if isSpace(data[i]) && !isEscape(data, i) {
return 0, nil
}

8
testdata/mmark.test vendored
View File

@ -212,3 +212,11 @@ Figure: Go code
</code></pre>
<figcaption>Go code</figcaption>
</figure>
+++
water is H~2~O
+++
<p>water is H<sub>2</sub>O</p>
+++
1024 is 2^10^
+++
<p>1024 is 2<sup>10</sup></p>