mirror of
https://github.com/alecthomas/chroma.git
synced 2025-03-17 20:58:08 +02:00
Adding HasClasses method for HTML formatter (#61)
* Adding HasClasses method for HTML formatter * Removing helper function and simply export the field
This commit is contained in:
parent
6604d06684
commit
4a55aefee6
@ -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 } }
|
||||
@ -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
|
||||
@ -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])
|
||||
@ -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 ""
|
||||
|
Loading…
x
Reference in New Issue
Block a user