update indentation to be used from textedit
This commit is contained in:
parent
3e105c26a6
commit
f3efe9c7b1
2
go.mod
2
go.mod
@ -4,4 +4,4 @@ go 1.25.3
|
|||||||
|
|
||||||
require code.squareroundforest.org/arpio/notation v0.0.0-20250826181910-5140794b16b2
|
require code.squareroundforest.org/arpio/notation v0.0.0-20250826181910-5140794b16b2
|
||||||
|
|
||||||
require code.squareroundforest.org/arpio/textedit v0.0.0-20251101195945-0569369ef5a7
|
require code.squareroundforest.org/arpio/textedit v0.0.0-20251102000454-f8e59c1465b4
|
||||||
|
|||||||
4
go.sum
4
go.sum
@ -1,4 +1,4 @@
|
|||||||
code.squareroundforest.org/arpio/notation v0.0.0-20250826181910-5140794b16b2 h1:S4mjQHL70CuzFg1AGkr0o0d+4M+ZWM0sbnlYq6f0b3I=
|
code.squareroundforest.org/arpio/notation v0.0.0-20250826181910-5140794b16b2 h1:S4mjQHL70CuzFg1AGkr0o0d+4M+ZWM0sbnlYq6f0b3I=
|
||||||
code.squareroundforest.org/arpio/notation v0.0.0-20250826181910-5140794b16b2/go.mod h1:ait4Fvg9o0+bq5hlxi9dAcPL5a+/sr33qsZPNpToMLY=
|
code.squareroundforest.org/arpio/notation v0.0.0-20250826181910-5140794b16b2/go.mod h1:ait4Fvg9o0+bq5hlxi9dAcPL5a+/sr33qsZPNpToMLY=
|
||||||
code.squareroundforest.org/arpio/textedit v0.0.0-20251101195945-0569369ef5a7 h1:+pvm8bXYg7hn7ATyC1REYTeFWvrp5Ky7tFgyscB0KWo=
|
code.squareroundforest.org/arpio/textedit v0.0.0-20251102000454-f8e59c1465b4 h1:/9Mq7Z64nRIm1rVRF3RWMG5STQB31tO9HjXm+bL8k/0=
|
||||||
code.squareroundforest.org/arpio/textedit v0.0.0-20251101195945-0569369ef5a7/go.mod h1:nXdFdxdI69JrkIT97f+AEE4OgplmxbgNFZC5j7gsdqs=
|
code.squareroundforest.org/arpio/textedit v0.0.0-20251102000454-f8e59c1465b4/go.mod h1:nXdFdxdI69JrkIT97f+AEE4OgplmxbgNFZC5j7gsdqs=
|
||||||
|
|||||||
48
indent.go
48
indent.go
@ -5,52 +5,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
)
|
)
|
||||||
|
|
||||||
type indentState struct {
|
|
||||||
started, lineStarted bool
|
|
||||||
}
|
|
||||||
|
|
||||||
func indentLen(indent string) int {
|
|
||||||
var l int
|
|
||||||
r := []rune(indent)
|
|
||||||
for _, ri := range r {
|
|
||||||
if ri == '\t' {
|
|
||||||
l += 8
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
l++
|
|
||||||
}
|
|
||||||
|
|
||||||
return l
|
|
||||||
}
|
|
||||||
|
|
||||||
func indentEdit(indent []rune) func(rune, indentState) ([]rune, indentState) {
|
|
||||||
return func(r rune, s indentState) ([]rune, indentState) {
|
|
||||||
var ret []rune
|
|
||||||
if r == '\n' {
|
|
||||||
s.started = true
|
|
||||||
s.lineStarted = false
|
|
||||||
ret = append(ret, '\n')
|
|
||||||
return ret, s
|
|
||||||
}
|
|
||||||
|
|
||||||
if s.started && !s.lineStarted {
|
|
||||||
ret = append(ret, indent...)
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = append(ret, r)
|
|
||||||
s.started = true
|
|
||||||
s.lineStarted = true
|
|
||||||
return ret, s
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func newIndentWriter(out io.Writer, indent string) *textedit.Writer {
|
func newIndentWriter(out io.Writer, indent string) *textedit.Writer {
|
||||||
return textedit.New(
|
return textedit.New(out, textedit.Indent("", indent))
|
||||||
out,
|
|
||||||
textedit.Func(
|
|
||||||
indentEdit([]rune(indent)),
|
|
||||||
func(indentState) []rune { return nil },
|
|
||||||
),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|||||||
15
render.go
15
render.go
@ -216,6 +216,21 @@ func (r *renderer) renderUnindented(name string, rg renderGuide, a []Attributes,
|
|||||||
printf("</%s>", name)
|
printf("</%s>", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func indentLen(indent string) int {
|
||||||
|
var l int
|
||||||
|
r := []rune(indent)
|
||||||
|
for _, ri := range r {
|
||||||
|
if ri == '\t' {
|
||||||
|
l += 8
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
l++
|
||||||
|
}
|
||||||
|
|
||||||
|
return l
|
||||||
|
}
|
||||||
|
|
||||||
func (r *renderer) renderChildTag(tagName string, rg renderGuide, lastBlock bool, ct Tag) (bool, bool) {
|
func (r *renderer) renderChildTag(tagName string, rg renderGuide, lastBlock bool, ct Tag) (bool, bool) {
|
||||||
printf := r.getPrintf(tagName)
|
printf := r.getPrintf(tagName)
|
||||||
if rg.preformatted {
|
if rg.preformatted {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user