12
12
MutableMapping ,
13
13
Dict ,
14
14
Mapping ,
15
- Set ,
16
15
Tuple ,
17
16
)
18
17
@@ -40,9 +39,17 @@ class VbaHandler(BaseHandler):
40
39
The directory in which to look for VBA files.
41
40
"""
42
41
43
- def __init__ (self , * , base_dir : Path , ** kwargs : Any ) -> None :
42
+ encoding : str
43
+ """
44
+ The encoding to use when reading VBA files.
45
+ Excel exports .bas and .cls files as `latin1`.
46
+ See https://en.wikipedia.org/wiki/ISO/IEC_8859-1 .
47
+ """
48
+
49
+ def __init__ (self , * , base_dir : Path , encoding : str , ** kwargs : Any ) -> None :
44
50
super ().__init__ (** kwargs )
45
51
self .base_dir = base_dir
52
+ self .encoding = encoding
46
53
47
54
name : str = "vba"
48
55
"""
@@ -121,9 +128,7 @@ def collect(
121
128
if not p .exists ():
122
129
raise CollectionError ("File not found." )
123
130
124
- with p .open ("r" ) as f :
125
- code = f .read ()
126
-
131
+ code = p .read_text (encoding = self .encoding , errors = "replace" )
127
132
code = collapse_long_lines (code )
128
133
129
134
return VbaModuleInfo (
@@ -178,6 +183,7 @@ def get_handler(
178
183
theme : str = "material" ,
179
184
custom_templates : str | None = None ,
180
185
config_file_path : str | None = None ,
186
+ encoding : str = "latin1" ,
181
187
** kwargs : Any ,
182
188
) -> VbaHandler :
183
189
"""
@@ -187,6 +193,10 @@ def get_handler(
187
193
theme: The theme to use when rendering contents.
188
194
custom_templates: Directory containing custom templates.
189
195
config_file_path: The MkDocs configuration file path.
196
+ encoding:
197
+ The encoding to use when reading VBA files.
198
+ Excel exports .bas and .cls files as `latin1`.
199
+ See https://en.wikipedia.org/wiki/ISO/IEC_8859-1 .
190
200
kwargs: Extra keyword arguments that we don't use.
191
201
192
202
Returns:
@@ -198,6 +208,7 @@ def get_handler(
198
208
if config_file_path
199
209
else Path ("." ).resolve ()
200
210
),
211
+ encoding = encoding ,
201
212
handler = "vba" ,
202
213
theme = theme ,
203
214
custom_templates = custom_templates ,
0 commit comments