Skip to content

Commit

Permalink
Fixes #213
Browse files Browse the repository at this point in the history
  • Loading branch information
yuin committed Apr 10, 2021
1 parent 75d8cce commit ab798ea
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
13 changes: 13 additions & 0 deletions extension/_test/definition_list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -141,3 +141,16 @@ on two lines.</p>
</dl>
//= = = = = = = = = = = = = = = = = = = = = = = =//


6: Definition lists indented with tabs
//- - - - - - - - -//
0
: ```
0
//- - - - - - - - -//
<dl>
<dt>0</dt>
<dd><pre><code> 0</code></pre>
</dd>
</dl>
//= = = = = = = = = = = = = = = = = = = = = = = =//
2 changes: 1 addition & 1 deletion extension/definition_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (b *definitionDescriptionParser) Open(parent gast.Node, reader text.Reader,
para.Parent().RemoveChild(para.Parent(), para)
}
cpos, padding := util.IndentPosition(line[pos+1:], pos+1, list.Offset-pos-1)
reader.AdvanceAndSetPadding(cpos, padding)
reader.AdvanceAndSetPadding(cpos+1, padding)

return ast.NewDefinitionDescription(), parser.HasChildren
}
Expand Down
7 changes: 4 additions & 3 deletions parser/code_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (b *codeBlockParser) Continue(node ast.Node, reader text.Reader, pc Context

// if code block line starts with a tab, keep a tab as it is.
if segment.Padding != 0 {
preserveLeadingTabInCodeBlock(&segment, reader)
preserveLeadingTabInCodeBlock(&segment, reader, 0)
}

node.Lines().Append(segment)
Expand Down Expand Up @@ -84,11 +84,12 @@ func (b *codeBlockParser) CanAcceptIndentedLine() bool {
return true
}

func preserveLeadingTabInCodeBlock(segment *text.Segment, reader text.Reader) {
offsetWithPadding := reader.LineOffset()
func preserveLeadingTabInCodeBlock(segment *text.Segment, reader text.Reader, indent int) {
offsetWithPadding := reader.LineOffset() + indent
sl, ss := reader.Position()
reader.SetPosition(sl, text.NewSegment(ss.Start-1, ss.Stop))
if offsetWithPadding == reader.LineOffset() {
println("here")

This comment has been minimized.

Copy link
@moorereason

moorereason Apr 12, 2021

Contributor

Oops.

segment.Padding = 0
segment.Start--
}
Expand Down
3 changes: 2 additions & 1 deletion parser/fcode_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ 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 {
preserveLeadingTabInCodeBlock(&segment, reader)
preserveLeadingTabInCodeBlock(&segment, reader, fdata.indent)
}
w, pos := util.IndentWidth(line, reader.LineOffset())
if w < 4 {
Expand Down

0 comments on commit ab798ea

Please sign in to comment.