github.com/charmbracelet/glamour@v0.7.0/styles.go (about) 1 package glamour 2 3 //go:generate go run ./internal/generate-style-json 4 5 import ( 6 "github.com/charmbracelet/glamour/ansi" 7 ) 8 9 const defaultListIndent = 2 10 const defaultListLevelIndent = 4 11 const defaultMargin = 2 12 13 var ( 14 // ASCIIStyleConfig uses only ASCII characters. 15 ASCIIStyleConfig = ansi.StyleConfig{ 16 Document: ansi.StyleBlock{ 17 StylePrimitive: ansi.StylePrimitive{ 18 BlockPrefix: "\n", 19 BlockSuffix: "\n", 20 }, 21 Margin: uintPtr(defaultMargin), 22 }, 23 BlockQuote: ansi.StyleBlock{ 24 StylePrimitive: ansi.StylePrimitive{}, 25 Indent: uintPtr(1), 26 IndentToken: stringPtr("| "), 27 }, 28 Paragraph: ansi.StyleBlock{ 29 StylePrimitive: ansi.StylePrimitive{}, 30 }, 31 List: ansi.StyleList{ 32 StyleBlock: ansi.StyleBlock{ 33 StylePrimitive: ansi.StylePrimitive{}, 34 }, 35 LevelIndent: defaultListLevelIndent, 36 }, 37 Heading: ansi.StyleBlock{ 38 StylePrimitive: ansi.StylePrimitive{ 39 BlockSuffix: "\n", 40 }, 41 }, 42 H1: ansi.StyleBlock{ 43 StylePrimitive: ansi.StylePrimitive{ 44 Prefix: "# ", 45 }, 46 }, 47 H2: ansi.StyleBlock{ 48 StylePrimitive: ansi.StylePrimitive{ 49 Prefix: "## ", 50 }, 51 }, 52 H3: ansi.StyleBlock{ 53 StylePrimitive: ansi.StylePrimitive{ 54 Prefix: "### ", 55 }, 56 }, 57 H4: ansi.StyleBlock{ 58 StylePrimitive: ansi.StylePrimitive{ 59 Prefix: "#### ", 60 }, 61 }, 62 H5: ansi.StyleBlock{ 63 StylePrimitive: ansi.StylePrimitive{ 64 Prefix: "##### ", 65 }, 66 }, 67 H6: ansi.StyleBlock{ 68 StylePrimitive: ansi.StylePrimitive{ 69 Prefix: "###### ", 70 }, 71 }, 72 Strikethrough: ansi.StylePrimitive{ 73 BlockPrefix: "~~", 74 BlockSuffix: "~~", 75 }, 76 Emph: ansi.StylePrimitive{ 77 BlockPrefix: "*", 78 BlockSuffix: "*", 79 }, 80 Strong: ansi.StylePrimitive{ 81 BlockPrefix: "**", 82 BlockSuffix: "**", 83 }, 84 HorizontalRule: ansi.StylePrimitive{ 85 Format: "\n--------\n", 86 }, 87 Item: ansi.StylePrimitive{ 88 BlockPrefix: "• ", 89 }, 90 Enumeration: ansi.StylePrimitive{ 91 BlockPrefix: ". ", 92 }, 93 Task: ansi.StyleTask{ 94 Ticked: "[x] ", 95 Unticked: "[ ] ", 96 }, 97 ImageText: ansi.StylePrimitive{ 98 Format: "Image: {{.text}} →", 99 }, 100 Code: ansi.StyleBlock{ 101 StylePrimitive: ansi.StylePrimitive{ 102 BlockPrefix: "`", 103 BlockSuffix: "`", 104 }, 105 }, 106 CodeBlock: ansi.StyleCodeBlock{ 107 StyleBlock: ansi.StyleBlock{ 108 Margin: uintPtr(defaultMargin), 109 }, 110 }, 111 Table: ansi.StyleTable{ 112 CenterSeparator: stringPtr("+"), 113 ColumnSeparator: stringPtr("|"), 114 RowSeparator: stringPtr("-"), 115 }, 116 DefinitionDescription: ansi.StylePrimitive{ 117 BlockPrefix: "\n* ", 118 }, 119 } 120 121 // DarkStyleConfig is the default dark style. 122 DarkStyleConfig = ansi.StyleConfig{ 123 Document: ansi.StyleBlock{ 124 StylePrimitive: ansi.StylePrimitive{ 125 BlockPrefix: "\n", 126 BlockSuffix: "\n", 127 Color: stringPtr("252"), 128 }, 129 Margin: uintPtr(defaultMargin), 130 }, 131 BlockQuote: ansi.StyleBlock{ 132 StylePrimitive: ansi.StylePrimitive{}, 133 Indent: uintPtr(1), 134 IndentToken: stringPtr("│ "), 135 }, 136 List: ansi.StyleList{ 137 LevelIndent: defaultListIndent, 138 }, 139 Heading: ansi.StyleBlock{ 140 StylePrimitive: ansi.StylePrimitive{ 141 BlockSuffix: "\n", 142 Color: stringPtr("39"), 143 Bold: boolPtr(true), 144 }, 145 }, 146 H1: ansi.StyleBlock{ 147 StylePrimitive: ansi.StylePrimitive{ 148 Prefix: " ", 149 Suffix: " ", 150 Color: stringPtr("228"), 151 BackgroundColor: stringPtr("63"), 152 Bold: boolPtr(true), 153 }, 154 }, 155 H2: ansi.StyleBlock{ 156 StylePrimitive: ansi.StylePrimitive{ 157 Prefix: "## ", 158 }, 159 }, 160 H3: ansi.StyleBlock{ 161 StylePrimitive: ansi.StylePrimitive{ 162 Prefix: "### ", 163 }, 164 }, 165 H4: ansi.StyleBlock{ 166 StylePrimitive: ansi.StylePrimitive{ 167 Prefix: "#### ", 168 }, 169 }, 170 H5: ansi.StyleBlock{ 171 StylePrimitive: ansi.StylePrimitive{ 172 Prefix: "##### ", 173 }, 174 }, 175 H6: ansi.StyleBlock{ 176 StylePrimitive: ansi.StylePrimitive{ 177 Prefix: "###### ", 178 Color: stringPtr("35"), 179 Bold: boolPtr(false), 180 }, 181 }, 182 Strikethrough: ansi.StylePrimitive{ 183 CrossedOut: boolPtr(true), 184 }, 185 Emph: ansi.StylePrimitive{ 186 Italic: boolPtr(true), 187 }, 188 Strong: ansi.StylePrimitive{ 189 Bold: boolPtr(true), 190 }, 191 HorizontalRule: ansi.StylePrimitive{ 192 Color: stringPtr("240"), 193 Format: "\n--------\n", 194 }, 195 Item: ansi.StylePrimitive{ 196 BlockPrefix: "• ", 197 }, 198 Enumeration: ansi.StylePrimitive{ 199 BlockPrefix: ". ", 200 }, 201 Task: ansi.StyleTask{ 202 StylePrimitive: ansi.StylePrimitive{}, 203 Ticked: "[✓] ", 204 Unticked: "[ ] ", 205 }, 206 Link: ansi.StylePrimitive{ 207 Color: stringPtr("30"), 208 Underline: boolPtr(true), 209 }, 210 LinkText: ansi.StylePrimitive{ 211 Color: stringPtr("35"), 212 Bold: boolPtr(true), 213 }, 214 Image: ansi.StylePrimitive{ 215 Color: stringPtr("212"), 216 Underline: boolPtr(true), 217 }, 218 ImageText: ansi.StylePrimitive{ 219 Color: stringPtr("243"), 220 Format: "Image: {{.text}} →", 221 }, 222 Code: ansi.StyleBlock{ 223 StylePrimitive: ansi.StylePrimitive{ 224 Prefix: " ", 225 Suffix: " ", 226 Color: stringPtr("203"), 227 BackgroundColor: stringPtr("236"), 228 }, 229 }, 230 CodeBlock: ansi.StyleCodeBlock{ 231 StyleBlock: ansi.StyleBlock{ 232 StylePrimitive: ansi.StylePrimitive{ 233 Color: stringPtr("244"), 234 }, 235 Margin: uintPtr(defaultMargin), 236 }, 237 Chroma: &ansi.Chroma{ 238 Text: ansi.StylePrimitive{ 239 Color: stringPtr("#C4C4C4"), 240 }, 241 Error: ansi.StylePrimitive{ 242 Color: stringPtr("#F1F1F1"), 243 BackgroundColor: stringPtr("#F05B5B"), 244 }, 245 Comment: ansi.StylePrimitive{ 246 Color: stringPtr("#676767"), 247 }, 248 CommentPreproc: ansi.StylePrimitive{ 249 Color: stringPtr("#FF875F"), 250 }, 251 Keyword: ansi.StylePrimitive{ 252 Color: stringPtr("#00AAFF"), 253 }, 254 KeywordReserved: ansi.StylePrimitive{ 255 Color: stringPtr("#FF5FD2"), 256 }, 257 KeywordNamespace: ansi.StylePrimitive{ 258 Color: stringPtr("#FF5F87"), 259 }, 260 KeywordType: ansi.StylePrimitive{ 261 Color: stringPtr("#6E6ED8"), 262 }, 263 Operator: ansi.StylePrimitive{ 264 Color: stringPtr("#EF8080"), 265 }, 266 Punctuation: ansi.StylePrimitive{ 267 Color: stringPtr("#E8E8A8"), 268 }, 269 Name: ansi.StylePrimitive{ 270 Color: stringPtr("#C4C4C4"), 271 }, 272 NameBuiltin: ansi.StylePrimitive{ 273 Color: stringPtr("#FF8EC7"), 274 }, 275 NameTag: ansi.StylePrimitive{ 276 Color: stringPtr("#B083EA"), 277 }, 278 NameAttribute: ansi.StylePrimitive{ 279 Color: stringPtr("#7A7AE6"), 280 }, 281 NameClass: ansi.StylePrimitive{ 282 Color: stringPtr("#F1F1F1"), 283 Underline: boolPtr(true), 284 Bold: boolPtr(true), 285 }, 286 NameDecorator: ansi.StylePrimitive{ 287 Color: stringPtr("#FFFF87"), 288 }, 289 NameFunction: ansi.StylePrimitive{ 290 Color: stringPtr("#00D787"), 291 }, 292 LiteralNumber: ansi.StylePrimitive{ 293 Color: stringPtr("#6EEFC0"), 294 }, 295 LiteralString: ansi.StylePrimitive{ 296 Color: stringPtr("#C69669"), 297 }, 298 LiteralStringEscape: ansi.StylePrimitive{ 299 Color: stringPtr("#AFFFD7"), 300 }, 301 GenericDeleted: ansi.StylePrimitive{ 302 Color: stringPtr("#FD5B5B"), 303 }, 304 GenericEmph: ansi.StylePrimitive{ 305 Italic: boolPtr(true), 306 }, 307 GenericInserted: ansi.StylePrimitive{ 308 Color: stringPtr("#00D787"), 309 }, 310 GenericStrong: ansi.StylePrimitive{ 311 Bold: boolPtr(true), 312 }, 313 GenericSubheading: ansi.StylePrimitive{ 314 Color: stringPtr("#777777"), 315 }, 316 Background: ansi.StylePrimitive{ 317 BackgroundColor: stringPtr("#373737"), 318 }, 319 }, 320 }, 321 Table: ansi.StyleTable{ 322 StyleBlock: ansi.StyleBlock{ 323 StylePrimitive: ansi.StylePrimitive{}, 324 }, 325 CenterSeparator: stringPtr("┼"), 326 ColumnSeparator: stringPtr("│"), 327 RowSeparator: stringPtr("─"), 328 }, 329 DefinitionDescription: ansi.StylePrimitive{ 330 BlockPrefix: "\n🠶 ", 331 }, 332 } 333 334 // LightStyleConfig is the default light style. 335 LightStyleConfig = ansi.StyleConfig{ 336 Document: ansi.StyleBlock{ 337 StylePrimitive: ansi.StylePrimitive{ 338 BlockPrefix: "\n", 339 BlockSuffix: "\n", 340 Color: stringPtr("234"), 341 }, 342 Margin: uintPtr(defaultMargin), 343 }, 344 BlockQuote: ansi.StyleBlock{ 345 StylePrimitive: ansi.StylePrimitive{}, 346 Indent: uintPtr(1), 347 IndentToken: stringPtr("│ "), 348 }, 349 List: ansi.StyleList{ 350 LevelIndent: defaultListIndent, 351 }, 352 Heading: ansi.StyleBlock{ 353 StylePrimitive: ansi.StylePrimitive{ 354 BlockSuffix: "\n", 355 Color: stringPtr("27"), 356 Bold: boolPtr(true), 357 }, 358 }, 359 H1: ansi.StyleBlock{ 360 StylePrimitive: ansi.StylePrimitive{ 361 Prefix: " ", 362 Suffix: " ", 363 Color: stringPtr("228"), 364 BackgroundColor: stringPtr("63"), 365 Bold: boolPtr(true), 366 }, 367 }, 368 H2: ansi.StyleBlock{ 369 StylePrimitive: ansi.StylePrimitive{ 370 Prefix: "## ", 371 }, 372 }, 373 H3: ansi.StyleBlock{ 374 StylePrimitive: ansi.StylePrimitive{ 375 Prefix: "### ", 376 }, 377 }, 378 H4: ansi.StyleBlock{ 379 StylePrimitive: ansi.StylePrimitive{ 380 Prefix: "#### ", 381 }, 382 }, 383 H5: ansi.StyleBlock{ 384 StylePrimitive: ansi.StylePrimitive{ 385 Prefix: "##### ", 386 }, 387 }, 388 H6: ansi.StyleBlock{ 389 StylePrimitive: ansi.StylePrimitive{ 390 Prefix: "###### ", 391 Bold: boolPtr(false), 392 }, 393 }, 394 Strikethrough: ansi.StylePrimitive{ 395 CrossedOut: boolPtr(true), 396 }, 397 Emph: ansi.StylePrimitive{ 398 Italic: boolPtr(true), 399 }, 400 Strong: ansi.StylePrimitive{ 401 Bold: boolPtr(true), 402 }, 403 HorizontalRule: ansi.StylePrimitive{ 404 Color: stringPtr("249"), 405 Format: "\n--------\n", 406 }, 407 Item: ansi.StylePrimitive{ 408 BlockPrefix: "• ", 409 }, 410 Enumeration: ansi.StylePrimitive{ 411 BlockPrefix: ". ", 412 }, 413 Task: ansi.StyleTask{ 414 StylePrimitive: ansi.StylePrimitive{}, 415 Ticked: "[✓] ", 416 Unticked: "[ ] ", 417 }, 418 Link: ansi.StylePrimitive{ 419 Color: stringPtr("36"), 420 Underline: boolPtr(true), 421 }, 422 LinkText: ansi.StylePrimitive{ 423 Color: stringPtr("29"), 424 Bold: boolPtr(true), 425 }, 426 Image: ansi.StylePrimitive{ 427 Color: stringPtr("205"), 428 Underline: boolPtr(true), 429 }, 430 ImageText: ansi.StylePrimitive{ 431 Color: stringPtr("243"), 432 Format: "Image: {{.text}} →", 433 }, 434 Code: ansi.StyleBlock{ 435 StylePrimitive: ansi.StylePrimitive{ 436 Prefix: " ", 437 Suffix: " ", 438 Color: stringPtr("203"), 439 BackgroundColor: stringPtr("254"), 440 }, 441 }, 442 CodeBlock: ansi.StyleCodeBlock{ 443 StyleBlock: ansi.StyleBlock{ 444 StylePrimitive: ansi.StylePrimitive{ 445 Color: stringPtr("242"), 446 }, 447 Margin: uintPtr(defaultMargin), 448 }, 449 Chroma: &ansi.Chroma{ 450 Text: ansi.StylePrimitive{ 451 Color: stringPtr("#2A2A2A"), 452 }, 453 Error: ansi.StylePrimitive{ 454 Color: stringPtr("#F1F1F1"), 455 BackgroundColor: stringPtr("#FF5555"), 456 }, 457 Comment: ansi.StylePrimitive{ 458 Color: stringPtr("#8D8D8D"), 459 }, 460 CommentPreproc: ansi.StylePrimitive{ 461 Color: stringPtr("#FF875F"), 462 }, 463 Keyword: ansi.StylePrimitive{ 464 Color: stringPtr("#279EFC"), 465 }, 466 KeywordReserved: ansi.StylePrimitive{ 467 Color: stringPtr("#FF5FD2"), 468 }, 469 KeywordNamespace: ansi.StylePrimitive{ 470 Color: stringPtr("#FB406F"), 471 }, 472 KeywordType: ansi.StylePrimitive{ 473 Color: stringPtr("#7049C2"), 474 }, 475 Operator: ansi.StylePrimitive{ 476 Color: stringPtr("#FF2626"), 477 }, 478 Punctuation: ansi.StylePrimitive{ 479 Color: stringPtr("#FA7878"), 480 }, 481 NameBuiltin: ansi.StylePrimitive{ 482 Color: stringPtr("#0A1BB1"), 483 }, 484 NameTag: ansi.StylePrimitive{ 485 Color: stringPtr("#581290"), 486 }, 487 NameAttribute: ansi.StylePrimitive{ 488 Color: stringPtr("#8362CB"), 489 }, 490 NameClass: ansi.StylePrimitive{ 491 Color: stringPtr("#212121"), 492 Underline: boolPtr(true), 493 Bold: boolPtr(true), 494 }, 495 NameConstant: ansi.StylePrimitive{ 496 Color: stringPtr("#581290"), 497 }, 498 NameDecorator: ansi.StylePrimitive{ 499 Color: stringPtr("#A3A322"), 500 }, 501 NameFunction: ansi.StylePrimitive{ 502 Color: stringPtr("#019F57"), 503 }, 504 LiteralNumber: ansi.StylePrimitive{ 505 Color: stringPtr("#22CCAE"), 506 }, 507 LiteralString: ansi.StylePrimitive{ 508 Color: stringPtr("#7E5B38"), 509 }, 510 LiteralStringEscape: ansi.StylePrimitive{ 511 Color: stringPtr("#00AEAE"), 512 }, 513 GenericDeleted: ansi.StylePrimitive{ 514 Color: stringPtr("#FD5B5B"), 515 }, 516 GenericEmph: ansi.StylePrimitive{ 517 Italic: boolPtr(true), 518 }, 519 GenericInserted: ansi.StylePrimitive{ 520 Color: stringPtr("#00D787"), 521 }, 522 GenericStrong: ansi.StylePrimitive{ 523 Bold: boolPtr(true), 524 }, 525 GenericSubheading: ansi.StylePrimitive{ 526 Color: stringPtr("#777777"), 527 }, 528 Background: ansi.StylePrimitive{ 529 BackgroundColor: stringPtr("#373737"), 530 }, 531 }, 532 }, 533 Table: ansi.StyleTable{ 534 StyleBlock: ansi.StyleBlock{ 535 StylePrimitive: ansi.StylePrimitive{}, 536 }, 537 CenterSeparator: stringPtr("┼"), 538 ColumnSeparator: stringPtr("│"), 539 RowSeparator: stringPtr("─"), 540 }, 541 DefinitionDescription: ansi.StylePrimitive{ 542 BlockPrefix: "\n🠶 ", 543 }, 544 } 545 546 // PinkStyleConfig is the default pink style. 547 PinkStyleConfig = ansi.StyleConfig{ 548 Document: ansi.StyleBlock{ 549 Margin: uintPtr(defaultMargin), 550 }, 551 BlockQuote: ansi.StyleBlock{ 552 Indent: uintPtr(1), 553 IndentToken: stringPtr("│ "), 554 }, 555 List: ansi.StyleList{ 556 LevelIndent: defaultListIndent, 557 }, 558 Heading: ansi.StyleBlock{ 559 StylePrimitive: ansi.StylePrimitive{ 560 BlockSuffix: "\n", 561 Color: stringPtr("212"), 562 Bold: boolPtr(true), 563 }, 564 }, 565 H1: ansi.StyleBlock{ 566 StylePrimitive: ansi.StylePrimitive{ 567 BlockSuffix: "\n", 568 BlockPrefix: "\n", 569 Prefix: "", 570 }, 571 }, 572 H2: ansi.StyleBlock{ 573 StylePrimitive: ansi.StylePrimitive{ 574 Prefix: "▌ ", 575 }, 576 }, 577 H3: ansi.StyleBlock{ 578 StylePrimitive: ansi.StylePrimitive{ 579 Prefix: "┃ ", 580 }, 581 }, 582 H4: ansi.StyleBlock{ 583 StylePrimitive: ansi.StylePrimitive{ 584 Prefix: "│ ", 585 }, 586 }, 587 H5: ansi.StyleBlock{ 588 StylePrimitive: ansi.StylePrimitive{ 589 Prefix: "┆ ", 590 }, 591 }, 592 H6: ansi.StyleBlock{ 593 StylePrimitive: ansi.StylePrimitive{ 594 Prefix: "┊ ", 595 Bold: boolPtr(false), 596 }, 597 }, 598 Text: ansi.StylePrimitive{}, 599 Strikethrough: ansi.StylePrimitive{ 600 CrossedOut: boolPtr(true), 601 }, 602 Emph: ansi.StylePrimitive{ 603 Italic: boolPtr(true), 604 }, 605 Strong: ansi.StylePrimitive{ 606 Bold: boolPtr(true), 607 }, 608 HorizontalRule: ansi.StylePrimitive{ 609 Color: stringPtr("212"), 610 Format: "\n──────\n", 611 }, 612 Item: ansi.StylePrimitive{ 613 BlockPrefix: "• ", 614 }, 615 Enumeration: ansi.StylePrimitive{ 616 BlockPrefix: ". ", 617 }, 618 Task: ansi.StyleTask{ 619 Ticked: "[✓] ", 620 Unticked: "[ ] ", 621 }, 622 Link: ansi.StylePrimitive{ 623 Color: stringPtr("99"), 624 Underline: boolPtr(true), 625 }, 626 LinkText: ansi.StylePrimitive{ 627 Bold: boolPtr(true), 628 }, 629 Image: ansi.StylePrimitive{ 630 Underline: boolPtr(true), 631 }, 632 ImageText: ansi.StylePrimitive{ 633 Format: "Image: {{.text}}", 634 }, 635 Code: ansi.StyleBlock{ 636 StylePrimitive: ansi.StylePrimitive{ 637 Color: stringPtr("212"), 638 BackgroundColor: stringPtr("236"), 639 Prefix: " ", 640 Suffix: " ", 641 }, 642 }, 643 Table: ansi.StyleTable{ 644 CenterSeparator: stringPtr("┼"), 645 ColumnSeparator: stringPtr("│"), 646 RowSeparator: stringPtr("─"), 647 }, 648 DefinitionList: ansi.StyleBlock{}, 649 DefinitionTerm: ansi.StylePrimitive{}, 650 DefinitionDescription: ansi.StylePrimitive{ 651 BlockPrefix: "\n🠶 ", 652 }, 653 HTMLBlock: ansi.StyleBlock{}, 654 HTMLSpan: ansi.StyleBlock{}, 655 } 656 657 // NoTTYStyleConfig is the default notty style. 658 NoTTYStyleConfig = ASCIIStyleConfig 659 660 // DefaultStyles are the default styles. 661 DefaultStyles = map[string]*ansi.StyleConfig{ 662 AsciiStyle: &ASCIIStyleConfig, 663 DarkStyle: &DarkStyleConfig, 664 DraculaStyle: &DraculaStyleConfig, 665 LightStyle: &LightStyleConfig, 666 NoTTYStyle: &NoTTYStyleConfig, 667 PinkStyle: &PinkStyleConfig, 668 } 669 ) 670 671 func boolPtr(b bool) *bool { return &b } 672 func stringPtr(s string) *string { return &s } 673 func uintPtr(u uint) *uint { return &u }