Skip to content

Commit

Permalink
fix: add prefix and suffix for baseelements
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Oct 12, 2023
1 parent 2bbacb7 commit 633e986
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
16 changes: 10 additions & 6 deletions ansi/baseelement.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type BaseElement struct {
Token string
Prefix string
Suffix string
Style scrapbook.Styler
Style scrapbook.StylePrimitive
}

func renderText(w io.Writer, styler scrapbook.Styler, s string) {
Expand All @@ -29,15 +29,19 @@ func renderText(w io.Writer, styler scrapbook.Styler, s string) {
}

func (e *BaseElement) Render(w io.Writer, ctx RenderContext) error {
bs := ctx.blockStack
parentBlock := bs.Current()
block := ctx.blockStack.Current()

renderText(w, parentBlock.Style, e.Prefix)
renderText(w, block.Style, e.Prefix)
defer func() {
renderText(w, parentBlock.Style, e.Suffix)
renderText(w, block.Style, e.Suffix)
}()

// TODO handle prefix/suffix
// We don't carry the text styles over to the prefixes. Also, don't make it
// a block style, we don't want margins and newlines applied to this text.
renderText(w, block.Style.StylePrimitive, e.Style.BlockPrefix)
defer func() {
renderText(w, block.Style.StylePrimitive, e.Style.BlockSuffix)
}()

s := e.Token
renderText(w, e.Style, s)
Expand Down
5 changes: 2 additions & 3 deletions ansi/codeblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,6 @@ func chromaStyle(style scrapbook.StylePrimitive) string {
}

func (e *CodeBlockElement) Render(w io.Writer, ctx RenderContext) error {
bs := ctx.blockStack

var margin int
rules := ctx.options.Styles.CodeBlock
theme := rules.Theme
Expand Down Expand Up @@ -129,9 +127,10 @@ func (e *CodeBlockElement) Render(w io.Writer, ctx RenderContext) error {
}

// fallback rendering
// TODO fix this styling
el := &BaseElement{
Token: e.Code,
Style: bs.Current().Style,
Style: ctx.options.Styles.Code.StylePrimitive,
}

return el.Render(w, ctx)
Expand Down

0 comments on commit 633e986

Please sign in to comment.