Skip to content

Commit 9a7f4c9

Browse files
committed
fix: panics when negative indent with tabs in fenced code block. Fixes #522
1 parent 9676021 commit 9a7f4c9

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

_test/extra.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,3 +861,18 @@ text" /></p>
861861
<li>test2</li>
862862
</ul>
863863
//= = = = = = = = = = = = = = = = = = = = = = = =//
864+
865+
69: Negative indentation with tabs in fenced code block
866+
OPTIONS: {"enableEscape": true}
867+
//- - - - - - - - -//
868+
*
869+
\t ~~~
870+
\t0
871+
//- - - - - - - - -//
872+
<ul>
873+
<li>
874+
<pre><code>0
875+
</code></pre>
876+
</li>
877+
</ul>
878+
//= = = = = = = = = = = = = = = = = = = = = = = =//

parser/fcode_block.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,7 @@ func (b *fencedCodeBlockParser) Continue(node ast.Node, reader text.Reader, pc C
8989
}
9090
pos, padding := util.IndentPositionPadding(line, reader.LineOffset(), segment.Padding, fdata.indent)
9191
if pos < 0 {
92-
pos = util.FirstNonSpacePosition(line)
93-
if pos < 0 {
94-
pos = 0
95-
}
92+
pos = max(0, util.FirstNonSpacePosition(line)) - segment.Padding
9693
padding = 0
9794
}
9895
seg := text.NewSegmentPadding(segment.Start+pos, segment.Stop, padding)

0 commit comments

Comments
 (0)