mirror of
https://github.com/yuin/goldmark
synced 2025-03-04 23:04:52 +00:00
refactoring
This commit is contained in:
parent
2ffadcefcf
commit
56bbdf0370
2 changed files with 13 additions and 16 deletions
|
|
@ -52,14 +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 code block line starts with a tab, keep a tab as it is.
|
||||||
if segment.Padding != 0 {
|
if segment.Padding != 0 {
|
||||||
offsetWithPadding := reader.LineOffset()
|
preserveLeadingTabInCodeBlock(&segment, reader)
|
||||||
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)
|
node.Lines().Append(segment)
|
||||||
|
|
@ -90,3 +83,14 @@ func (b *codeBlockParser) CanInterruptParagraph() bool {
|
||||||
func (b *codeBlockParser) CanAcceptIndentedLine() bool {
|
func (b *codeBlockParser) CanAcceptIndentedLine() bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func preserveLeadingTabInCodeBlock(segment *text.Segment, reader text.Reader) {
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -73,14 +73,7 @@ func (b *fencedCodeBlockParser) Continue(node ast.Node, reader text.Reader, pc C
|
||||||
fdata := pc.Get(fencedCodeBlockInfoKey).(*fenceData)
|
fdata := pc.Get(fencedCodeBlockInfoKey).(*fenceData)
|
||||||
// if code block line starts with a tab, keep a tab as it is.
|
// if code block line starts with a tab, keep a tab as it is.
|
||||||
if segment.Padding != 0 {
|
if segment.Padding != 0 {
|
||||||
offsetWithPadding := reader.LineOffset()
|
preserveLeadingTabInCodeBlock(&segment, reader)
|
||||||
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())
|
w, pos := util.IndentWidth(line, reader.LineOffset())
|
||||||
if w < 4 {
|
if w < 4 {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue