Skip to content

Commit

Permalink
Adding HasClasses method for HTML formatter (#61)
Browse files Browse the repository at this point in the history
* Adding HasClasses method for HTML formatter

* Removing helper function and simply export the field
  • Loading branch information
Depado authored and alecthomas committed Oct 13, 2017
1 parent 6604d06 commit 4a55aef
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions formatters/html/html.go
Expand Up @@ -20,7 +20,7 @@ func Standalone() Option { return func(f *Formatter) { f.standalone = true } }
func ClassPrefix(prefix string) Option { return func(f *Formatter) { f.prefix = prefix } }

// WithClasses emits HTML using CSS classes, rather than inline styles.
func WithClasses() Option { return func(f *Formatter) { f.classes = true } }
func WithClasses() Option { return func(f *Formatter) { f.Classes = true } }

// TabWidth sets the number of characters for a tab. Defaults to 8.
func TabWidth(width int) Option { return func(f *Formatter) { f.tabWidth = width } }
Expand Down Expand Up @@ -72,7 +72,7 @@ func New(options ...Option) *Formatter {
type Formatter struct {
standalone bool
prefix string
classes bool
Classes bool // Exported field to detect when classes are being used
tabWidth int
lineNumbers bool
lineNumbersInTable bool
Expand Down Expand Up @@ -131,14 +131,14 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []*chroma
return err
}
css := f.styleToCSS(style)
if !f.classes {
if !f.Classes {
for t, style := range css {
css[t] = compressStyle(style)
}
}
if f.standalone {
fmt.Fprint(w, "<html>\n")
if f.classes {
if f.Classes {
fmt.Fprint(w, "<style type=\"text/css\">\n")
f.WriteCSS(w, style)
fmt.Fprintf(w, "body { %s; }\n", css[chroma.Background])
Expand Down Expand Up @@ -249,7 +249,7 @@ func (f *Formatter) class(t chroma.TokenType) string {
}

func (f *Formatter) styleAttr(styles map[chroma.TokenType]string, tt chroma.TokenType) string {
if f.classes {
if f.Classes {
cls := f.class(tt)
if cls == "" {
return ""
Expand Down

0 comments on commit 4a55aef

Please sign in to comment.