mirror of
https://github.com/rwinkhart/glamour-temp-MUTN.git
synced 2026-08-27 20:36:26 -04:00
508 lines
11 KiB
Go
508 lines
11 KiB
Go
package glamour
|
|
|
|
//go:generate go run ./internal/generate-style-json
|
|
|
|
import (
|
|
"github.com/charmbracelet/glamour/ansi"
|
|
)
|
|
|
|
const defaultListIndent = 2
|
|
const defaultListLevelIndent = 4
|
|
const defaultMargin = 2
|
|
|
|
var (
|
|
// ASCIIStyleConfig uses only ASCII characters.
|
|
ASCIIStyleConfig = ansi.StyleConfig{
|
|
Document: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
BlockPrefix: "\n",
|
|
BlockSuffix: "\n",
|
|
},
|
|
Margin: uintPtr(defaultMargin),
|
|
},
|
|
BlockQuote: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{},
|
|
Indent: uintPtr(1),
|
|
IndentToken: stringPtr("| "),
|
|
},
|
|
Paragraph: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{},
|
|
},
|
|
List: ansi.StyleList{
|
|
StyleBlock: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{},
|
|
},
|
|
LevelIndent: defaultListLevelIndent,
|
|
},
|
|
Heading: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
BlockSuffix: "\n",
|
|
},
|
|
},
|
|
H1: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "# ",
|
|
},
|
|
},
|
|
H2: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "## ",
|
|
},
|
|
},
|
|
H3: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "### ",
|
|
},
|
|
},
|
|
H4: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "#### ",
|
|
},
|
|
},
|
|
H5: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "##### ",
|
|
},
|
|
},
|
|
H6: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "###### ",
|
|
},
|
|
},
|
|
Strikethrough: ansi.StylePrimitive{
|
|
BlockPrefix: "~~",
|
|
BlockSuffix: "~~",
|
|
},
|
|
Emph: ansi.StylePrimitive{
|
|
BlockPrefix: "*",
|
|
BlockSuffix: "*",
|
|
},
|
|
Strong: ansi.StylePrimitive{
|
|
BlockPrefix: "**",
|
|
BlockSuffix: "**",
|
|
},
|
|
HorizontalRule: ansi.StylePrimitive{
|
|
Format: "\n--------\n",
|
|
},
|
|
Item: ansi.StylePrimitive{
|
|
BlockPrefix: "• ",
|
|
},
|
|
Enumeration: ansi.StylePrimitive{
|
|
BlockPrefix: ". ",
|
|
},
|
|
Task: ansi.StyleTask{
|
|
Ticked: "[x] ",
|
|
Unticked: "[ ] ",
|
|
},
|
|
ImageText: ansi.StylePrimitive{
|
|
Format: "Image: {{.text}} →",
|
|
},
|
|
Code: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
BlockPrefix: "`",
|
|
BlockSuffix: "`",
|
|
},
|
|
},
|
|
CodeBlock: ansi.StyleCodeBlock{
|
|
StyleBlock: ansi.StyleBlock{
|
|
Margin: uintPtr(defaultMargin),
|
|
},
|
|
},
|
|
Table: ansi.StyleTable{
|
|
CenterSeparator: stringPtr("+"),
|
|
ColumnSeparator: stringPtr("|"),
|
|
RowSeparator: stringPtr("-"),
|
|
},
|
|
DefinitionDescription: ansi.StylePrimitive{
|
|
BlockPrefix: "\n* ",
|
|
},
|
|
}
|
|
|
|
// DarkStyleConfig is the default dark style.
|
|
DarkStyleConfig = ansi.StyleConfig{
|
|
Document: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
BlockPrefix: "\n",
|
|
BlockSuffix: "\n",
|
|
Color: stringPtr("252"),
|
|
},
|
|
Margin: uintPtr(defaultMargin),
|
|
},
|
|
BlockQuote: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{},
|
|
Indent: uintPtr(1),
|
|
IndentToken: stringPtr("│ "),
|
|
},
|
|
List: ansi.StyleList{
|
|
LevelIndent: defaultListIndent,
|
|
},
|
|
Heading: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
BlockSuffix: "\n",
|
|
Color: stringPtr("39"),
|
|
Bold: boolPtr(true),
|
|
},
|
|
},
|
|
H1: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: " ",
|
|
Suffix: " ",
|
|
Color: stringPtr("228"),
|
|
BackgroundColor: stringPtr("63"),
|
|
Bold: boolPtr(true),
|
|
},
|
|
},
|
|
H2: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "## ",
|
|
},
|
|
},
|
|
H3: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "### ",
|
|
},
|
|
},
|
|
H4: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "#### ",
|
|
},
|
|
},
|
|
H5: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "##### ",
|
|
},
|
|
},
|
|
H6: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "###### ",
|
|
Color: stringPtr("35"),
|
|
Bold: boolPtr(false),
|
|
},
|
|
},
|
|
Strikethrough: ansi.StylePrimitive{
|
|
CrossedOut: boolPtr(true),
|
|
},
|
|
Emph: ansi.StylePrimitive{
|
|
Italic: boolPtr(true),
|
|
},
|
|
Strong: ansi.StylePrimitive{
|
|
Bold: boolPtr(true),
|
|
},
|
|
HorizontalRule: ansi.StylePrimitive{
|
|
Color: stringPtr("240"),
|
|
Format: "\n--------\n",
|
|
},
|
|
Item: ansi.StylePrimitive{
|
|
BlockPrefix: "• ",
|
|
},
|
|
Enumeration: ansi.StylePrimitive{
|
|
BlockPrefix: ". ",
|
|
},
|
|
Task: ansi.StyleTask{
|
|
StylePrimitive: ansi.StylePrimitive{},
|
|
Ticked: "[✓] ",
|
|
Unticked: "[ ] ",
|
|
},
|
|
Link: ansi.StylePrimitive{
|
|
Color: stringPtr("30"),
|
|
Underline: boolPtr(true),
|
|
},
|
|
LinkText: ansi.StylePrimitive{
|
|
Color: stringPtr("35"),
|
|
Bold: boolPtr(true),
|
|
},
|
|
Image: ansi.StylePrimitive{
|
|
Color: stringPtr("212"),
|
|
Underline: boolPtr(true),
|
|
},
|
|
ImageText: ansi.StylePrimitive{
|
|
Color: stringPtr("243"),
|
|
Format: "Image: {{.text}} →",
|
|
},
|
|
Code: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: " ",
|
|
Suffix: " ",
|
|
Color: stringPtr("203"),
|
|
BackgroundColor: stringPtr("236"),
|
|
},
|
|
},
|
|
CodeBlock: ansi.StyleCodeBlock{
|
|
StyleBlock: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Color: stringPtr("244"),
|
|
},
|
|
Margin: uintPtr(defaultMargin),
|
|
},
|
|
},
|
|
Table: ansi.StyleTable{
|
|
StyleBlock: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{},
|
|
},
|
|
CenterSeparator: stringPtr("┼"),
|
|
ColumnSeparator: stringPtr("│"),
|
|
RowSeparator: stringPtr("─"),
|
|
},
|
|
DefinitionDescription: ansi.StylePrimitive{
|
|
BlockPrefix: "\n🠶 ",
|
|
},
|
|
}
|
|
|
|
// LightStyleConfig is the default light style.
|
|
LightStyleConfig = ansi.StyleConfig{
|
|
Document: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
BlockPrefix: "\n",
|
|
BlockSuffix: "\n",
|
|
Color: stringPtr("234"),
|
|
},
|
|
Margin: uintPtr(defaultMargin),
|
|
},
|
|
BlockQuote: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{},
|
|
Indent: uintPtr(1),
|
|
IndentToken: stringPtr("│ "),
|
|
},
|
|
List: ansi.StyleList{
|
|
LevelIndent: defaultListIndent,
|
|
},
|
|
Heading: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
BlockSuffix: "\n",
|
|
Color: stringPtr("27"),
|
|
Bold: boolPtr(true),
|
|
},
|
|
},
|
|
H1: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: " ",
|
|
Suffix: " ",
|
|
Color: stringPtr("228"),
|
|
BackgroundColor: stringPtr("63"),
|
|
Bold: boolPtr(true),
|
|
},
|
|
},
|
|
H2: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "## ",
|
|
},
|
|
},
|
|
H3: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "### ",
|
|
},
|
|
},
|
|
H4: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "#### ",
|
|
},
|
|
},
|
|
H5: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "##### ",
|
|
},
|
|
},
|
|
H6: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "###### ",
|
|
Bold: boolPtr(false),
|
|
},
|
|
},
|
|
Strikethrough: ansi.StylePrimitive{
|
|
CrossedOut: boolPtr(true),
|
|
},
|
|
Emph: ansi.StylePrimitive{
|
|
Italic: boolPtr(true),
|
|
},
|
|
Strong: ansi.StylePrimitive{
|
|
Bold: boolPtr(true),
|
|
},
|
|
HorizontalRule: ansi.StylePrimitive{
|
|
Color: stringPtr("249"),
|
|
Format: "\n--------\n",
|
|
},
|
|
Item: ansi.StylePrimitive{
|
|
BlockPrefix: "• ",
|
|
},
|
|
Enumeration: ansi.StylePrimitive{
|
|
BlockPrefix: ". ",
|
|
},
|
|
Task: ansi.StyleTask{
|
|
StylePrimitive: ansi.StylePrimitive{},
|
|
Ticked: "[✓] ",
|
|
Unticked: "[ ] ",
|
|
},
|
|
Link: ansi.StylePrimitive{
|
|
Color: stringPtr("36"),
|
|
Underline: boolPtr(true),
|
|
},
|
|
LinkText: ansi.StylePrimitive{
|
|
Color: stringPtr("29"),
|
|
Bold: boolPtr(true),
|
|
},
|
|
Image: ansi.StylePrimitive{
|
|
Color: stringPtr("205"),
|
|
Underline: boolPtr(true),
|
|
},
|
|
ImageText: ansi.StylePrimitive{
|
|
Color: stringPtr("243"),
|
|
Format: "Image: {{.text}} →",
|
|
},
|
|
Code: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: " ",
|
|
Suffix: " ",
|
|
Color: stringPtr("203"),
|
|
BackgroundColor: stringPtr("254"),
|
|
},
|
|
},
|
|
CodeBlock: ansi.StyleCodeBlock{
|
|
StyleBlock: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Color: stringPtr("242"),
|
|
},
|
|
Margin: uintPtr(defaultMargin),
|
|
},
|
|
},
|
|
Table: ansi.StyleTable{
|
|
StyleBlock: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{},
|
|
},
|
|
CenterSeparator: stringPtr("┼"),
|
|
ColumnSeparator: stringPtr("│"),
|
|
RowSeparator: stringPtr("─"),
|
|
},
|
|
DefinitionDescription: ansi.StylePrimitive{
|
|
BlockPrefix: "\n🠶 ",
|
|
},
|
|
}
|
|
|
|
// PinkStyleConfig is the default pink style.
|
|
PinkStyleConfig = ansi.StyleConfig{
|
|
Document: ansi.StyleBlock{
|
|
Margin: uintPtr(defaultMargin),
|
|
},
|
|
BlockQuote: ansi.StyleBlock{
|
|
Indent: uintPtr(1),
|
|
IndentToken: stringPtr("│ "),
|
|
},
|
|
List: ansi.StyleList{
|
|
LevelIndent: defaultListIndent,
|
|
},
|
|
Heading: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
BlockSuffix: "\n",
|
|
Color: stringPtr("212"),
|
|
Bold: boolPtr(true),
|
|
},
|
|
},
|
|
H1: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
BlockSuffix: "\n",
|
|
BlockPrefix: "\n",
|
|
Prefix: "",
|
|
},
|
|
},
|
|
H2: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "▌ ",
|
|
},
|
|
},
|
|
H3: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "┃ ",
|
|
},
|
|
},
|
|
H4: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "│ ",
|
|
},
|
|
},
|
|
H5: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "┆ ",
|
|
},
|
|
},
|
|
H6: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Prefix: "┊ ",
|
|
Bold: boolPtr(false),
|
|
},
|
|
},
|
|
Text: ansi.StylePrimitive{},
|
|
Strikethrough: ansi.StylePrimitive{
|
|
CrossedOut: boolPtr(true),
|
|
},
|
|
Emph: ansi.StylePrimitive{
|
|
Italic: boolPtr(true),
|
|
},
|
|
Strong: ansi.StylePrimitive{
|
|
Bold: boolPtr(true),
|
|
},
|
|
HorizontalRule: ansi.StylePrimitive{
|
|
Color: stringPtr("212"),
|
|
Format: "\n──────\n",
|
|
},
|
|
Item: ansi.StylePrimitive{
|
|
BlockPrefix: "• ",
|
|
},
|
|
Enumeration: ansi.StylePrimitive{
|
|
BlockPrefix: ". ",
|
|
},
|
|
Task: ansi.StyleTask{
|
|
Ticked: "[✓] ",
|
|
Unticked: "[ ] ",
|
|
},
|
|
Link: ansi.StylePrimitive{
|
|
Color: stringPtr("99"),
|
|
Underline: boolPtr(true),
|
|
},
|
|
LinkText: ansi.StylePrimitive{
|
|
Bold: boolPtr(true),
|
|
},
|
|
Image: ansi.StylePrimitive{
|
|
Underline: boolPtr(true),
|
|
},
|
|
ImageText: ansi.StylePrimitive{
|
|
Format: "Image: {{.text}}",
|
|
},
|
|
Code: ansi.StyleBlock{
|
|
StylePrimitive: ansi.StylePrimitive{
|
|
Color: stringPtr("212"),
|
|
BackgroundColor: stringPtr("236"),
|
|
Prefix: " ",
|
|
Suffix: " ",
|
|
},
|
|
},
|
|
Table: ansi.StyleTable{
|
|
CenterSeparator: stringPtr("┼"),
|
|
ColumnSeparator: stringPtr("│"),
|
|
RowSeparator: stringPtr("─"),
|
|
},
|
|
DefinitionList: ansi.StyleBlock{},
|
|
DefinitionTerm: ansi.StylePrimitive{},
|
|
DefinitionDescription: ansi.StylePrimitive{
|
|
BlockPrefix: "\n🠶 ",
|
|
},
|
|
HTMLBlock: ansi.StyleBlock{},
|
|
HTMLSpan: ansi.StyleBlock{},
|
|
}
|
|
|
|
// NoTTYStyleConfig is the default notty style.
|
|
NoTTYStyleConfig = ASCIIStyleConfig
|
|
|
|
// DefaultStyles are the default styles.
|
|
DefaultStyles = map[string]*ansi.StyleConfig{
|
|
AsciiStyle: &ASCIIStyleConfig,
|
|
DarkStyle: &DarkStyleConfig,
|
|
DraculaStyle: &DraculaStyleConfig,
|
|
LightStyle: &LightStyleConfig,
|
|
NoTTYStyle: &NoTTYStyleConfig,
|
|
PinkStyle: &PinkStyleConfig,
|
|
}
|
|
)
|
|
|
|
func boolPtr(b bool) *bool { return &b }
|
|
func stringPtr(s string) *string { return &s }
|
|
func uintPtr(u uint) *uint { return &u }
|