mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-09-06 08:57:14 -04:00
Reuse reflow's writer-pipes
This commit is contained in:
+7
-11
@@ -6,7 +6,6 @@ import (
|
||||
"github.com/alecthomas/chroma"
|
||||
"github.com/alecthomas/chroma/quick"
|
||||
"github.com/alecthomas/chroma/styles"
|
||||
"github.com/muesli/reflow/ansi"
|
||||
"github.com/muesli/reflow/indent"
|
||||
)
|
||||
|
||||
@@ -102,21 +101,18 @@ func (e *CodeBlockElement) Render(w io.Writer, ctx RenderContext) error {
|
||||
}))
|
||||
}
|
||||
|
||||
iw := &indent.Writer{
|
||||
Indent: indentation + margin,
|
||||
IndentFunc: func(wr io.Writer) {
|
||||
renderText(w, ctx.colorProfile, bs.Current().Style.StylePrimitive, " ")
|
||||
},
|
||||
Forward: &ansi.Writer{
|
||||
Forward: w,
|
||||
},
|
||||
}
|
||||
iw := indent.NewWriterPipe(w, indentation+margin, func(wr io.Writer) {
|
||||
renderText(w, ctx.colorProfile, bs.Current().Style.StylePrimitive, " ")
|
||||
})
|
||||
|
||||
if len(theme) > 0 {
|
||||
renderText(iw, ctx.colorProfile, bs.Current().Style.StylePrimitive, rules.BlockPrefix)
|
||||
err := quick.Highlight(iw, e.Code, e.Language, "terminal256", theme)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
renderText(iw, ctx.colorProfile, bs.Current().Style.StylePrimitive, rules.BlockSuffix)
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// fallback rendering
|
||||
|
||||
+3
-10
@@ -4,7 +4,6 @@ import (
|
||||
"bytes"
|
||||
"io"
|
||||
|
||||
"github.com/muesli/reflow/ansi"
|
||||
"github.com/muesli/reflow/indent"
|
||||
"github.com/muesli/reflow/wordwrap"
|
||||
)
|
||||
@@ -62,15 +61,9 @@ func (e *HeadingElement) Finish(w io.Writer, ctx RenderContext) error {
|
||||
margin = *rules.Margin
|
||||
}
|
||||
|
||||
iw := &indent.Writer{
|
||||
Indent: indentation + margin,
|
||||
IndentFunc: func(wr io.Writer) {
|
||||
renderText(w, ctx.colorProfile, bs.Parent().Style.StylePrimitive, " ")
|
||||
},
|
||||
Forward: &ansi.Writer{
|
||||
Forward: w,
|
||||
},
|
||||
}
|
||||
iw := indent.NewWriterPipe(w, indentation+margin, func(wr io.Writer) {
|
||||
renderText(w, ctx.colorProfile, bs.Parent().Style.StylePrimitive, " ")
|
||||
})
|
||||
|
||||
flow := wordwrap.NewWriter(int(bs.Width(ctx) - indentation - margin*2))
|
||||
_, err := flow.Write(bs.Current().Block.Bytes())
|
||||
|
||||
+6
-19
@@ -3,7 +3,6 @@ package ansi
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/muesli/reflow/ansi"
|
||||
"github.com/muesli/reflow/indent"
|
||||
"github.com/muesli/reflow/padding"
|
||||
)
|
||||
@@ -29,29 +28,17 @@ func NewMarginWriter(ctx RenderContext, w io.Writer, rules StyleBlock) *MarginWr
|
||||
margin = *rules.Margin
|
||||
}
|
||||
|
||||
pw := &padding.Writer{
|
||||
Padding: bs.Width(ctx),
|
||||
PadFunc: func(wr io.Writer) {
|
||||
renderText(w, ctx.colorProfile, rules.StylePrimitive, " ")
|
||||
},
|
||||
Forward: &ansi.Writer{
|
||||
Forward: w,
|
||||
},
|
||||
}
|
||||
pw := padding.NewWriterPipe(w, bs.Width(ctx), func(wr io.Writer) {
|
||||
renderText(w, ctx.colorProfile, rules.StylePrimitive, " ")
|
||||
})
|
||||
|
||||
ic := " "
|
||||
if rules.IndentToken != nil {
|
||||
ic = *rules.IndentToken
|
||||
}
|
||||
iw := &indent.Writer{
|
||||
Indent: indentation + margin,
|
||||
IndentFunc: func(wr io.Writer) {
|
||||
renderText(w, ctx.colorProfile, bs.Parent().Style.StylePrimitive, ic)
|
||||
},
|
||||
Forward: &ansi.Writer{
|
||||
Forward: pw,
|
||||
},
|
||||
}
|
||||
iw := indent.NewWriterPipe(pw, indentation+margin, func(wr io.Writer) {
|
||||
renderText(w, ctx.colorProfile, bs.Parent().Style.StylePrimitive, ic)
|
||||
})
|
||||
|
||||
return &MarginWriter{
|
||||
w: w,
|
||||
|
||||
+3
-10
@@ -3,7 +3,6 @@ package ansi
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/muesli/reflow/ansi"
|
||||
"github.com/muesli/reflow/indent"
|
||||
"github.com/olekukonko/tablewriter"
|
||||
)
|
||||
@@ -43,15 +42,9 @@ func (e *TableElement) Render(w io.Writer, ctx RenderContext) error {
|
||||
margin = *rules.Margin
|
||||
}
|
||||
|
||||
iw := &indent.Writer{
|
||||
Indent: indentation + margin,
|
||||
IndentFunc: func(wr io.Writer) {
|
||||
renderText(w, ctx.colorProfile, bs.Current().Style.StylePrimitive, " ")
|
||||
},
|
||||
Forward: &ansi.Writer{
|
||||
Forward: w,
|
||||
},
|
||||
}
|
||||
iw := indent.NewWriterPipe(w, indentation+margin, func(wr io.Writer) {
|
||||
renderText(w, ctx.colorProfile, bs.Current().Style.StylePrimitive, " ")
|
||||
})
|
||||
|
||||
style := bs.With(rules.StylePrimitive)
|
||||
ctx.table.styleWriter = NewStyleWriter(ctx, iw, style)
|
||||
|
||||
Reference in New Issue
Block a user