diff --git a/go.sum b/go.sum index 4728970..b343391 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,6 @@ github.com/GeertJohan/go.rice v1.0.0/go.mod h1:eH6gbSOAUv07dQuZVnBmoDP8mgsM1rtix github.com/akavel/rsrc v0.8.0/go.mod h1:uLoCtb9J+EyAqh+26kdrTgmzRBFPGOolLWKpdxkKq+c= github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38 h1:smF2tmSOzy2Mm+0dGI2AIUHY+w0BUc+4tn40djz7+6U= github.com/alecthomas/assert v0.0.0-20170929043011-405dbfeb8e38/go.mod h1:r7bzyVFMNntcxPZXK3/+KdruV1H5KSlyVY0gc+NgInI= -github.com/alecthomas/chroma v0.6.9 h1:afiCdwnNPo6fcyvoqqsXs78t7NbR9TuW4wDB7NJkcag= -github.com/alecthomas/chroma v0.6.9/go.mod h1:1U/PfCsTALWWYHDnsIQkxEBM0+6LLe0v8+RSVMOwxeY= github.com/alecthomas/chroma v0.7.0 h1:z+0HgTUmkpRDRz0SRSdMaqOLfJV4F+N1FPDZUZIDUzw= github.com/alecthomas/chroma v0.7.0/go.mod h1:1U/PfCsTALWWYHDnsIQkxEBM0+6LLe0v8+RSVMOwxeY= github.com/alecthomas/colour v0.0.0-20160524082231-60882d9e2721 h1:JHZL0hZKJ1VENNfmXvHbgYlbUOvpzYzvy2aZU5gXVeo= diff --git a/vendor/github.com/alecthomas/chroma/formatters/api.go b/vendor/github.com/alecthomas/chroma/formatters/api.go index 276bead..6da0a24 100644 --- a/vendor/github.com/alecthomas/chroma/formatters/api.go +++ b/vendor/github.com/alecthomas/chroma/formatters/api.go @@ -20,7 +20,7 @@ var ( return nil })) // Default HTML formatter outputs self-contained HTML. - htmlFull = Register("html", html.New(html.Standalone(), html.WithClasses())) // nolint + htmlFull = Register("html", html.New(html.Standalone(true), html.WithClasses(true))) // nolint SVG = Register("svg", svg.New(svg.EmbedFont("Liberation Mono", svg.FontLiberationMono, svg.WOFF))) ) diff --git a/vendor/github.com/alecthomas/chroma/formatters/html/html.go b/vendor/github.com/alecthomas/chroma/formatters/html/html.go index 3f68a7d..4a307b2 100644 --- a/vendor/github.com/alecthomas/chroma/formatters/html/html.go +++ b/vendor/github.com/alecthomas/chroma/formatters/html/html.go @@ -14,32 +14,47 @@ import ( type Option func(f *Formatter) // Standalone configures the HTML formatter for generating a standalone HTML document. -func Standalone() Option { return func(f *Formatter) { f.standalone = true } } +func Standalone(b bool) Option { return func(f *Formatter) { f.standalone = b } } // ClassPrefix sets the CSS class prefix. 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(b bool) Option { return func(f *Formatter) { f.Classes = b } } // TabWidth sets the number of characters for a tab. Defaults to 8. func TabWidth(width int) Option { return func(f *Formatter) { f.tabWidth = width } } -// PreventSurroundingPre prevents the surrounding pre tags around the generated code -func PreventSurroundingPre() Option { return func(f *Formatter) { f.preventSurroundingPre = true } } +// PreventSurroundingPre prevents the surrounding pre tags around the generated code. +func PreventSurroundingPre(b bool) Option { + return func(f *Formatter) { + if b { + f.preWrapper = nopPreWrapper + } else { + f.preWrapper = defaultPreWrapper + } + } +} + +// WithPreWrapper allows control of the surrounding pre tags. +func WithPreWrapper(wrapper PreWrapper) Option { + return func(f *Formatter) { + f.preWrapper = wrapper + } +} // WithLineNumbers formats output with line numbers. -func WithLineNumbers() Option { +func WithLineNumbers(b bool) Option { return func(f *Formatter) { - f.lineNumbers = true + f.lineNumbers = b } } // LineNumbersInTable will, when combined with WithLineNumbers, separate the line numbers // and code in table td's, which make them copy-and-paste friendly. -func LineNumbersInTable() Option { +func LineNumbersInTable(b bool) Option { return func(f *Formatter) { - f.lineNumbersInTable = true + f.lineNumbersInTable = b } } @@ -64,6 +79,7 @@ func BaseLineNumber(n int) Option { func New(options ...Option) *Formatter { f := &Formatter{ baseLineNumber: 1, + preWrapper: defaultPreWrapper, } for _, option := range options { option(f) @@ -71,17 +87,57 @@ func New(options ...Option) *Formatter { return f } +// PreWrapper defines the operations supported in WithPreWrapper. +type PreWrapper interface { + // Start is called to write a start
 element.
