charmbracelet / glamour

Stylesheet-based markdown rendering for your CLI apps 💇🏻‍♀️
MIT License
2.49k stars 183 forks source link

document margin is only applied if color is also present #141

Open anicolao opened 2 years ago

anicolao commented 2 years ago

To reproduce:

cp styles/light.json /tmp
vi /tmp/light.json # remove color line from document block at top of file
glow -s /tmp/light.json ANYFILE.md

The output of glow should have a two space margin. The margin appears only before lines which have colour in them, like headers, and not before other lines.

anicolao commented 2 years ago

The following hack does work around the problem:

diff --git a/ansi/margin.go b/ansi/margin.go
index e039783..4e1992f 100644
--- a/ansi/margin.go
+++ b/ansi/margin.go
@@ -29,10 +29,10 @@ func NewMarginWriter(ctx RenderContext, w io.Writer, rules StyleBlock) *MarginWr
    }

    pw := padding.NewWriterPipe(w, bs.Width(ctx), func(wr io.Writer) {
-       renderText(w, ctx.options.ColorProfile, rules.StylePrimitive, " ")
+       renderText(w, ctx.options.ColorProfile, rules.StylePrimitive, "\u200b ")
    })

-   ic := " "
+   ic := "\u200b "
    if rules.IndentToken != nil {
        ic = *rules.IndentToken
    }