Colorize applies syntax-highlighting to a cheatsheet's Text.
(conf config.Config)
| 10 | |
| 11 | // Colorize applies syntax-highlighting to a cheatsheet's Text. |
| 12 | func (s *Sheet) Colorize(conf config.Config) { |
| 13 | |
| 14 | // if the syntax was not specified, default to bash |
| 15 | lex := s.Syntax |
| 16 | if lex == "" { |
| 17 | lex = "bash" |
| 18 | } |
| 19 | |
| 20 | // write colorized text into a buffer |
| 21 | var buf bytes.Buffer |
| 22 | err := quick.Highlight( |
| 23 | &buf, |
| 24 | s.Text, |
| 25 | lex, |
| 26 | conf.Formatter, |
| 27 | conf.Style, |
| 28 | ) |
| 29 | |
| 30 | // if colorization somehow failed, do nothing |
| 31 | if err != nil { |
| 32 | return |
| 33 | } |
| 34 | |
| 35 | // otherwise, swap the cheatsheet's Text with its colorized equivalent |
| 36 | s.Text = buf.String() |
| 37 | } |
no outgoing calls