+	// The code flag tells whether this block surrounds
+	// highlighted code. This will be false when surrounding
+	// line numbers.
+	Start(code bool, styleAttr string) string
+
+	// End is called to write the end 
element. + End(code bool) string +} + +type preWrapper struct { + start func(code bool, styleAttr string) string + end func(code bool) string +} + +func (p preWrapper) Start(code bool, styleAttr string) string { + return p.start(code, styleAttr) +} + +func (p preWrapper) End(code bool) string { + return p.end(code) +} + +var ( + nopPreWrapper = preWrapper{ + start: func(code bool, styleAttr string) string { return "" }, + end: func(code bool) string { return "" }, + } + defaultPreWrapper = preWrapper{ + start: func(code bool, styleAttr string) string { + return fmt.Sprintf("", styleAttr) + }, + end: func(code bool) string { + return "" + }, + } +) + // Formatter that generates HTML. type Formatter struct { - standalone bool - prefix string - Classes bool // Exported field to detect when classes are being used - preventSurroundingPre bool - tabWidth int - lineNumbers bool - lineNumbersInTable bool - highlightRanges highlightRanges - baseLineNumber int + standalone bool + prefix string + Classes bool // Exported field to detect when classes are being used + preWrapper PreWrapper + tabWidth int + lineNumbers bool + lineNumbersInTable bool + highlightRanges highlightRanges + baseLineNumber int } type highlightRanges [][2]int @@ -129,9 +185,7 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []chroma. fmt.Fprintf(w, "\n", f.styleAttr(css, chroma.Background)) fmt.Fprintf(w, "", f.styleAttr(css, chroma.LineTable)) fmt.Fprintf(w, "\n", f.styleAttr(css, chroma.LineTableTD)) - if !f.preventSurroundingPre { - fmt.Fprintf(w, "", f.styleAttr(css, chroma.Background)) - } + fmt.Fprintf(w, f.preWrapper.Start(false, f.styleAttr(css, chroma.Background))) for index := range lines { line := f.baseLineNumber + index highlight, next := f.shouldHighlight(highlightIndex, line) @@ -148,16 +202,13 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []chroma. fmt.Fprintf(w, "") } } - if !f.preventSurroundingPre { - fmt.Fprint(w, "") - } + fmt.Fprint(w, f.preWrapper.End(false)) fmt.Fprint(w, "\n") fmt.Fprintf(w, "\n", f.styleAttr(css, chroma.LineTableTD, "width:100%")) } - if !f.preventSurroundingPre { - fmt.Fprintf(w, "", f.styleAttr(css, chroma.Background)) - } + fmt.Fprintf(w, f.preWrapper.Start(true, f.styleAttr(css, chroma.Background))) + highlightIndex = 0 for index, tokens := range lines { // 1-based line number. @@ -187,9 +238,7 @@ func (f *Formatter) writeHTML(w io.Writer, style *chroma.Style, tokens []chroma. } } - if !f.preventSurroundingPre { - fmt.Fprint(w, "") - } + fmt.Fprintf(w, f.preWrapper.End(true)) if wrapInTable { fmt.Fprint(w, "\n") diff --git a/vendor/github.com/alecthomas/chroma/lexers/b/bash.go b/vendor/github.com/alecthomas/chroma/lexers/b/bash.go index 131e432..38b3f22 100644 --- a/vendor/github.com/alecthomas/chroma/lexers/b/bash.go +++ b/vendor/github.com/alecthomas/chroma/lexers/b/bash.go @@ -53,7 +53,7 @@ var Bash = internal.Register(MustNewLexer( {`&`, Punctuation, nil}, {`\|`, Punctuation, nil}, {`\s+`, Text, nil}, - {`\d+\b`, LiteralNumber, nil}, + {`\d+(?= |$)`, LiteralNumber, nil}, {"[^=\\s\\[\\]{}()$\"\\'`\\\\<&|;]+", Text, nil}, {`<`, Text, nil}, }, diff --git a/vendor/github.com/alecthomas/chroma/lexers/m/mysql.go b/vendor/github.com/alecthomas/chroma/lexers/m/mysql.go index 52c9ad2..9f47e32 100644 --- a/vendor/github.com/alecthomas/chroma/lexers/m/mysql.go +++ b/vendor/github.com/alecthomas/chroma/lexers/m/mysql.go @@ -26,7 +26,7 @@ var MySQL = internal.Register(MustNewLexer( {`((?:_[a-z0-9]+)?)(")`, ByGroups(LiteralStringAffix, LiteralStringDouble), Push("double-string")}, {"[+*/<>=~!@#%^&|`?-]", Operator, nil}, {`\b(tinyint|smallint|mediumint|int|integer|bigint|date|datetime|time|bit|bool|tinytext|mediumtext|longtext|text|tinyblob|mediumblob|longblob|blob|float|double|double\s+precision|real|numeric|dec|decimal|timestamp|year|char|varchar|varbinary|varcharacter|enum|set)(\b\s*)(\()?`, ByGroups(KeywordType, Text, Punctuation), nil}, - {`\b(add|all|alter|analyze|and|as|asc|asensitive|before|between|bigint|binary|blob|both|by|call|cascade|case|change|char|character|check|collate|column|condition|constraint|continue|convert|create|cross|current_date|current_time|current_timestamp|current_user|cursor|database|databases|day_hour|day_microsecond|day_minute|day_second|dec|decimal|declare|default|delayed|delete|desc|describe|deterministic|distinct|distinctrow|div|double|drop|dual|each|else|elseif|enclosed|escaped|exists|exit|explain|fetch|flush|float|float4|float8|for|force|foreign|from|fulltext|grant|group|having|high_priority|hour_microsecond|hour_minute|hour_second|if|ignore|in|index|infile|inner|inout|insensitive|insert|int|int1|int2|int3|int4|int8|integer|interval|into|is|iterate|join|key|keys|kill|leading|leave|left|like|limit|lines|load|localtime|localtimestamp|lock|long|loop|low_priority|match|minute_microsecond|minute_second|mod|modifies|natural|no_write_to_binlog|not|numeric|on|optimize|option|optionally|or|order|out|outer|outfile|precision|primary|procedure|purge|raid0|read|reads|real|references|regexp|release|rename|repeat|replace|require|restrict|return|revoke|right|rlike|schema|schemas|second_microsecond|select|sensitive|separator|set|show|smallint|soname|spatial|specific|sql|sql_big_result|sql_calc_found_rows|sql_small_result|sqlexception|sqlstate|sqlwarning|ssl|starting|straight_join|table|terminated|then|to|trailing|trigger|undo|union|unique|unlock|unsigned|update|usage|use|using|utc_date|utc_time|utc_timestamp|values|varying|when|where|while|with|write|x509|xor|year_month|zerofill)\b`, Keyword, nil}, + {`\b(add|all|alter|analyze|and|as|asc|asensitive|before|between|bigint|binary|blob|both|by|call|cascade|case|change|char|character|check|collate|column|condition|constraint|continue|convert|create|cross|current_date|current_time|current_timestamp|current_user|cursor|database|databases|day_hour|day_microsecond|day_minute|day_second|dec|decimal|declare|default|delayed|delete|desc|describe|deterministic|distinct|distinctrow|div|double|drop|dual|each|else|elseif|enclosed|escaped|exists|exit|explain|fetch|flush|float|float4|float8|for|force|foreign|from|fulltext|grant|group|having|high_priority|hour_microsecond|hour_minute|hour_second|identified|if|ignore|in|index|infile|inner|inout|insensitive|insert|int|int1|int2|int3|int4|int8|integer|interval|into|is|iterate|join|key|keys|kill|leading|leave|left|like|limit|lines|load|localtime|localtimestamp|lock|long|loop|low_priority|match|minute_microsecond|minute_second|mod|modifies|natural|no_write_to_binlog|not|numeric|on|optimize|option|optionally|or|order|out|outer|outfile|precision|primary|privileges|procedure|purge|raid0|read|reads|real|references|regexp|release|rename|repeat|replace|require|restrict|return|revoke|right|rlike|schema|schemas|second_microsecond|select|sensitive|separator|set|show|smallint|soname|spatial|specific|sql|sql_big_result|sql_calc_found_rows|sql_small_result|sqlexception|sqlstate|sqlwarning|ssl|starting|straight_join|table|terminated|then|to|trailing|trigger|undo|union|unique|unlock|unsigned|update|usage|use|user|using|utc_date|utc_time|utc_timestamp|values|varying|when|where|while|with|write|x509|xor|year_month|zerofill)\b`, Keyword, nil}, {`\b(auto_increment|engine|charset|tables)\b`, KeywordPseudo, nil}, {`(true|false|null)`, NameConstant, nil}, {`([a-z_]\w*)(\s*)(\()`, ByGroups(NameFunction, Text, Punctuation), nil}, diff --git a/vendor/github.com/alecthomas/chroma/regexp.go b/vendor/github.com/alecthomas/chroma/regexp.go index 9756fe8..7c2fb0b 100644 --- a/vendor/github.com/alecthomas/chroma/regexp.go +++ b/vendor/github.com/alecthomas/chroma/regexp.go @@ -34,7 +34,6 @@ func (e EmitterFunc) Emit(groups []string, lexer Lexer) Iterator { return e(grou func ByGroups(emitters ...Emitter) Emitter { return EmitterFunc(func(groups []string, lexer Lexer) Iterator { iterators := make([]Iterator, 0, len(groups)-1) - // NOTE: If this panics, there is a mismatch with groups if len(emitters) != len(groups)-1 { iterators = append(iterators, Error.Emit(groups, lexer)) // panic(errors.Errorf("number of groups %q does not match number of emitters %v", groups, emitters)) diff --git a/vendor/modules.txt b/vendor/modules.txt index e6d3f00..7ce424c 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -1,4 +1,4 @@ -# github.com/alecthomas/chroma v0.6.9 +# github.com/alecthomas/chroma v0.7.0 github.com/alecthomas/chroma github.com/alecthomas/chroma/formatters github.com/alecthomas/chroma/formatters/html