mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
Fixes: #177
This commit is contained in:
parent
f3e20f4795
commit
2ffadcefcf
3 changed files with 100 additions and 0 deletions
|
|
@ -159,3 +159,79 @@ bbb
|
|||
<img src="gt.jpg" alt=">" />
|
||||
<img src="amp.jpg" alt="&" /></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>
|
||||
//= = = = = = = = = = = = = = = = = = = = = = = =//
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue