From bdbe6ae0c528ad7af8b85bef2949aefb7ce03654 Mon Sep 17 00:00:00 2001 From: Tom Payne Date: Sat, 4 Jan 2020 16:19:56 +0100 Subject: [PATCH] Generate example styles from default styles --- internal/generate-style-json/main.go | 38 +++++++++ styles/README.md | 5 ++ styles/dark.json | 120 ++++++++++++++------------- styles/light.json | 120 ++++++++++++++------------- styles/notty.json | 75 ++++++++--------- styles/simple.json | 50 +++++------ 6 files changed, 233 insertions(+), 175 deletions(-) create mode 100644 internal/generate-style-json/main.go diff --git a/internal/generate-style-json/main.go b/internal/generate-style-json/main.go new file mode 100644 index 0000000..31dd0dc --- /dev/null +++ b/internal/generate-style-json/main.go @@ -0,0 +1,38 @@ +package main + +import ( + "encoding/json" + "fmt" + "os" + "path/filepath" + + "github.com/charmbracelet/glamour" + "github.com/charmbracelet/glamour/ansi" +) + +func writeStyleJSON(filename string, styleConfig *ansi.StyleConfig) error { + f, err := os.Create(filename) + if err != nil { + return err + } + defer f.Close() + e := json.NewEncoder(f) + e.SetIndent("", " ") + return e.Encode(styleConfig) +} + +func run() error { + for style, styleConfig := range glamour.DefaultStyles { + if err := writeStyleJSON(filepath.Join("styles", style+".json"), styleConfig); err != nil { + return err + } + } + return nil +} + +func main() { + if err := run(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} diff --git a/styles/README.md b/styles/README.md index 89c11a2..ede5d99 100644 --- a/styles/README.md +++ b/styles/README.md @@ -1,5 +1,10 @@ # Glamour Style Guide +The JSON files in this directory are generated from the default styles. To +re-generate them, run: + + go run ./internal/generate-style-json + ## Block Elements Block elements contain other elements and are rendered around them. All block diff --git a/styles/dark.json b/styles/dark.json index f0596c7..44fb41c 100644 --- a/styles/dark.json +++ b/styles/dark.json @@ -1,9 +1,17 @@ { "document": { - "indent": 2, "block_prefix": "\n", "block_suffix": "\n", - "color": "252" + "color": "252", + "indent": 2 + }, + "block_quote": { + "indent": 1, + "indent_token": "│ " + }, + "paragraph": {}, + "list": { + "level_indent": 2 }, "heading": { "block_suffix": "\n", @@ -13,8 +21,8 @@ "h1": { "prefix": " ", "suffix": " ", - "background_color": "63", "color": "228", + "background_color": "63", "bold": true }, "h2": { @@ -35,40 +43,6 @@ "bold": false }, "text": {}, - "list": { - "level_indent": 2 - }, - "item": { - "block_prefix": "• " - }, - "enumeration": { - "block_prefix": ". " - }, - "link_text": { - "color": "35", - "bold": true - }, - "link": { - "underline": true, - "color": "30" - }, - "image_text": { - "format": "Image: {{.text}} →", - "color": "243" - }, - "image": { - "underline": true, - "color": "212" - }, - "table": { - "center_separator": "┼", - "column_separator": "│", - "row_separator": "─" - }, - "task": { - "unticked": "[ ] ", - "ticked": "[✓] " - }, "strikethrough": { "crossed_out": true }, @@ -79,29 +53,44 @@ "bold": true }, "hr": { - "format": "\n--------\n", - "color": "240" + "color": "240", + "format": "\n--------\n" }, - "block_quote": { - "indent": 1, - "indent_token": "│ " + "item": { + "block_prefix": "• " }, - "definition_list": {}, - "definition_term": {}, - "definition_description": { - "block_prefix": "\n🠶 " + "enumeration": { + "block_prefix": ". " + }, + "task": { + "ticked": "[✓] ", + "unticked": "[ ] " + }, + "link": { + "color": "30", + "underline": true + }, + "link_text": { + "color": "35", + "bold": true + }, + "image": { + "color": "212", + "underline": true + }, + "image_text": { + "color": "243", + "format": "Image: {{.text}} →" }, - "html_block": {}, - "html_span": {}, "code": { "prefix": " ", "suffix": " ", - "background_color": "236", - "color": "203" + "color": "203", + "background_color": "236" }, "code_block": { - "margin": 2, "color": "244", + "margin": 2, "chroma": { "text": { "color": "#C4C4C4" @@ -148,18 +137,23 @@ }, "name_class": { "color": "#F1F1F1", - "bold": true, - "underline": true + "underline": true, + "bold": true }, + "name_constant": {}, "name_decorator": { "color": "#FFFF87" }, + "name_exception": {}, "name_function": { "color": "#00D787" }, + "name_other": {}, + "literal": {}, "literal_number": { "color": "#6EEFC0" }, + "literal_date": {}, "literal_string": { "color": "#C69669" }, @@ -172,12 +166,12 @@ "generic_emph": { "italic": true }, - "generic_strong": { - "bold": true - }, "generic_inserted": { "color": "#00D787" }, + "generic_strong": { + "bold": true + }, "generic_subheading": { "color": "#777777" }, @@ -185,5 +179,17 @@ "background_color": "#373737" } } - } + }, + "table": { + "center_separator": "┼", + "column_separator": "│", + "row_separator": "─" + }, + "definition_list": {}, + "definition_term": {}, + "definition_description": { + "block_prefix": "\n🠶 " + }, + "html_block": {}, + "html_span": {} } diff --git a/styles/light.json b/styles/light.json index fc89965..8845006 100644 --- a/styles/light.json +++ b/styles/light.json @@ -1,9 +1,17 @@ { "document": { - "indent": 2, "block_prefix": "\n", "block_suffix": "\n", - "color": "234" + "color": "234", + "indent": 2 + }, + "block_quote": { + "indent": 1, + "indent_token": "│ " + }, + "paragraph": {}, + "list": { + "level_indent": 2 }, "heading": { "block_suffix": "\n", @@ -13,8 +21,8 @@ "h1": { "prefix": " ", "suffix": " ", - "background_color": "63", "color": "228", + "background_color": "63", "bold": true }, "h2": { @@ -34,40 +42,6 @@ "bold": false }, "text": {}, - "list": { - "level_indent": 2 - }, - "item": { - "block_prefix": "• " - }, - "enumeration": { - "block_prefix": ". " - }, - "link_text": { - "color": "29", - "bold": true - }, - "link": { - "underline": true, - "color": "36" - }, - "image_text": { - "format": "Image: {{.text}} →", - "color": "243" - }, - "image": { - "underline": true, - "color": "205" - }, - "table": { - "center_separator": "┼", - "column_separator": "│", - "row_separator": "─" - }, - "task": { - "unticked": "[ ] ", - "ticked": "[✓] " - }, "strikethrough": { "crossed_out": true }, @@ -78,29 +52,44 @@ "bold": true }, "hr": { - "format": "\n--------\n", - "color": "249" + "color": "249", + "format": "\n--------\n" }, - "block_quote": { - "indent": 1, - "indent_token": "│ " + "item": { + "block_prefix": "• " }, - "definition_list": {}, - "definition_term": {}, - "definition_description": { - "block_prefix": "\n🠶 " + "enumeration": { + "block_prefix": ". " + }, + "task": { + "ticked": "[✓] ", + "unticked": "[ ] " + }, + "link": { + "color": "36", + "underline": true + }, + "link_text": { + "color": "29", + "bold": true + }, + "image": { + "color": "205", + "underline": true + }, + "image_text": { + "color": "243", + "format": "Image: {{.text}} →" }, - "html_block": {}, - "html_span": {}, "code": { "prefix": " ", "suffix": " ", - "background_color": "254", - "color": "203" + "color": "203", + "background_color": "254" }, "code_block": { - "margin": 2, "color": "242", + "margin": 2, "chroma": { "text": { "color": "#2A2A2A" @@ -133,6 +122,7 @@ "punctuation": { "color": "#FA7878" }, + "name": {}, "name_builtin": { "color": "#0A1BB1" }, @@ -144,8 +134,8 @@ }, "name_class": { "color": "#212121", - "bold": true, - "underline": true + "underline": true, + "bold": true }, "name_constant": { "color": "#581290" @@ -153,12 +143,16 @@ "name_decorator": { "color": "#A3A322" }, + "name_exception": {}, "name_function": { "color": "#019F57" }, + "name_other": {}, + "literal": {}, "literal_number": { "color": "#22CCAE" }, + "literal_date": {}, "literal_string": { "color": "#7E5B38" }, @@ -171,12 +165,12 @@ "generic_emph": { "italic": true }, - "generic_strong": { - "bold": true - }, "generic_inserted": { "color": "#00D787" }, + "generic_strong": { + "bold": true + }, "generic_subheading": { "color": "#777777" }, @@ -184,5 +178,17 @@ "background_color": "#373737" } } - } + }, + "table": { + "center_separator": "┼", + "column_separator": "│", + "row_separator": "─" + }, + "definition_list": {}, + "definition_term": {}, + "definition_description": { + "block_prefix": "\n🠶 " + }, + "html_block": {}, + "html_span": {} } diff --git a/styles/notty.json b/styles/notty.json index b4529d9..8438de1 100644 --- a/styles/notty.json +++ b/styles/notty.json @@ -1,8 +1,16 @@ { "document": { - "indent": 2, "block_prefix": "\n", - "block_suffix": "\n" + "block_suffix": "\n", + "indent": 2 + }, + "block_quote": { + "indent": 1, + "indent_token": "│ " + }, + "paragraph": {}, + "list": { + "level_indent": 4 }, "heading": { "block_suffix": "\n" @@ -26,30 +34,6 @@ "prefix": "###### " }, "text": {}, - "list": { - "level_indent": 4 - }, - "item": { - "block_prefix": "• " - }, - "enumeration": { - "block_prefix": ". " - }, - "link_text": {}, - "link": {}, - "image_text": { - "format": "Image: {{.text}} →" - }, - "image": {}, - "table": { - "center_separator": "┼", - "column_separator": "│", - "row_separator": "─" - }, - "task": { - "unticked": "[ ] ", - "ticked": "[✓] " - }, "strikethrough": { "block_prefix": "~~", "block_suffix": "~~" @@ -65,9 +49,33 @@ "hr": { "format": "\n--------\n" }, - "block_quote": { - "indent": 1, - "indent_token": "│ " + "item": { + "block_prefix": "• " + }, + "enumeration": { + "block_prefix": ". " + }, + "task": { + "ticked": "[✓] ", + "unticked": "[ ] " + }, + "link": {}, + "link_text": {}, + "image": {}, + "image_text": { + "format": "Image: {{.text}} →" + }, + "code": { + "block_prefix": "`", + "block_suffix": "`" + }, + "code_block": { + "margin": 2 + }, + "table": { + "center_separator": "┼", + "column_separator": "│", + "row_separator": "─" }, "definition_list": {}, "definition_term": {}, @@ -75,12 +83,5 @@ "block_prefix": "\n🠶 " }, "html_block": {}, - "html_span": {}, - "code": { - "block_prefix": "`", - "block_suffix": "`" - }, - "code_block": { - "margin": 2 - } + "html_span": {} } diff --git a/styles/simple.json b/styles/simple.json index 6db564d..ea10fc6 100644 --- a/styles/simple.json +++ b/styles/simple.json @@ -1,5 +1,13 @@ { "document": {}, + "block_quote": { + "indent": 1, + "indent_token": "\u003e " + }, + "paragraph": {}, + "list": { + "level_indent": 4 + }, "heading": { "block_suffix": "\n" }, @@ -23,27 +31,6 @@ "prefix": "###### " }, "text": {}, - "list": { - "level_indent": 4 - }, - "item": { - "block_prefix": "- " - }, - "enumeration": { - "block_prefix": ". " - }, - "link_text": {}, - "link": {}, - "image_text": { - "format": "Image: {{.text}} => " - }, - "image": {}, - "code": { - "block_prefix": "`", - "block_suffix": "`" - }, - "code_block": {}, - "table": {}, "strikethrough": { "block_prefix": "~~", "block_suffix": "~~" @@ -59,10 +46,25 @@ "hr": { "format": "\n--------\n" }, - "block_quote": { - "indent": 1, - "indent_token": "> " + "item": { + "block_prefix": "- " }, + "enumeration": { + "block_prefix": ". " + }, + "task": {}, + "link": {}, + "link_text": {}, + "image": {}, + "image_text": { + "format": "Image: {{.text}} =\u003e " + }, + "code": { + "block_prefix": "`", + "block_suffix": "`" + }, + "code_block": {}, + "table": {}, "definition_list": {}, "definition_term": {}, "definition_description": {