Skip to content

Commit

Permalink
wip: fix list margins
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Oct 12, 2023
1 parent 633e986 commit 482a7e8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
1 change: 1 addition & 0 deletions ansi/baseelement.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func renderText(w io.Writer, styler scrapbook.Styler, s string) {
func (e *BaseElement) Render(w io.Writer, ctx RenderContext) error {
block := ctx.blockStack.Current()

// Don't add text styling to filler text.
renderText(w, block.Style, e.Prefix)
defer func() {
renderText(w, block.Style, e.Suffix)
Expand Down
18 changes: 12 additions & 6 deletions ansi/elements.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,24 +91,30 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element {

// Lists
case ast.KindList:
s := ctx.options.Styles.List.StyleBlock
if s.Indent == nil {
// TODO clean this up
s := ctx.options.Styles.List
// set the styles
item := ctx.options.Styles.Item
s.StyleBlock.StylePrimitive.BlockPrefix = item.BlockPrefix
s.StyleBlock.StylePrimitive.Prefix = item.Prefix

if s.StyleBlock.Indent == nil {
var i uint
s.Indent = &i
s.StyleBlock.Indent = &i
}
n := node.Parent()
for n != nil {
if n.Kind() == ast.KindList {
i := ctx.options.Styles.List.LevelIndent
s.Indent = &i
i := s.LevelIndent
s.StyleBlock.Indent = &i
break
}
n = n.Parent()
}

e := &BlockElement{
Block: &bytes.Buffer{},
Style: ctx.blockStack.Current().Style,
Style: s.StyleBlock,
Margin: true,
Newline: true,
}
Expand Down

0 comments on commit 482a7e8

Please sign in to comment.