Skip to content

Commit

Permalink
Fixes: #177
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Feb 7, 2021
1 parent f3e20f4 commit 2ffadce
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 0 deletions.
76 changes: 76 additions & 0 deletions _test/extra.txt
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,79 @@ bbb
<img src="gt.jpg" alt="&gt;" />
<img src="amp.jpg" alt="&amp;" /></p>
//= = = = = = = = = = = = = = = = = = = = = = = =//


13: fenced code block starting with tab inside list
//- - - - - - - - -//
* foo
```Makefile
foo
foo
```
//- - - - - - - - -//
<ul>
<li>foo
<pre><code class="language-Makefile">foo
foo
</code></pre>
</li>
</ul>
//= = = = = = = = = = = = = = = = = = = = = = = =//

14: fenced code block inside list, mismatched tab start
//- - - - - - - - -//
* foo
```Makefile
foo
foo
```
//- - - - - - - - -//
<ul>
<li>foo
<pre><code class="language-Makefile">foo
foo
</code></pre>
</li>
</ul>
//= = = = = = = = = = = = = = = = = = = = = = = =//


15: fenced code block inside nested list
//- - - - - - - - -//
* foo
- bar
```Makefile
foo
foo
```
//- - - - - - - - -//
<ul>
<li>foo
<ul>
<li>bar
<pre><code class="language-Makefile">foo
foo
</code></pre>
</li>
</ul>
</li>
</ul>
//= = = = = = = = = = = = = = = = = = = = = = = =//

16: indented code block starting with a tab.
//- - - - - - - - -//
* foo

foo
foo

//- - - - - - - - -//
<ul>
<li>
<p>foo</p>
<pre><code>foo
foo
</code></pre>
</li>
</ul>
//= = = = = = = = = = = = = = = = = = = = = = = =//
13 changes: 13 additions & 0 deletions parser/code_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,19 @@ func (b *codeBlockParser) Continue(node ast.Node, reader text.Reader, pc Context
}
reader.AdvanceAndSetPadding(pos, padding)
_, segment = reader.PeekLine()

// if code block line starts with a tab, keep a tab as it is.
if segment.Padding != 0 {
offsetWithPadding := reader.LineOffset()
sl, ss := reader.Position()
reader.SetPosition(sl, text.NewSegment(ss.Start-1, ss.Stop))
if offsetWithPadding == reader.LineOffset() {
segment.Padding = 0
segment.Start--
}
reader.SetPosition(sl, ss)
}

node.Lines().Append(segment)
reader.Advance(segment.Len() - 1)
return Continue | NoChildren
Expand Down
11 changes: 11 additions & 0 deletions parser/fcode_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ func (b *fencedCodeBlockParser) Open(parent ast.Node, reader text.Reader, pc Con
func (b *fencedCodeBlockParser) Continue(node ast.Node, reader text.Reader, pc Context) State {
line, segment := reader.PeekLine()
fdata := pc.Get(fencedCodeBlockInfoKey).(*fenceData)
// if code block line starts with a tab, keep a tab as it is.
if segment.Padding != 0 {
offsetWithPadding := reader.LineOffset()
sl, ss := reader.Position()
reader.SetPosition(sl, text.NewSegment(ss.Start-1, ss.Stop))
if offsetWithPadding == reader.LineOffset() {
segment.Padding = 0
segment.Start--
}
reader.SetPosition(sl, ss)
}
w, pos := util.IndentWidth(line, reader.LineOffset())
if w < 4 {
i := pos
Expand Down

1 comment on commit 2ffadce

@karelbilek
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hahaha OK, it was simpler done by someone who knows what he is doing :D

thanks so much.

I am not sure if this is still not needed. I think might be.

#188

Please sign in to comment.