@@ -53,6 +53,7 @@ func NewFile(src string, config *Config) (*File, error) {
5353 var format , ext string
5454 var fbytes []byte
5555 var lookup bool
56+ path := src
5657
5758 if system .FileExists (src ) {
5859 fbytes , _ = os .ReadFile (src )
@@ -62,14 +63,24 @@ func NewFile(src string, config *Config) (*File, error) {
6263 ext , format = FormatFromExt (src , config .Formats )
6364 }
6465 } else {
65- ext , format = FormatFromExt (config .Flags .InExt , config .Formats )
6666 fbytes = []byte (src )
67- src = "stdin" + config .Flags .InExt
6867 lookup = true
68+ // For stdin, allow an explicit path override to drive path-based config.
69+ if config .Flags .InPath != "" {
70+ path = config .Flags .InPath
71+ } else {
72+ path = "stdin" + config .Flags .InExt
73+ }
74+ // If --ext was explicitly set, respect it; otherwise infer from the path.
75+ if config .Flags .InExt != ".txt" {
76+ ext , format = FormatFromExt (config .Flags .InExt , config .Formats )
77+ } else {
78+ ext , format = FormatFromExt (path , config .Formats )
79+ }
6980 }
7081
71- filepaths := []string {src }
72- normed := system .ReplaceFileExt (src , config .Formats )
82+ filepaths := []string {path }
83+ normed := system .ReplaceFileExt (path , config .Formats )
7384
7485 baseStyles := config .GBaseStyles
7586 checks := make (map [string ]bool )
@@ -95,7 +106,7 @@ func NewFile(src string, config *Config) (*File, error) {
95106 sec , err := glob .Compile (syntax )
96107 if err != nil {
97108 return & File {}, err
98- } else if sec .Match (src ) {
109+ } else if sec .Match (path ) {
99110 lang = code
100111 break
101112 }
@@ -105,8 +116,8 @@ func NewFile(src string, config *Config) (*File, error) {
105116 for sec , p := range config .Stylesheets {
106117 pat , err := glob .Compile (sec )
107118 if err != nil {
108- return & File {}, NewE100 (src , err )
109- } else if pat .Match (src ) {
119+ return & File {}, NewE100 (path , err )
120+ } else if pat .Match (path ) {
110121 transform = p
111122 break
112123 }
@@ -120,11 +131,11 @@ func NewFile(src string, config *Config) (*File, error) {
120131 lines := strings .SplitAfter (strings .Clone (content ), "\n " )
121132
122133 file := File {
123- NormedExt : ext , Format : format , RealExt : filepath .Ext (src ),
134+ NormedExt : ext , Format : format , RealExt : filepath .Ext (path ),
124135 BaseStyles : baseStyles , Checks : checks , Lines : lines , Content : content ,
125136 Comments : make (map [string ]bool ), history : make (map [string ]int ),
126137 simple : config .Flags .Simple , Transform : transform ,
127- limits : make (map [string ]int ), Path : src , Metrics : make (map [string ]int ),
138+ limits : make (map [string ]int ), Path : path , Metrics : make (map [string ]int ),
128139 NLP : nlp.Info {Endpoint : config .NLPEndpoint , Lang : lang },
129140 Lookup : lookup , NormedPath : normed ,
130141 }
0 commit comments