1212 MutableMapping ,
1313 Dict ,
1414 Mapping ,
15- Set ,
1615 Tuple ,
1716)
1817
@@ -40,9 +39,17 @@ class VbaHandler(BaseHandler):
4039 The directory in which to look for VBA files.
4140 """
4241
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 :
4450 super ().__init__ (** kwargs )
4551 self .base_dir = base_dir
52+ self .encoding = encoding
4653
4754 name : str = "vba"
4855 """
@@ -121,9 +128,7 @@ def collect(
121128 if not p .exists ():
122129 raise CollectionError ("File not found." )
123130
124- with p .open ("r" ) as f :
125- code = f .read ()
126-
131+ code = p .read_text (encoding = self .encoding , errors = "replace" )
127132 code = collapse_long_lines (code )
128133
129134 return VbaModuleInfo (
@@ -178,6 +183,7 @@ def get_handler(
178183 theme : str = "material" ,
179184 custom_templates : str | None = None ,
180185 config_file_path : str | None = None ,
186+ encoding : str = "latin1" ,
181187 ** kwargs : Any ,
182188) -> VbaHandler :
183189 """
@@ -187,6 +193,10 @@ def get_handler(
187193 theme: The theme to use when rendering contents.
188194 custom_templates: Directory containing custom templates.
189195 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 .
190200 kwargs: Extra keyword arguments that we don't use.
191201
192202 Returns:
@@ -198,6 +208,7 @@ def get_handler(
198208 if config_file_path
199209 else Path ("." ).resolve ()
200210 ),
211+ encoding = encoding ,
201212 handler = "vba" ,
202213 theme = theme ,
203214 custom_templates = custom_templates ,
0 commit comments