Skip to content

Commit

Permalink
fix: disable padding for the codeblock
Browse files Browse the repository at this point in the history
test: update test snapshots
  • Loading branch information
jahvon committed Dec 24, 2024
1 parent ffae7b7 commit 986e3e8
Show file tree
Hide file tree
Showing 51 changed files with 339 additions and 333 deletions.
2 changes: 1 addition & 1 deletion ansi/blockelement.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (e *BlockElement) Finish(w io.Writer, ctx RenderContext) error {
" ,.;-+|",
)

mw := NewMarginWriter(ctx, w, bs.Current().Style)
mw := NewMarginWriter(ctx, w, bs.Current().Style, true)
if _, err := io.WriteString(mw, s); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion ansi/codeblock.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func (e *CodeBlockElement) Finish(w io.Writer, ctx RenderContext) error {
mutex.Unlock()
}

mw := NewMarginWriter(ctx, w, bs.Current().Style)
mw := NewMarginWriter(ctx, w, bs.Current().Style, false)
renderText(mw, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, rules.BlockPrefix)
if len(theme) > 0 {
err := quick.Highlight(mw, e.Code, e.Language, "terminal256", theme)
Expand Down
2 changes: 1 addition & 1 deletion ansi/heading.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (e *HeadingElement) Render(w io.Writer, ctx RenderContext) error {
func (e *HeadingElement) Finish(w io.Writer, ctx RenderContext) error {
bs := ctx.blockStack
rules := bs.Current().Style
mw := NewMarginWriter(ctx, w, rules)
mw := NewMarginWriter(ctx, w, rules, true)

flow := wordwrap.NewWriter(int(bs.Width(ctx)))
_, err := flow.Write(bs.Current().Block.Bytes())
Expand Down
14 changes: 9 additions & 5 deletions ansi/margin.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type MarginWriter struct {
}

// NewMarginWriter returns a new MarginWriter.
func NewMarginWriter(ctx RenderContext, w io.Writer, rules StyleBlock) *MarginWriter {
func NewMarginWriter(ctx RenderContext, w io.Writer, rules StyleBlock, padded bool) *MarginWriter {
bs := ctx.blockStack
mw := &MarginWriter{
w: w,
Expand All @@ -44,11 +44,15 @@ func NewMarginWriter(ctx RenderContext, w io.Writer, rules StyleBlock) *MarginWr
mw.margin = *rules.Margin
}

mw.pw = padding.NewWriterPipe(mw.w, bs.Width(ctx), func(wr io.Writer) {
renderText(mw.w, mw.profile, mw.rules, " ")
})
fwd := mw.w
if padded {
mw.pw = padding.NewWriterPipe(mw.w, bs.Width(ctx), func(wr io.Writer) {
renderText(mw.w, mw.profile, mw.rules, "")
})
fwd = mw.pw
}

mw.iw = indent.NewWriterPipe(mw.pw, mw.indentation+mw.margin, mw.indentFunc)
mw.iw = indent.NewWriterPipe(fwd, mw.indentation+(mw.margin*2), mw.indentFunc)

Check failure on line 55 in ansi/margin.go

View workflow job for this annotation

GitHub Actions / lint-soft

Magic number: 2, in <operation> detected (mnd)
return mw
}

Expand Down
2 changes: 1 addition & 1 deletion ansi/paragraph.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func (e *ParagraphElement) Finish(w io.Writer, ctx RenderContext) error {
bs := ctx.blockStack
rules := bs.Current().Style

mw := NewMarginWriter(ctx, w, rules)
mw := NewMarginWriter(ctx, w, rules, true)
if len(strings.TrimSpace(bs.Current().Block.String())) > 0 {
flow := wordwrap.NewWriter(int(bs.Width(ctx)))
flow.KeepNewlines = ctx.options.PreserveNewLines
Expand Down
4 changes: 2 additions & 2 deletions ansi/testdata/TestRenderer/block_quote.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ansi/testdata/TestRenderer/code.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ansi/testdata/TestRenderer/code_block.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ansi/testdata/TestRenderer/emoji.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ansi/testdata/TestRenderer/emph.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions ansi/testdata/TestRenderer/enumeration.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions ansi/testdata/TestRenderer/heading.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ansi/testdata/TestRenderer/image.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ansi/testdata/TestRenderer/link.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions ansi/testdata/TestRenderer/list.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions ansi/testdata/TestRenderer/ordered_list.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ansi/testdata/TestRenderer/strikethrough.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ansi/testdata/TestRenderer/strong.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ansi/testdata/TestRenderer/table.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ansi/testdata/TestRenderer/table_align.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions ansi/testdata/TestRenderer/task.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 986e3e8

Please sign in to comment.