Skip to content

Commit a1ce32b

Browse files
committed
Fixing file detection order
1 parent 4298105 commit a1ce32b

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

main.go

+8-7
Original file line numberDiff line numberDiff line change
@@ -185,21 +185,21 @@ func (args *Args) renderFile(name string) (image.Image, string, error) {
185185
args.logger("mime: %s", typ)
186186
var g func(io.Reader, string) (image.Image, error)
187187
var notStream bool
188-
switch {
188+
switch ext := strings.ToLower(strings.TrimPrefix(filepath.Ext(name), ".")); {
189189
case typ == "image/svg":
190190
g = args.renderResvg
191-
case typ == "text/plain":
192-
g = args.renderMarkdown
193191
case isImageBuiltin(typ):
194192
g = args.renderImage
193+
case isLibreOffice(typ, ext):
194+
g, notStream = args.renderLibreOffice, true
195195
case isVipsImage(typ): // use vips
196196
g = args.renderVips
197+
case typ == "text/plain":
198+
g = args.renderMarkdown
197199
case strings.HasPrefix(typ, "font/"):
198200
g = args.renderFont
199201
case strings.HasPrefix(typ, "video/"):
200202
g, notStream = args.renderAstiav, true
201-
case isLibreOffice(typ):
202-
g, notStream = args.renderLibreOffice, true
203203
default:
204204
return nil, "", fmt.Errorf("mime type %q not supported", typ)
205205
}
@@ -646,15 +646,16 @@ func isVipsImage(typ string) bool {
646646

647647
// isLibreOffice returns true if the mime type is supported by the `soffice`
648648
// command.
649-
func isLibreOffice(typ string) bool {
649+
func isLibreOffice(typ, ext string) bool {
650650
switch {
651651
case
652652
strings.HasPrefix(typ, "application/vnd.openxmlformats-officedocument."), // pptx, xlsx, ...
653653
strings.HasPrefix(typ, "application/vnd.ms-"), // ppt, xls, ...
654654
strings.HasPrefix(typ, "application/vnd.oasis.opendocument."), // otp, otp, odg, ...
655655
typ == "text/rtf",
656656
typ == "text/csv",
657-
typ == "text/tab-separated-values":
657+
typ == "text/tab-separated-values",
658+
typ == "text/plain" && (ext == "csv" || ext == "tsv"):
658659
return true
659660
}
660661
return false

0 commit comments

Comments
 (0)