diff --git a/ansi/blockstack.go b/ansi/blockstack.go index 0ce8df1..96fdb91 100644 --- a/ansi/blockstack.go +++ b/ansi/blockstack.go @@ -91,5 +91,5 @@ func (s BlockStack) Current() BlockElement { func (s BlockStack) With(child StylePrimitive) StylePrimitive { sb := StyleBlock{} sb.StylePrimitive = child - return cascadeStyle(s.Current().Style, sb, true).StylePrimitive + return cascadeStyle(s.Current().Style, sb, false).StylePrimitive } diff --git a/ansi/elements.go b/ansi/elements.go index 970a884..f4403da 100644 --- a/ansi/elements.go +++ b/ansi/elements.go @@ -78,7 +78,7 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element { case ast.KindBlockquote: e := &BlockElement{ Block: &bytes.Buffer{}, - Style: cascadeStyle(ctx.blockStack.Current().Style, ctx.options.Styles.BlockQuote, true), + Style: cascadeStyle(ctx.blockStack.Current().Style, ctx.options.Styles.BlockQuote, false), Margin: true, Newline: true, } @@ -107,7 +107,7 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element { e := &BlockElement{ Block: &bytes.Buffer{}, - Style: cascadeStyle(ctx.blockStack.Current().Style, s, true), + Style: cascadeStyle(ctx.blockStack.Current().Style, s, false), Margin: true, Newline: true, } @@ -281,7 +281,7 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element { // n := node.(*ast.CodeSpan) e := &BlockElement{ Block: &bytes.Buffer{}, - Style: cascadeStyle(ctx.blockStack.Current().Style, ctx.options.Styles.Code, true), + Style: cascadeStyle(ctx.blockStack.Current().Style, ctx.options.Styles.Code, false), } return Element{ Renderer: e, @@ -344,7 +344,7 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element { case astext.KindDefinitionList: e := &BlockElement{ Block: &bytes.Buffer{}, - Style: cascadeStyle(ctx.blockStack.Current().Style, ctx.options.Styles.DefinitionList, true), + Style: cascadeStyle(ctx.blockStack.Current().Style, ctx.options.Styles.DefinitionList, false), Margin: true, Newline: true, } diff --git a/ansi/heading.go b/ansi/heading.go index a6f5660..c195ae5 100644 --- a/ansi/heading.go +++ b/ansi/heading.go @@ -21,17 +21,17 @@ func (e *HeadingElement) Render(w io.Writer, ctx RenderContext) error { switch e.Level { case 1: - rules = cascadeStyles(false, rules, ctx.options.Styles.H1) + rules = cascadeStyles(true, rules, ctx.options.Styles.H1) case 2: - rules = cascadeStyles(false, rules, ctx.options.Styles.H2) + rules = cascadeStyles(true, rules, ctx.options.Styles.H2) case 3: - rules = cascadeStyles(false, rules, ctx.options.Styles.H3) + rules = cascadeStyles(true, rules, ctx.options.Styles.H3) case 4: - rules = cascadeStyles(false, rules, ctx.options.Styles.H4) + rules = cascadeStyles(true, rules, ctx.options.Styles.H4) case 5: - rules = cascadeStyles(false, rules, ctx.options.Styles.H5) + rules = cascadeStyles(true, rules, ctx.options.Styles.H5) case 6: - rules = cascadeStyles(false, rules, ctx.options.Styles.H6) + rules = cascadeStyles(true, rules, ctx.options.Styles.H6) } if !e.First { @@ -40,7 +40,7 @@ func (e *HeadingElement) Render(w io.Writer, ctx RenderContext) error { be := BlockElement{ Block: &bytes.Buffer{}, - Style: cascadeStyle(bs.Current().Style, rules, true), + Style: cascadeStyle(bs.Current().Style, rules, false), } bs.Push(be) diff --git a/ansi/paragraph.go b/ansi/paragraph.go index ed7f91d..20cd00e 100644 --- a/ansi/paragraph.go +++ b/ansi/paragraph.go @@ -22,7 +22,7 @@ func (e *ParagraphElement) Render(w io.Writer, ctx RenderContext) error { } be := BlockElement{ Block: &bytes.Buffer{}, - Style: cascadeStyle(bs.Current().Style, rules, true), + Style: cascadeStyle(bs.Current().Style, rules, false), } bs.Push(be) diff --git a/ansi/style.go b/ansi/style.go index abfc36d..4b599da 100644 --- a/ansi/style.go +++ b/ansi/style.go @@ -136,38 +136,37 @@ type StyleConfig struct { HTMLSpan StyleBlock `json:"html_span"` } -func cascadeStyles(onlyColors bool, s ...StyleBlock) StyleBlock { +func cascadeStyles(toBlock bool, s ...StyleBlock) StyleBlock { var r StyleBlock for _, v := range s { - r = cascadeStyle(r, v, onlyColors) + r = cascadeStyle(r, v, toBlock) } return r } -func cascadeStyle(parent StyleBlock, child StyleBlock, onlyColors bool) StyleBlock { +func cascadeStyle(parent StyleBlock, child StyleBlock, toBlock bool) StyleBlock { s := child s.Color = parent.Color s.BackgroundColor = parent.BackgroundColor + s.Underline = parent.Underline + s.Bold = parent.Bold + s.Italic = parent.Italic + s.CrossedOut = parent.CrossedOut + s.Faint = parent.Faint + s.Conceal = parent.Conceal + s.Overlined = parent.Overlined + s.Inverse = parent.Inverse + s.Blink = parent.Blink - if !onlyColors { + if toBlock { s.Indent = parent.Indent s.Margin = parent.Margin - s.Underline = parent.Underline - s.Bold = parent.Bold - s.Italic = parent.Italic - s.CrossedOut = parent.CrossedOut - s.Faint = parent.Faint - s.Conceal = parent.Conceal - s.Overlined = parent.Overlined - s.Inverse = parent.Inverse - s.Blink = parent.Blink s.BlockPrefix = parent.BlockPrefix s.BlockSuffix = parent.BlockSuffix s.Prefix = parent.Prefix s.Suffix = parent.Suffix - s.Format = parent.Format } if child.Color != nil { diff --git a/styles/examples/heading.png b/styles/examples/heading.png index bf53a3e..b10bc34 100644 Binary files a/styles/examples/heading.png and b/styles/examples/heading.png differ diff --git a/testdata/heading.test b/testdata/heading.test index 706ca5d..7769fff 100644 --- a/testdata/heading.test +++ b/testdata/heading.test @@ -1,3 +1,3 @@ - => h1 <=  + => h1 <=   ## h2   ### h3 \ No newline at end of file diff --git a/testdata/readme.test b/testdata/readme.test index e89c1db..14fa909 100644 --- a/testdata/readme.test +++ b/testdata/readme.test @@ -1,20 +1,20 @@ -  Gold                                                                          +  Gold                                                                                                                                                           Render markdown on the CLI, with pizzazz!                                                                                                                      - ## What is it?                                                                 + ## What is it?                                                                                                                                                  Gold is a Golang library that allows you to use JSON based stylesheets to       render Markdown files in the terminal. Just like CSS, you can define color and  style attributes on Markdown elements. The difference is that you use ANSI      color and terminal codes instead of CSS properties and hex colors.                                                                                             - ## Usage                                                                       + ## Usage                                                                                                                                                        See cmd/gold /cmd/gold/.                                                                                                                                       - ## Example Output                                                              + ## Example Output                                                                                                                                               Image: Gold Dark Style →                                                        https://github.com/charmbracelet/gold/raw/master/styles/gallery/dark.png       @@ -22,12 +22,12 @@  Check out the Gold Style Gallery                                                https://github.com/charmbracelet/gold/blob/master/styles/gallery/README.md!                                                                                    - ## Colors                                                                      + ## Colors                                                                                                                                                       Currently  gold  uses the Aurora ANSI colors                                    https://godoc.org/github.com/logrusorgru/aurora#Index.                                                                                                         - ## Development                                                                 + ## Development                                                                                                                                                  Style definitions located in  styles/  can be embedded into the binary by       running statik https://github.com/rakyll/statik: