wrap lines on examples
This commit is contained in:
parent
7f5274b34d
commit
833708e38a
2 changed files with 8 additions and 1 deletions
|
|
@ -65,5 +65,10 @@ func renderCodeToString(snippet *Snippet) *h.Element {
|
||||||
source = out.String()
|
source = out.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
return ui.GoCodeSnippet(source, "border-radius: 0.5rem;")
|
return ui.CodeSnippet(ui.CodeSnippetProps{
|
||||||
|
Code: source,
|
||||||
|
Lang: "go",
|
||||||
|
CustomStyles: []string{"border-radius: 0.5rem;"},
|
||||||
|
WrapLines: true,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ func FormatCode(props CodeSnippetProps) string {
|
||||||
lexer := lexers.Get(props.Lang)
|
lexer := lexers.Get(props.Lang)
|
||||||
style := styles.Get("github")
|
style := styles.Get("github")
|
||||||
formatter := html.New(
|
formatter := html.New(
|
||||||
|
html.WrapLongLines(props.WrapLines),
|
||||||
html.WithLineNumbers(!props.SingleLine && !props.HideLineNumbers),
|
html.WithLineNumbers(!props.SingleLine && !props.HideLineNumbers),
|
||||||
html.WithCustomCSS(map[chroma.TokenType]string{
|
html.WithCustomCSS(map[chroma.TokenType]string{
|
||||||
chroma.PreWrapper: fmt.Sprintf("border-radius: 0.2rem; line-height: 24px; font-size: 14px; padding: 12px; overflow: auto; background-color: rgb(245, 245, 245) !important; %s", strings.Join(props.CustomStyles, ";")),
|
chroma.PreWrapper: fmt.Sprintf("border-radius: 0.2rem; line-height: 24px; font-size: 14px; padding: 12px; overflow: auto; background-color: rgb(245, 245, 245) !important; %s", strings.Join(props.CustomStyles, ";")),
|
||||||
|
|
@ -42,6 +43,7 @@ type CodeSnippetProps struct {
|
||||||
CustomStyles []string
|
CustomStyles []string
|
||||||
HideLineNumbers bool
|
HideLineNumbers bool
|
||||||
SingleLine bool
|
SingleLine bool
|
||||||
|
WrapLines bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func CodeSnippet(props CodeSnippetProps) *h.Element {
|
func CodeSnippet(props CodeSnippetProps) *h.Element {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue