From 15db676ead58fe0d34064aac7f77256ad1a9bd56 Mon Sep 17 00:00:00 2001 From: Jahvon Dockery Date: Sat, 3 Aug 2024 00:09:06 -0400 Subject: [PATCH] feat: Add code block indentation token support This change incorporates the specified indentation token when rendering code blocks. It includes fixes to how the margin and indentation tokens are rendered globally. When both are specified, the margin is rendered first as an empty space. This PR is another attempt at adding the functionality from https://github.com/charmbracelet/glamour/pull/299 --- ansi/blockelement.go | 2 +- ansi/codeblock.go | 122 ++++++++++-------- ansi/elements.go | 18 ++- ansi/heading.go | 2 +- ansi/margin.go | 74 ++++++++--- ansi/paragraph.go | 2 +- ansi/testdata/TestRenderer/block_quote.golden | 4 +- ansi/testdata/TestRenderer/code.golden | 2 +- ansi/testdata/TestRenderer/code_block.golden | 4 +- ansi/testdata/TestRenderer/emoji.golden | 2 +- ansi/testdata/TestRenderer/emph.golden | 2 +- ansi/testdata/TestRenderer/enumeration.golden | 6 +- ansi/testdata/TestRenderer/heading.golden | 4 +- ansi/testdata/TestRenderer/image.golden | 2 +- ansi/testdata/TestRenderer/link.golden | 2 +- ansi/testdata/TestRenderer/list.golden | 8 +- .../testdata/TestRenderer/ordered_list.golden | 8 +- .../TestRenderer/strikethrough.golden | 2 +- ansi/testdata/TestRenderer/strong.golden | 2 +- ansi/testdata/TestRenderer/table.golden | 2 +- ansi/testdata/TestRenderer/table_align.golden | 2 +- ansi/testdata/TestRenderer/task.golden | 6 +- ansi/testdata/TestRendererIssues/106.golden | 30 ++--- ansi/testdata/TestRendererIssues/107.golden | 10 +- ansi/testdata/TestRendererIssues/117.golden | 8 +- ansi/testdata/TestRendererIssues/149.golden | 6 +- ansi/testdata/TestRendererIssues/172.golden | 10 +- ansi/testdata/TestRendererIssues/237.golden | 16 +-- ansi/testdata/TestRendererIssues/239.golden | 14 +- ansi/testdata/TestRendererIssues/257.golden | 4 +- ansi/testdata/TestRendererIssues/290.golden | 8 +- ansi/testdata/TestRendererIssues/312.golden | 30 ++--- ansi/testdata/TestRendererIssues/313.golden | 12 +- ansi/testdata/TestRendererIssues/315.golden | 8 +- ansi/testdata/TestRendererIssues/316.golden | 10 +- ansi/testdata/TestRendererIssues/42.golden | 10 +- ansi/testdata/TestRendererIssues/43.golden | 16 +-- ansi/testdata/TestRendererIssues/44.golden | 14 +- ansi/testdata/TestRendererIssues/46_1.golden | 8 +- ansi/testdata/TestRendererIssues/46_2.golden | 24 ++-- ansi/testdata/TestRendererIssues/47.golden | 2 +- ansi/testdata/TestRendererIssues/48.golden | 30 ++--- ansi/testdata/TestRendererIssues/60.golden | 52 ++++---- ansi/testdata/TestRendererIssues/79.golden | 14 +- examples/artichokes/main.go | 3 +- glamour.go | 2 +- glamour_test.go | 3 +- testdata/TestCapitalization.golden | 10 +- testdata/TestRenderHelpers.golden | 76 +++++------ testdata/TestTermRenderer.golden | 76 +++++------ testdata/TestTermRendererWriter.golden | 76 +++++------ testdata/TestWithPreservedNewLines.golden | 10 +- 52 files changed, 458 insertions(+), 412 deletions(-) diff --git a/ansi/blockelement.go b/ansi/blockelement.go index 2ca7bb34..add6e05a 100644 --- a/ansi/blockelement.go +++ b/ansi/blockelement.go @@ -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 } diff --git a/ansi/codeblock.go b/ansi/codeblock.go index f0c3017f..87df9496 100644 --- a/ansi/codeblock.go +++ b/ansi/codeblock.go @@ -1,13 +1,13 @@ package ansi import ( + "bytes" "io" "sync" "github.com/alecthomas/chroma/v2" "github.com/alecthomas/chroma/v2/quick" "github.com/alecthomas/chroma/v2/styles" - "github.com/muesli/reflow/indent" "github.com/muesli/termenv" ) @@ -62,19 +62,25 @@ func chromaStyle(style StylePrimitive) string { func (e *CodeBlockElement) Render(w io.Writer, ctx RenderContext) error { bs := ctx.blockStack - - var indentation uint - var margin uint rules := ctx.options.Styles.CodeBlock - if rules.Indent != nil { - indentation = *rules.Indent - } - if rules.Margin != nil { - margin = *rules.Margin + + be := BlockElement{ + Block: &bytes.Buffer{}, + Style: rules.StyleBlock, } - theme := rules.Theme + bs.Push(be) + return nil +} + +func (e *CodeBlockElement) Finish(w io.Writer, ctx RenderContext) error { + bs := ctx.blockStack + rules := bs.Current().Style + + cb := ctx.options.Styles.CodeBlock + theme := cb.Theme + chromaRules := cb.Chroma - if rules.Chroma != nil && ctx.options.ColorProfile != termenv.Ascii { + if chromaRules != nil && ctx.options.ColorProfile != termenv.Ascii { theme = chromaStyleTheme mutex.Lock() // Don't register the style if it's already registered. @@ -82,62 +88,64 @@ func (e *CodeBlockElement) Render(w io.Writer, ctx RenderContext) error { if !ok { styles.Register(chroma.MustNewStyle(theme, chroma.StyleEntries{ - chroma.Text: chromaStyle(rules.Chroma.Text), - chroma.Error: chromaStyle(rules.Chroma.Error), - chroma.Comment: chromaStyle(rules.Chroma.Comment), - chroma.CommentPreproc: chromaStyle(rules.Chroma.CommentPreproc), - chroma.Keyword: chromaStyle(rules.Chroma.Keyword), - chroma.KeywordReserved: chromaStyle(rules.Chroma.KeywordReserved), - chroma.KeywordNamespace: chromaStyle(rules.Chroma.KeywordNamespace), - chroma.KeywordType: chromaStyle(rules.Chroma.KeywordType), - chroma.Operator: chromaStyle(rules.Chroma.Operator), - chroma.Punctuation: chromaStyle(rules.Chroma.Punctuation), - chroma.Name: chromaStyle(rules.Chroma.Name), - chroma.NameBuiltin: chromaStyle(rules.Chroma.NameBuiltin), - chroma.NameTag: chromaStyle(rules.Chroma.NameTag), - chroma.NameAttribute: chromaStyle(rules.Chroma.NameAttribute), - chroma.NameClass: chromaStyle(rules.Chroma.NameClass), - chroma.NameConstant: chromaStyle(rules.Chroma.NameConstant), - chroma.NameDecorator: chromaStyle(rules.Chroma.NameDecorator), - chroma.NameException: chromaStyle(rules.Chroma.NameException), - chroma.NameFunction: chromaStyle(rules.Chroma.NameFunction), - chroma.NameOther: chromaStyle(rules.Chroma.NameOther), - chroma.Literal: chromaStyle(rules.Chroma.Literal), - chroma.LiteralNumber: chromaStyle(rules.Chroma.LiteralNumber), - chroma.LiteralDate: chromaStyle(rules.Chroma.LiteralDate), - chroma.LiteralString: chromaStyle(rules.Chroma.LiteralString), - chroma.LiteralStringEscape: chromaStyle(rules.Chroma.LiteralStringEscape), - chroma.GenericDeleted: chromaStyle(rules.Chroma.GenericDeleted), - chroma.GenericEmph: chromaStyle(rules.Chroma.GenericEmph), - chroma.GenericInserted: chromaStyle(rules.Chroma.GenericInserted), - chroma.GenericStrong: chromaStyle(rules.Chroma.GenericStrong), - chroma.GenericSubheading: chromaStyle(rules.Chroma.GenericSubheading), - chroma.Background: chromaStyle(rules.Chroma.Background), + chroma.Text: chromaStyle(chromaRules.Text), + chroma.Error: chromaStyle(chromaRules.Error), + chroma.Comment: chromaStyle(chromaRules.Comment), + chroma.CommentPreproc: chromaStyle(chromaRules.CommentPreproc), + chroma.Keyword: chromaStyle(chromaRules.Keyword), + chroma.KeywordReserved: chromaStyle(chromaRules.KeywordReserved), + chroma.KeywordNamespace: chromaStyle(chromaRules.KeywordNamespace), + chroma.KeywordType: chromaStyle(chromaRules.KeywordType), + chroma.Operator: chromaStyle(chromaRules.Operator), + chroma.Punctuation: chromaStyle(chromaRules.Punctuation), + chroma.Name: chromaStyle(chromaRules.Name), + chroma.NameBuiltin: chromaStyle(chromaRules.NameBuiltin), + chroma.NameTag: chromaStyle(chromaRules.NameTag), + chroma.NameAttribute: chromaStyle(chromaRules.NameAttribute), + chroma.NameClass: chromaStyle(chromaRules.NameClass), + chroma.NameConstant: chromaStyle(chromaRules.NameConstant), + chroma.NameDecorator: chromaStyle(chromaRules.NameDecorator), + chroma.NameException: chromaStyle(chromaRules.NameException), + chroma.NameFunction: chromaStyle(chromaRules.NameFunction), + chroma.NameOther: chromaStyle(chromaRules.NameOther), + chroma.Literal: chromaStyle(chromaRules.Literal), + chroma.LiteralNumber: chromaStyle(chromaRules.LiteralNumber), + chroma.LiteralDate: chromaStyle(chromaRules.LiteralDate), + chroma.LiteralString: chromaStyle(chromaRules.LiteralString), + chroma.LiteralStringEscape: chromaStyle(chromaRules.LiteralStringEscape), + chroma.GenericDeleted: chromaStyle(chromaRules.GenericDeleted), + chroma.GenericEmph: chromaStyle(chromaRules.GenericEmph), + chroma.GenericInserted: chromaStyle(chromaRules.GenericInserted), + chroma.GenericStrong: chromaStyle(chromaRules.GenericStrong), + chroma.GenericSubheading: chromaStyle(chromaRules.GenericSubheading), + chroma.Background: chromaStyle(chromaRules.Background), })) } mutex.Unlock() } - iw := indent.NewWriterPipe(w, indentation+margin, func(wr io.Writer) { - renderText(w, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, " ") - }) - + mw := NewMarginWriter(ctx, w, bs.Current().Style, false) + renderText(mw, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, rules.BlockPrefix) if len(theme) > 0 { - renderText(iw, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, rules.BlockPrefix) - - err := quick.Highlight(iw, e.Code, e.Language, "terminal256", theme) + err := quick.Highlight(mw, e.Code, e.Language, "terminal256", theme) if err != nil { return err } - renderText(iw, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, rules.BlockSuffix) - return nil - } + } else { + // fallback rendering + el := &BaseElement{ + Token: e.Code, + Style: rules.StylePrimitive, + } - // fallback rendering - el := &BaseElement{ - Token: e.Code, - Style: rules.StylePrimitive, + err := el.Render(mw, ctx) + if err != nil { + return err + } } + renderText(mw, ctx.options.ColorProfile, bs.Current().Style.StylePrimitive, rules.BlockSuffix) - return el.Render(iw, ctx) + bs.Current().Block.Reset() + bs.Pop() + return nil } diff --git a/ansi/elements.go b/ansi/elements.go index 161857ab..14d572f2 100644 --- a/ansi/elements.go +++ b/ansi/elements.go @@ -282,12 +282,14 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element { line := n.Lines().At(i) s += string(line.Value(source)) } + e := &CodeBlockElement{ + Code: s, + Language: string(n.Language(source)), + } return Element{ Entering: "\n", - Renderer: &CodeBlockElement{ - Code: s, - Language: string(n.Language(source)), - }, + Renderer: e, + Finisher: e, } case ast.KindCodeBlock: @@ -298,11 +300,13 @@ func (tr *ANSIRenderer) NewElement(node ast.Node, source []byte) Element { line := n.Lines().At(i) s += string(line.Value(source)) } + e := &CodeBlockElement{ + Code: s, + } return Element{ Entering: "\n", - Renderer: &CodeBlockElement{ - Code: s, - }, + Renderer: e, + Finisher: e, } case ast.KindCodeSpan: diff --git a/ansi/heading.go b/ansi/heading.go index b7e2e755..d9fdfe1c 100644 --- a/ansi/heading.go +++ b/ansi/heading.go @@ -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()) diff --git a/ansi/margin.go b/ansi/margin.go index e039783f..dbbf82be 100644 --- a/ansi/margin.go +++ b/ansi/margin.go @@ -5,48 +5,80 @@ import ( "github.com/muesli/reflow/indent" "github.com/muesli/reflow/padding" + "github.com/muesli/termenv" ) // MarginWriter is a Writer that applies indentation and padding around // whatever you write to it. type MarginWriter struct { + indentation, margin uint + indentPos, marginPos uint + indentToken string + + profile termenv.Profile + rules, parentRules StylePrimitive + w io.Writer pw *padding.Writer iw *indent.Writer } // 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, + profile: ctx.options.ColorProfile, + rules: rules.StylePrimitive, + parentRules: bs.Parent().Style.StylePrimitive, + } - var indentation uint - var margin uint if rules.Indent != nil { - indentation = *rules.Indent + mw.indentation = *rules.Indent + mw.indentToken = " " + if rules.IndentToken != nil { + mw.indentToken = *rules.IndentToken + } } if rules.Margin != nil { - margin = *rules.Margin + mw.margin = *rules.Margin } - pw := padding.NewWriterPipe(w, bs.Width(ctx), func(wr io.Writer) { - renderText(w, ctx.options.ColorProfile, rules.StylePrimitive, " ") - }) - - ic := " " - if rules.IndentToken != nil { - ic = *rules.IndentToken - } - iw := indent.NewWriterPipe(pw, indentation+margin, func(wr io.Writer) { - renderText(w, ctx.options.ColorProfile, bs.Parent().Style.StylePrimitive, ic) - }) - - return &MarginWriter{ - w: w, - pw: pw, - iw: iw, + 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(fwd, mw.indentation+(mw.margin*2), mw.indentFunc) + return mw } func (w *MarginWriter) Write(b []byte) (int, error) { return w.iw.Write(b) } + +// indentFunc is called when writing each the margin and indentation tokens. +// The margin is written first, using an empty space character as the token. +// The indentation is written next, using the token specified in the rules. +func (w *MarginWriter) indentFunc(iw io.Writer) { + ic := " " + switch { + case w.margin == 0 && w.indentation == 0: + return + case w.margin >= 1 && w.indentation == 0: + break + case w.margin >= 1 && w.marginPos < w.margin: + w.marginPos++ + case w.indentation >= 1 && w.indentPos < w.indentation: + w.indentPos++ + ic = w.indentToken + if w.indentPos == w.indentation { + w.marginPos = 0 + w.indentPos = 0 + } + } + renderText(w.w, w.profile, w.parentRules, ic) +} diff --git a/ansi/paragraph.go b/ansi/paragraph.go index 96513275..b2582df0 100644 --- a/ansi/paragraph.go +++ b/ansi/paragraph.go @@ -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 diff --git a/ansi/testdata/TestRenderer/block_quote.golden b/ansi/testdata/TestRenderer/block_quote.golden index 8bc88d84..383d0138 100644 --- a/ansi/testdata/TestRenderer/block_quote.golden +++ b/ansi/testdata/TestRenderer/block_quote.golden @@ -1,2 +1,2 @@ - -=> First line of quote Second line                                                + +=> First line of quote Second line diff --git a/ansi/testdata/TestRenderer/code.golden b/ansi/testdata/TestRenderer/code.golden index ba6f5d31..25790fd9 100644 --- a/ansi/testdata/TestRenderer/code.golden +++ b/ansi/testdata/TestRenderer/code.golden @@ -1 +1 @@ -This is a code. +This is a code. diff --git a/ansi/testdata/TestRenderer/code_block.golden b/ansi/testdata/TestRenderer/code_block.golden index c608da7a..5d6938d1 100644 --- a/ansi/testdata/TestRenderer/code_block.golden +++ b/ansi/testdata/TestRenderer/code_block.golden @@ -1,3 +1,3 @@ - -This is a code block.  + +This is a code block.  \ No newline at end of file diff --git a/ansi/testdata/TestRenderer/emoji.golden b/ansi/testdata/TestRenderer/emoji.golden index 0d1abe49..204160da 100644 --- a/ansi/testdata/TestRenderer/emoji.golden +++ b/ansi/testdata/TestRenderer/emoji.golden @@ -1 +1 @@ -πŸ™ ⚑ 🐱 = ❀️ +πŸ™ ⚑ 🐱 = ❀️ diff --git a/ansi/testdata/TestRenderer/emph.golden b/ansi/testdata/TestRenderer/emph.golden index 2d963988..02b5ba66 100644 --- a/ansi/testdata/TestRenderer/emph.golden +++ b/ansi/testdata/TestRenderer/emph.golden @@ -1 +1 @@ -This text is emphasized. +This text is emphasized. diff --git a/ansi/testdata/TestRenderer/enumeration.golden b/ansi/testdata/TestRenderer/enumeration.golden index 13e62fcf..eee4f755 100644 --- a/ansi/testdata/TestRenderer/enumeration.golden +++ b/ansi/testdata/TestRenderer/enumeration.golden @@ -1,3 +1,3 @@ - -1. First Item                                                                    -2. Second Item                                                                   + +1. First Item +2. Second Item diff --git a/ansi/testdata/TestRenderer/heading.golden b/ansi/testdata/TestRenderer/heading.golden index 134dfc58..4de117ba 100644 --- a/ansi/testdata/TestRenderer/heading.golden +++ b/ansi/testdata/TestRenderer/heading.golden @@ -1,3 +1,3 @@ -=> h1 <= -## h2 +=> h1 <= +## h2 ### h3 \ No newline at end of file diff --git a/ansi/testdata/TestRenderer/image.golden b/ansi/testdata/TestRenderer/image.golden index e4ea8ac7..85a49191 100644 --- a/ansi/testdata/TestRenderer/image.golden +++ b/ansi/testdata/TestRenderer/image.golden @@ -1 +1 @@ -Image [Image: https://charm.sh/logo.png]. +Image [Image: https://charm.sh/logo.png]. diff --git a/ansi/testdata/TestRenderer/link.golden b/ansi/testdata/TestRenderer/link.golden index ed11bdb4..38b0da0f 100644 --- a/ansi/testdata/TestRenderer/link.golden +++ b/ansi/testdata/TestRenderer/link.golden @@ -1 +1 @@ -This is a link (https://charm.sh). +This is a link (https://charm.sh). diff --git a/ansi/testdata/TestRenderer/list.golden b/ansi/testdata/TestRenderer/list.golden index 4ba92dc8..f131caad 100644 --- a/ansi/testdata/TestRenderer/list.golden +++ b/ansi/testdata/TestRenderer/list.golden @@ -1,4 +1,4 @@ - -β€’ First Item                                                                     -    β€’ Nested List Item                                                           -β€’ Second Item                                                                    + +β€’ First Item +    β€’ Nested List Item +β€’ Second Item diff --git a/ansi/testdata/TestRenderer/ordered_list.golden b/ansi/testdata/TestRenderer/ordered_list.golden index c262de69..d2941ee7 100644 --- a/ansi/testdata/TestRenderer/ordered_list.golden +++ b/ansi/testdata/TestRenderer/ordered_list.golden @@ -1,4 +1,4 @@ - -3. 3 is first and numbered 3 -4. 4 is second and numbered 4 -5. ten is third and numbered 5 + +3. 3 is first and numbered 3 +4. 4 is second and numbered 4 +5. ten is third and numbered 5 diff --git a/ansi/testdata/TestRenderer/strikethrough.golden b/ansi/testdata/TestRenderer/strikethrough.golden index 7aae17a4..15c9485d 100644 --- a/ansi/testdata/TestRenderer/strikethrough.golden +++ b/ansi/testdata/TestRenderer/strikethrough.golden @@ -1 +1 @@ -Scratch this. +Scratch this. diff --git a/ansi/testdata/TestRenderer/strong.golden b/ansi/testdata/TestRenderer/strong.golden index 33470429..21be3040 100644 --- a/ansi/testdata/TestRenderer/strong.golden +++ b/ansi/testdata/TestRenderer/strong.golden @@ -1 +1 @@ -This text is strong. +This text is strong. diff --git a/ansi/testdata/TestRenderer/table.golden b/ansi/testdata/TestRenderer/table.golden index eae2429a..82e621f6 100644 --- a/ansi/testdata/TestRenderer/table.golden +++ b/ansi/testdata/TestRenderer/table.golden @@ -1,4 +1,4 @@ - + Label β”‚Value β”‚URL ──────────────────┼────────────────┼──────────────────────────────────────────── First β”‚foo β”‚https://charm.sh https://charm.sh diff --git a/ansi/testdata/TestRenderer/table_align.golden b/ansi/testdata/TestRenderer/table_align.golden index 4507bc62..73ceee6b 100644 --- a/ansi/testdata/TestRenderer/table_align.golden +++ b/ansi/testdata/TestRenderer/table_align.golden @@ -1,4 +1,4 @@ - + Label β”‚ Value β”‚ URL ──────────────────┼────────────────┼──────────────────────────────────────────── First β”‚ foo β”‚ charm.sh diff --git a/ansi/testdata/TestRenderer/task.golden b/ansi/testdata/TestRenderer/task.golden index ead71348..a7bc051d 100644 --- a/ansi/testdata/TestRenderer/task.golden +++ b/ansi/testdata/TestRenderer/task.golden @@ -1,3 +1,3 @@ - -βœ“ Finished Task                                                                  -βœ— Outstanding Task                                                               + +βœ“ Finished Task +βœ— Outstanding Task diff --git a/ansi/testdata/TestRendererIssues/106.golden b/ansi/testdata/TestRendererIssues/106.golden index 6a0e4633..1a5b46f9 100644 --- a/ansi/testdata/TestRendererIssues/106.golden +++ b/ansi/testdata/TestRendererIssues/106.golden @@ -1,17 +1,17 @@ -                                                                              - β€’ `hi`                                                                       - β€’ \hi                                                                        - β€’ *hi                                                                        - β€’ _hi                                                                        - β€’ {hi}                                                                       - β€’ [hi]                                                                       - β€’                                                                        - β€’ (hi)                                                                       - β€’ # hi                                                                       - β€’ + hi                                                                       - β€’ - hi                                                                       - β€’ . hi                                                                       - β€’ ! hi                                                                       - β€’ | hi                                                                       + + β€’ `hi` + β€’ \hi + β€’ *hi + β€’ _hi + β€’ {hi} + β€’ [hi] + β€’  + β€’ (hi) + β€’ # hi + β€’ + hi + β€’ - hi + β€’ . hi + β€’ ! hi + β€’ | hi diff --git a/ansi/testdata/TestRendererIssues/107.golden b/ansi/testdata/TestRendererIssues/107.golden index 87796cf0..10af51e3 100644 --- a/ansi/testdata/TestRendererIssues/107.golden +++ b/ansi/testdata/TestRendererIssues/107.golden @@ -1,7 +1,7 @@ -                                                                              -   [Mount]                                                                    -   Options=reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,noauto,     - _netdev,allow_other,uid=1000,gid=1000,IdentityFile=/PATH/TO/SSH-KEY/id_rsa,  - StrictHostKeyChecking=no                                                     + +     [Mount] +     Options=reconnect,ServerAliveInterval=15,ServerAliveCountMax=3,noauto, + _netdev,allow_other,uid=1000,gid=1000,IdentityFile=/PATH/TO/SSH-KEY/id_rsa, + StrictHostKeyChecking=no  diff --git a/ansi/testdata/TestRendererIssues/117.golden b/ansi/testdata/TestRendererIssues/117.golden index 6456bf56..3e2d9842 100644 --- a/ansi/testdata/TestRendererIssues/117.golden +++ b/ansi/testdata/TestRendererIssues/117.golden @@ -1,6 +1,6 @@ -                                                                              - cmd β”‚descr - ────────────────────────────────────┼─────────────────────────────────────── -  glow config  β”‚open glow config + + cmd β”‚descr + ────────────────────────────────────┼─────────────────────────────────────── +  glow config  β”‚open glow config diff --git a/ansi/testdata/TestRendererIssues/149.golden b/ansi/testdata/TestRendererIssues/149.golden index 86069be8..a790ebd5 100644 --- a/ansi/testdata/TestRendererIssues/149.golden +++ b/ansi/testdata/TestRendererIssues/149.golden @@ -1,5 +1,5 @@ - a http://example.com/with-a-big-path/likely-to-use-more-than-one-line?why-   - not=after-all-                                                               - why-not-use-queryparams-too&abc=123                                          + a http://example.com/with-a-big-path/likely-to-use-more-than-one-line?why- + not=after-all- + why-not-use-queryparams-too&abc=123 diff --git a/ansi/testdata/TestRendererIssues/172.golden b/ansi/testdata/TestRendererIssues/172.golden index 5afc5636..f9acb1db 100644 --- a/ansi/testdata/TestRendererIssues/172.golden +++ b/ansi/testdata/TestRendererIssues/172.golden @@ -1,7 +1,7 @@ -                                                                              - β”‚ The quick brown fox jumps over the lazy dog. The quick brown fox jumps     - over                                                                         - β”‚ the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown - β”‚ fox jumps over the lazy dog.                                               + + β”‚ The quick brown fox jumps over the lazy dog. The quick brown fox jumps + over + β”‚ the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown + β”‚ fox jumps over the lazy dog. diff --git a/ansi/testdata/TestRendererIssues/237.golden b/ansi/testdata/TestRendererIssues/237.golden index 28c37995..be61ffb4 100644 --- a/ansi/testdata/TestRendererIssues/237.golden +++ b/ansi/testdata/TestRendererIssues/237.golden @@ -1,10 +1,10 @@ -                                                                              - β”‚ Content Security Policy (CSP) is an added layer of security that helps to  - β”‚ detect and mitigate certain types of attacks, including Cross-Site         - β”‚ Scripting                                                                  - β”‚ (XSS) and data injection attacks. These attacks are used for everything    - β”‚ from data theft, to site defacement, to malware distribution.              - β”‚                                                                            - β”‚ from MDN                                                                   + + β”‚ Content Security Policy (CSP) is an added layer of security that helps to + β”‚ detect and mitigate certain types of attacks, including Cross-Site + β”‚ Scripting + β”‚ (XSS) and data injection attacks. These attacks are used for everything + β”‚ from data theft, to site defacement, to malware distribution. + β”‚  + β”‚ from MDN diff --git a/ansi/testdata/TestRendererIssues/239.golden b/ansi/testdata/TestRendererIssues/239.golden index 0d88ee10..fd24d448 100644 --- a/ansi/testdata/TestRendererIssues/239.golden +++ b/ansi/testdata/TestRendererIssues/239.golden @@ -1,9 +1,9 @@ -                                                                              - First term                                                                   - 🠢 Definition one of first term.                                              -                                                                              - Second term                                                                  - 🠢 Definition one of second term.                                             -                                                                              + + First term + 🠢 Definition one of first term. + + Second term + 🠢 Definition one of second term. + diff --git a/ansi/testdata/TestRendererIssues/257.golden b/ansi/testdata/TestRendererIssues/257.golden index eeffc6db..261dfd63 100644 --- a/ansi/testdata/TestRendererIssues/257.golden +++ b/ansi/testdata/TestRendererIssues/257.golden @@ -1,4 +1,4 @@ -                                                                              -   set runtimepath^=$XDG_CONFIG_HOME/vim                                      + +     set runtimepath^=$XDG_CONFIG_HOME/vim  diff --git a/ansi/testdata/TestRendererIssues/290.golden b/ansi/testdata/TestRendererIssues/290.golden index 1cc53087..cd8f602a 100644 --- a/ansi/testdata/TestRendererIssues/290.golden +++ b/ansi/testdata/TestRendererIssues/290.golden @@ -1,6 +1,6 @@ -                                                                              - β€’ test@example.com mailto:test@example.com                                   - β€’ https://google.com https://google.com                                      - β€’ https://google.com https://google.com                                      + + β€’ test@example.com mailto:test@example.com + β€’ https://google.com https://google.com + β€’ https://google.com https://google.com diff --git a/ansi/testdata/TestRendererIssues/312.golden b/ansi/testdata/TestRendererIssues/312.golden index 48c9c0ba..ccaa2334 100644 --- a/ansi/testdata/TestRendererIssues/312.golden +++ b/ansi/testdata/TestRendererIssues/312.golden @@ -1,17 +1,17 @@ -  File                                                                        -                                                                              - bold text with URL https://www.example.com                                   -                                                                              - italic text with URL https://www.example.com                                 -                                                                              - URL https://www.example.com                                                  -                                                                              - url with bold within https://www.example.com                                 -                                                                              - url with italic within https://www.example.com                               -                                                                              - entire url text is bold https://www.example.com                              -                                                                              - entire url text is italic https://www.example.com                            +  File  + + bold text with URL https://www.example.com + + italic text with URL https://www.example.com + + URL https://www.example.com + + url with bold within https://www.example.com + + url with italic within https://www.example.com + + entire url text is bold https://www.example.com + + entire url text is italic https://www.example.com diff --git a/ansi/testdata/TestRendererIssues/313.golden b/ansi/testdata/TestRendererIssues/313.golden index 127f65e2..9c89ffa5 100644 --- a/ansi/testdata/TestRendererIssues/313.golden +++ b/ansi/testdata/TestRendererIssues/313.golden @@ -1,8 +1,8 @@ -                                                                              - β”‚ This is a block quote                                                      - β”‚                                                                            - β”‚ β”‚ This is the nested quote                                                 - β”‚                                                                            - β”‚ This is part of the outer block quote.                                     + + β”‚ This is a block quote + β”‚  + β”‚ β”‚ This is the nested quote + β”‚  + β”‚ This is part of the outer block quote. diff --git a/ansi/testdata/TestRendererIssues/315.golden b/ansi/testdata/TestRendererIssues/315.golden index 4cbc3d8e..39f969be 100644 --- a/ansi/testdata/TestRendererIssues/315.golden +++ b/ansi/testdata/TestRendererIssues/315.golden @@ -1,6 +1,6 @@ -                                                                              - Expression β”‚Value β”‚Type - ───────────────────────────────────────────┼────────────────┼─────────────── -  (1 >= 26) || (12 >= 6) {.java} β”‚s β”‚a + + Expression β”‚Value β”‚Type + ───────────────────────────────────────────┼────────────────┼─────────────── +  (1 >= 26) || (12 >= 6) {.java} β”‚s β”‚a diff --git a/ansi/testdata/TestRendererIssues/316.golden b/ansi/testdata/TestRendererIssues/316.golden index 4a7e2032..5226de60 100644 --- a/ansi/testdata/TestRendererIssues/316.golden +++ b/ansi/testdata/TestRendererIssues/316.golden @@ -1,7 +1,7 @@ -                                                                              - Aβ”‚B - ────────────────────────────────────────────────────────┼─────────────────── - Here https://example.comβ”‚hello - https://autolink.com https://autolink.comβ”‚world + + Aβ”‚B + ────────────────────────────────────────────────────────┼─────────────────── + Here https://example.comβ”‚hello + https://autolink.com https://autolink.comβ”‚world diff --git a/ansi/testdata/TestRendererIssues/42.golden b/ansi/testdata/TestRendererIssues/42.golden index 19478759..e6871a95 100644 --- a/ansi/testdata/TestRendererIssues/42.golden +++ b/ansi/testdata/TestRendererIssues/42.golden @@ -1,7 +1,7 @@ - If you want to make a more significant change, please first open an issue    - https://github.com/twpayne/chezmoi/issues/new to discuss the change that you - want to make. Dave Cheney gives a good rationale                             - https://dave.cheney.net/2019/02/18/talk-then-code as to why this is          - important.                                                                   + If you want to make a more significant change, please first open an issue + https://github.com/twpayne/chezmoi/issues/new to discuss the change that you + want to make. Dave Cheney gives a good rationale + https://dave.cheney.net/2019/02/18/talk-then-code as to why this is + important. diff --git a/ansi/testdata/TestRendererIssues/43.golden b/ansi/testdata/TestRendererIssues/43.golden index f88488f2..a22ecc05 100644 --- a/ansi/testdata/TestRendererIssues/43.golden +++ b/ansi/testdata/TestRendererIssues/43.golden @@ -1,10 +1,10 @@ -                                                                              - β€’ Getting started                                                            - β€’ Developing locally                                                         - β€’ Documentation changes                                                      - β€’ Contributing changes                                                       - β€’ Managing releases                                                          - β€’ Packaging                                                                  - β€’ Updating the website                                                       + + β€’ Getting started + β€’ Developing locally + β€’ Documentation changes + β€’ Contributing changes + β€’ Managing releases + β€’ Packaging + β€’ Updating the website diff --git a/ansi/testdata/TestRendererIssues/44.golden b/ansi/testdata/TestRendererIssues/44.golden index 60fb0347..76b33f03 100644 --- a/ansi/testdata/TestRendererIssues/44.golden +++ b/ansi/testdata/TestRendererIssues/44.golden @@ -1,9 +1,9 @@ -                                                                              - Distri…β”‚Architectures β”‚Package - ───────┼─────────────────────────────────┼────────────────────────────────── - Debian β”‚ amd64 ,  arm64 ,  armel ,  i386…β”‚ deb  https://github.com/twpayne/… - RedHat β”‚ aarch64 ,  armhfp ,  i686 ,  pp…β”‚ rpm  https://github.com/twpayne/… - OpenSU…β”‚ aarch64 ,  armhfp ,  i686 ,  pp…β”‚ rpm  https://github.com/twpayne/… - Ubuntu β”‚ amd64 ,  arm64 ,  armel ,  i386…β”‚ deb  https://github.com/twpayne/… + + Distri…β”‚Architectures β”‚Package + ───────┼─────────────────────────────────┼────────────────────────────────── + Debian β”‚ amd64 ,  arm64 ,  armel ,  i386…β”‚ deb  https://github.com/twpayne/… + RedHat β”‚ aarch64 ,  armhfp ,  i686 ,  pp…β”‚ rpm  https://github.com/twpayne/… + OpenSU…β”‚ aarch64 ,  armhfp ,  i686 ,  pp…β”‚ rpm  https://github.com/twpayne/… + Ubuntu β”‚ amd64 ,  arm64 ,  armel ,  i386…β”‚ deb  https://github.com/twpayne/… diff --git a/ansi/testdata/TestRendererIssues/46_1.golden b/ansi/testdata/TestRendererIssues/46_1.golden index 0eb404ed..be7831a3 100644 --- a/ansi/testdata/TestRendererIssues/46_1.golden +++ b/ansi/testdata/TestRendererIssues/46_1.golden @@ -1,6 +1,6 @@ -                                                                              - β€’ Navigation                                                                 -   β€’ Familiar shortcuts (arrows, ~, -, @), quick reference                    -                                                                              + + β€’ Navigation +   β€’ Familiar shortcuts (arrows, ~, -, @), quick reference + diff --git a/ansi/testdata/TestRendererIssues/46_2.golden b/ansi/testdata/TestRendererIssues/46_2.golden index 745200bc..5512df15 100644 --- a/ansi/testdata/TestRendererIssues/46_2.golden +++ b/ansi/testdata/TestRendererIssues/46_2.golden @@ -1,14 +1,14 @@ -                                                                              - Dependency β”‚Installa…β”‚Operation - ─────────────────────────────────────────┼─────────┼──────────────────────── - xdg-open (Linux), open(1) (macOS), cygst…β”‚base β”‚desktop opener - file, coreutils (cp, mv, rm), xargs β”‚base β”‚file type, copy, move a… - tar, (un)zip [atool/bsdtar for more form…β”‚base β”‚create, list, extract t… - archivemount, fusermount(3) β”‚optional β”‚mount, unmount archives - sshfs, rclone https://rclone.org/, fuser…β”‚optional β”‚mount, unmount remotes - trash-cli β”‚optional β”‚trash files (default ac… - vlock (Linux), bashlock (macOS), lock(1)…β”‚optional β”‚terminal locker (fallba… - advcpmv (Linux) (integration https://git…β”‚optional β”‚copy, move progress -  $VISUAL  (else  $EDITOR ),  $PAGER ,  $…β”‚optional β”‚fallback vi, less, sh + + Dependency β”‚Installa…β”‚Operation + ─────────────────────────────────────────┼─────────┼──────────────────────── + xdg-open (Linux), open(1) (macOS), cygst…β”‚base β”‚desktop opener + file, coreutils (cp, mv, rm), xargs β”‚base β”‚file type, copy, move a… + tar, (un)zip [atool/bsdtar for more form…β”‚base β”‚create, list, extract t… + archivemount, fusermount(3) β”‚optional β”‚mount, unmount archives + sshfs, rclone https://rclone.org/, fuser…β”‚optional β”‚mount, unmount remotes + trash-cli β”‚optional β”‚trash files (default ac… + vlock (Linux), bashlock (macOS), lock(1)…β”‚optional β”‚terminal locker (fallba… + advcpmv (Linux) (integration https://git…β”‚optional β”‚copy, move progress +  $VISUAL  (else  $EDITOR ),  $PAGER ,  $…β”‚optional β”‚fallback vi, less, sh diff --git a/ansi/testdata/TestRendererIssues/47.golden b/ansi/testdata/TestRendererIssues/47.golden index 5422c7c3..c663b3d4 100644 --- a/ansi/testdata/TestRendererIssues/47.golden +++ b/ansi/testdata/TestRendererIssues/47.golden @@ -1,3 +1,3 @@ - Example:                                                    + Example:   diff --git a/ansi/testdata/TestRendererIssues/48.golden b/ansi/testdata/TestRendererIssues/48.golden index a20338ce..379dce4f 100644 --- a/ansi/testdata/TestRendererIssues/48.golden +++ b/ansi/testdata/TestRendererIssues/48.golden @@ -1,17 +1,17 @@ - emoji in text                                                                -                                                                              - πŸ™ ⚑ 🐱 = ❀️                                                                -                                                                              - emoji in header                                                              -                                                                              - ## πŸ™ ⚑ 🐱 = ❀️                                                             -                                                                              - no emoji in code blocks                                                      -                                                                              -   :octopus: :zap: :cat: = :heart:                                            -                                                                              - no emoji in inline code                                                      -                                                                              -  :octopus: :zap: :cat: = :heart:                                             + emoji in text + + πŸ™ ⚑ 🐱 = ❀️ + + emoji in header +  + ## πŸ™ ⚑ 🐱 = ❀️ + + no emoji in code blocks + +     :octopus: :zap: :cat: = :heart: + + no emoji in inline code + +  :octopus: :zap: :cat: = :heart:  diff --git a/ansi/testdata/TestRendererIssues/60.golden b/ansi/testdata/TestRendererIssues/60.golden index c9c8688a..3ee492bd 100644 --- a/ansi/testdata/TestRendererIssues/60.golden +++ b/ansi/testdata/TestRendererIssues/60.golden @@ -1,28 +1,28 @@ -                                                                              - Library β”‚Version - ─────────────────────────────────────────────────────────────┼────────────── - ESMF https://github.com/esmf-org/esmf β”‚v8.6.1 - FMS https://github.com/NOAA-GFDL/FMS/ β”‚2024.01.02 - netCDF https://github.com/Unidata/netcdf-c β”‚4.9.2 - netCDF Fortran https://github.com/Unidata/netcdf-fortran β”‚4.6.1 - netCDF C++ https://github.com/Unidata/netcdf-cxx4 β”‚4.3.1 - HDF5 https://portal.hdfgroup.org/display/support β”‚1.10.11 - HDF4 https://portal.hdfgroup.org/display/support β”‚4.2.16-2 - GFE https://github.com/Goddard-Fortran-Ecosystem/GFE β”‚v1.16.0 - xgboost https://github.com/dmlc/xgboost β”‚v1.6.0 - libyaml https://github.com/yaml/libyaml.git β”‚0.2.5 - antlr2 https://www.antlr2.org/ β”‚2.7.7 - GSL https://www.gnu.org/software/gsl/ β”‚2.7 - jpeg http://www.ijg.org/ β”‚9e - zlib http://www.zlib.net/ β”‚1.3.1 - szip https://support.hdfgroup.org/doc_resource/SZIP/ β”‚2.1.1 - cURL https://curl.haxx.se/ β”‚8.8.0 - UDUNITS2 https://github.com/GMAO-SI-Team/UDUNITS-2.git β”‚2.2.28 - NCO http://nco.sourceforge.net/ β”‚5.2.6 - CDO https://code.mpimet.mpg.de/projects/cdo β”‚2.3.0 - nccmp https://gitlab.com/remikz/nccmp β”‚1.9.1.0 - HDF-EOS2 https://wiki.earthdata.nasa.gov/display/DAS β”‚3.0 - HDF-EOS5 https://wiki.earthdata.nasa.gov/display/DAS β”‚2.0 - SDP Toolkit https://wiki.earthdata.nasa.gov/display/DAS β”‚5.2.20 + + Library β”‚Version + ─────────────────────────────────────────────────────────────┼────────────── + ESMF https://github.com/esmf-org/esmf β”‚v8.6.1 + FMS https://github.com/NOAA-GFDL/FMS/ β”‚2024.01.02 + netCDF https://github.com/Unidata/netcdf-c β”‚4.9.2 + netCDF Fortran https://github.com/Unidata/netcdf-fortran β”‚4.6.1 + netCDF C++ https://github.com/Unidata/netcdf-cxx4 β”‚4.3.1 + HDF5 https://portal.hdfgroup.org/display/support β”‚1.10.11 + HDF4 https://portal.hdfgroup.org/display/support β”‚4.2.16-2 + GFE https://github.com/Goddard-Fortran-Ecosystem/GFE β”‚v1.16.0 + xgboost https://github.com/dmlc/xgboost β”‚v1.6.0 + libyaml https://github.com/yaml/libyaml.git β”‚0.2.5 + antlr2 https://www.antlr2.org/ β”‚2.7.7 + GSL https://www.gnu.org/software/gsl/ β”‚2.7 + jpeg http://www.ijg.org/ β”‚9e + zlib http://www.zlib.net/ β”‚1.3.1 + szip https://support.hdfgroup.org/doc_resource/SZIP/ β”‚2.1.1 + cURL https://curl.haxx.se/ β”‚8.8.0 + UDUNITS2 https://github.com/GMAO-SI-Team/UDUNITS-2.git β”‚2.2.28 + NCO http://nco.sourceforge.net/ β”‚5.2.6 + CDO https://code.mpimet.mpg.de/projects/cdo β”‚2.3.0 + nccmp https://gitlab.com/remikz/nccmp β”‚1.9.1.0 + HDF-EOS2 https://wiki.earthdata.nasa.gov/display/DAS β”‚3.0 + HDF-EOS5 https://wiki.earthdata.nasa.gov/display/DAS β”‚2.0 + SDP Toolkit https://wiki.earthdata.nasa.gov/display/DAS β”‚5.2.20 diff --git a/ansi/testdata/TestRendererIssues/79.golden b/ansi/testdata/TestRendererIssues/79.golden index 23b0f168..8180b20f 100644 --- a/ansi/testdata/TestRendererIssues/79.golden +++ b/ansi/testdata/TestRendererIssues/79.golden @@ -1,9 +1,9 @@ - Preceding blockquote paragraph                                               -                                                                              - β”‚ 1st blockquote paragraph                                                   - β”‚                                                                            - β”‚   quoted code block                                                        - β”‚                                                                            - β”‚ 2nd blockquote paragraph                                                   + Preceding blockquote paragraph + + β”‚ 1st blockquote paragraph + β”‚  + β”‚     quoted code block + β”‚  + β”‚ 2nd blockquote paragraph diff --git a/examples/artichokes/main.go b/examples/artichokes/main.go index 231f154e..fc6903b7 100644 --- a/examples/artichokes/main.go +++ b/examples/artichokes/main.go @@ -6,8 +6,9 @@ import ( "log" "os" - "github.com/charmbracelet/glamour" "github.com/muesli/termenv" + + "github.com/charmbracelet/glamour" ) //go:embed artichokes.md diff --git a/glamour.go b/glamour.go index 6a8a1c38..c7c50229 100644 --- a/glamour.go +++ b/glamour.go @@ -16,7 +16,7 @@ import ( "golang.org/x/term" "github.com/charmbracelet/glamour/ansi" - styles "github.com/charmbracelet/glamour/styles" + "github.com/charmbracelet/glamour/styles" ) const ( diff --git a/glamour_test.go b/glamour_test.go index dc152a72..cf00b930 100644 --- a/glamour_test.go +++ b/glamour_test.go @@ -8,8 +8,9 @@ import ( "strings" "testing" - styles "github.com/charmbracelet/glamour/styles" "github.com/charmbracelet/x/exp/golden" + + styles "github.com/charmbracelet/glamour/styles" ) const markdown = "testdata/readme.markdown.in" diff --git a/testdata/TestCapitalization.golden b/testdata/TestCapitalization.golden index 2c684356..cb35a6b8 100644 --- a/testdata/TestCapitalization.golden +++ b/testdata/TestCapitalization.golden @@ -1,7 +1,7 @@ -  EVERYTHING IS UPPERCASE                                                     -                                                                              - ## Everything Is Titled                                                      -                                                                              - ### everything is lowercase                                                  +  EVERYTHING IS UPPERCASE  +  + ## Everything Is Titled +  + ### everything is lowercase  diff --git a/testdata/TestRenderHelpers.golden b/testdata/TestRenderHelpers.golden index e598ccaa..7c3344ab 100644 --- a/testdata/TestRenderHelpers.golden +++ b/testdata/TestRenderHelpers.golden @@ -1,40 +1,40 @@ -  Gold                                                                        -                                                                              - Render markdown on the CLI, with pizzazz!                                    -                                                                              - ## 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                                                                     -                                                                              - See cmd/gold /cmd/gold/.                                                     -                                                                              - ## Example Output                                                            -                                                                              - Image: Gold Dark Style β†’                                                     - https://github.com/charmbracelet/gold/raw/master/styles/gallery/dark.png     -                                                                              - Check out the Gold Style Gallery                                             - https://github.com/charmbracelet/gold/blob/master/styles/gallery/README.md!  -                                                                              - ## Colors                                                                    -                                                                              - Currently  gold  uses the Aurora ANSI colors                                 - https://godoc.org/github.com/logrusorgru/aurora#Index.                       -                                                                              - ## Development                                                               -                                                                              - Style definitions located in  styles/  can be embedded into the binary by    - running statik https://github.com/rakyll/statik:                             -                                                                              -   statik -f -src styles -include "*.json"                                    -                                                                              - You can re-generate screenshots of all available styles by running           - gallery.sh . This requires  termshot  and  pngcrush  installed on your       - system!                                                                      +  Gold  + + Render markdown on the CLI, with pizzazz! +  + ## 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 + + See cmd/gold /cmd/gold/. +  + ## Example Output + + Image: Gold Dark Style β†’ + https://github.com/charmbracelet/gold/raw/master/styles/gallery/dark.png + + Check out the Gold Style Gallery + https://github.com/charmbracelet/gold/blob/master/styles/gallery/README.md! +  + ## Colors + + Currently  gold  uses the Aurora ANSI colors + https://godoc.org/github.com/logrusorgru/aurora#Index. +  + ## Development + + Style definitions located in  styles/  can be embedded into the binary by + running statik https://github.com/rakyll/statik: + +     statik -f -src styles -include "*.json" + + You can re-generate screenshots of all available styles by running  + gallery.sh . This requires  termshot  and  pngcrush  installed on your + system! diff --git a/testdata/TestTermRenderer.golden b/testdata/TestTermRenderer.golden index e598ccaa..7c3344ab 100644 --- a/testdata/TestTermRenderer.golden +++ b/testdata/TestTermRenderer.golden @@ -1,40 +1,40 @@ -  Gold                                                                        -                                                                              - Render markdown on the CLI, with pizzazz!                                    -                                                                              - ## 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                                                                     -                                                                              - See cmd/gold /cmd/gold/.                                                     -                                                                              - ## Example Output                                                            -                                                                              - Image: Gold Dark Style β†’                                                     - https://github.com/charmbracelet/gold/raw/master/styles/gallery/dark.png     -                                                                              - Check out the Gold Style Gallery                                             - https://github.com/charmbracelet/gold/blob/master/styles/gallery/README.md!  -                                                                              - ## Colors                                                                    -                                                                              - Currently  gold  uses the Aurora ANSI colors                                 - https://godoc.org/github.com/logrusorgru/aurora#Index.                       -                                                                              - ## Development                                                               -                                                                              - Style definitions located in  styles/  can be embedded into the binary by    - running statik https://github.com/rakyll/statik:                             -                                                                              -   statik -f -src styles -include "*.json"                                    -                                                                              - You can re-generate screenshots of all available styles by running           - gallery.sh . This requires  termshot  and  pngcrush  installed on your       - system!                                                                      +  Gold  + + Render markdown on the CLI, with pizzazz! +  + ## 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 + + See cmd/gold /cmd/gold/. +  + ## Example Output + + Image: Gold Dark Style β†’ + https://github.com/charmbracelet/gold/raw/master/styles/gallery/dark.png + + Check out the Gold Style Gallery + https://github.com/charmbracelet/gold/blob/master/styles/gallery/README.md! +  + ## Colors + + Currently  gold  uses the Aurora ANSI colors + https://godoc.org/github.com/logrusorgru/aurora#Index. +  + ## Development + + Style definitions located in  styles/  can be embedded into the binary by + running statik https://github.com/rakyll/statik: + +     statik -f -src styles -include "*.json" + + You can re-generate screenshots of all available styles by running  + gallery.sh . This requires  termshot  and  pngcrush  installed on your + system! diff --git a/testdata/TestTermRendererWriter.golden b/testdata/TestTermRendererWriter.golden index e598ccaa..7c3344ab 100644 --- a/testdata/TestTermRendererWriter.golden +++ b/testdata/TestTermRendererWriter.golden @@ -1,40 +1,40 @@ -  Gold                                                                        -                                                                              - Render markdown on the CLI, with pizzazz!                                    -                                                                              - ## 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                                                                     -                                                                              - See cmd/gold /cmd/gold/.                                                     -                                                                              - ## Example Output                                                            -                                                                              - Image: Gold Dark Style β†’                                                     - https://github.com/charmbracelet/gold/raw/master/styles/gallery/dark.png     -                                                                              - Check out the Gold Style Gallery                                             - https://github.com/charmbracelet/gold/blob/master/styles/gallery/README.md!  -                                                                              - ## Colors                                                                    -                                                                              - Currently  gold  uses the Aurora ANSI colors                                 - https://godoc.org/github.com/logrusorgru/aurora#Index.                       -                                                                              - ## Development                                                               -                                                                              - Style definitions located in  styles/  can be embedded into the binary by    - running statik https://github.com/rakyll/statik:                             -                                                                              -   statik -f -src styles -include "*.json"                                    -                                                                              - You can re-generate screenshots of all available styles by running           - gallery.sh . This requires  termshot  and  pngcrush  installed on your       - system!                                                                      +  Gold  + + Render markdown on the CLI, with pizzazz! +  + ## 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 + + See cmd/gold /cmd/gold/. +  + ## Example Output + + Image: Gold Dark Style β†’ + https://github.com/charmbracelet/gold/raw/master/styles/gallery/dark.png + + Check out the Gold Style Gallery + https://github.com/charmbracelet/gold/blob/master/styles/gallery/README.md! +  + ## Colors + + Currently  gold  uses the Aurora ANSI colors + https://godoc.org/github.com/logrusorgru/aurora#Index. +  + ## Development + + Style definitions located in  styles/  can be embedded into the binary by + running statik https://github.com/rakyll/statik: + +     statik -f -src styles -include "*.json" + + You can re-generate screenshots of all available styles by running  + gallery.sh . This requires  termshot  and  pngcrush  installed on your + system! diff --git a/testdata/TestWithPreservedNewLines.golden b/testdata/TestWithPreservedNewLines.golden index 54f4f7c5..4bfc295f 100644 --- a/testdata/TestWithPreservedNewLines.golden +++ b/testdata/TestWithPreservedNewLines.golden @@ -1,5 +1,5 @@ -Preserving line breaks will ensure -that this text displays on two separate lines - -While this text appears on one line, it will wrap when the text meets the -renderer's default value of 80 characters +Preserving line breaks will ensure +that this text displays on two separate lines + +While this text appears on one line, it will wrap when the text meets the +renderer's default value of 80 characters