Skip to content

Commit 022f14c

Browse files
kamilkrzyskowsquidfunk
authored andcommitted
Fixed UTF-8 with BOM encoding support
1 parent 2f1b2e9 commit 022f14c

File tree

8 files changed

+12
-12
lines changed

8 files changed

+12
-12
lines changed

Diff for: material/plugins/blog/plugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def _resolve_authors(self, config: MkDocsConfig):
460460
return config.authors
461461

462462
# Open file and parse as YAML
463-
with open(file, encoding = "utf-8") as f:
463+
with open(file, encoding = "utf-8-sig") as f:
464464
config.config_file_path = os.path.abspath(file)
465465
try:
466466
config.load_dict(yaml.load(f, SafeLoader) or {})

Diff for: material/plugins/blog/structure/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, file: File, config: MkDocsConfig):
5757
path = os.path.relpath(file.abs_src_path, docs)
5858

5959
# Read contents and metadata immediately
60-
with open(file.abs_src_path, encoding = "utf-8") as f:
60+
with open(file.abs_src_path, encoding = "utf-8-sig") as f:
6161
self.markdown = f.read()
6262

6363
# Sadly, MkDocs swallows any exceptions that occur during parsing.

Diff for: material/plugins/info/plugin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def _convert_to_abs(path: str, abs_prefix: str = None) -> str:
437437
# logic. Side effect: It converts the INHERIT path to absolute.
438438
def _load_yaml(abs_src_path: str):
439439

440-
with open(abs_src_path, "r", encoding ="utf-8-sig") as file:
440+
with open(abs_src_path, encoding ="utf-8-sig") as file:
441441
source = file.read()
442442

443443
try:
@@ -479,7 +479,7 @@ def _resolve_pattern(abspath: str, return_path: bool = False):
479479

480480
# Get project configuration with resolved absolute paths for validation
481481
def _get_project_config(project_config_file: str):
482-
with open(project_config_file, encoding="utf-8") as file:
482+
with open(project_config_file, encoding="utf-8-sig") as file:
483483
config = MkDocsConfig(config_file_path = project_config_file)
484484
config.load_file(file)
485485

Diff for: material/plugins/privacy/plugin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def _parse_media(self, initiator: File) -> list[URL]:
254254

255255
# Find and extract all external asset URLs
256256
expr = re.compile(self.assets_expr_map[extension], flags = re.I | re.M)
257-
with open(initiator.abs_src_path, encoding = "utf-8") as f:
257+
with open(initiator.abs_src_path, encoding = "utf-8-sig") as f:
258258
return [urlparse(url) for url in re.findall(expr, f.read())]
259259

260260
# Parse template or page HTML and find all external links that need to be
@@ -437,7 +437,7 @@ def _fetch(self, file: File, config: MkDocsConfig):
437437

438438
# Patch all links to external assets in the given file
439439
def _patch(self, initiator: File):
440-
with open(initiator.abs_src_path, encoding = "utf-8") as f:
440+
with open(initiator.abs_src_path, encoding = "utf-8-sig") as f:
441441

442442
# Replace callback
443443
def replace(match: Match):

Diff for: src/plugins/blog/plugin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def _resolve_authors(self, config: MkDocsConfig):
460460
return config.authors
461461

462462
# Open file and parse as YAML
463-
with open(file, encoding = "utf-8") as f:
463+
with open(file, encoding = "utf-8-sig") as f:
464464
config.config_file_path = os.path.abspath(file)
465465
try:
466466
config.load_dict(yaml.load(f, SafeLoader) or {})

Diff for: src/plugins/blog/structure/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def __init__(self, file: File, config: MkDocsConfig):
5757
path = os.path.relpath(file.abs_src_path, docs)
5858

5959
# Read contents and metadata immediately
60-
with open(file.abs_src_path, encoding = "utf-8") as f:
60+
with open(file.abs_src_path, encoding = "utf-8-sig") as f:
6161
self.markdown = f.read()
6262

6363
# Sadly, MkDocs swallows any exceptions that occur during parsing.

Diff for: src/plugins/info/plugin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ def _convert_to_abs(path: str, abs_prefix: str = None) -> str:
437437
# logic. Side effect: It converts the INHERIT path to absolute.
438438
def _load_yaml(abs_src_path: str):
439439

440-
with open(abs_src_path, "r", encoding ="utf-8-sig") as file:
440+
with open(abs_src_path, encoding ="utf-8-sig") as file:
441441
source = file.read()
442442

443443
try:
@@ -479,7 +479,7 @@ def _resolve_pattern(abspath: str, return_path: bool = False):
479479

480480
# Get project configuration with resolved absolute paths for validation
481481
def _get_project_config(project_config_file: str):
482-
with open(project_config_file, encoding="utf-8") as file:
482+
with open(project_config_file, encoding="utf-8-sig") as file:
483483
config = MkDocsConfig(config_file_path = project_config_file)
484484
config.load_file(file)
485485

Diff for: src/plugins/privacy/plugin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ def _parse_media(self, initiator: File) -> list[URL]:
254254

255255
# Find and extract all external asset URLs
256256
expr = re.compile(self.assets_expr_map[extension], flags = re.I | re.M)
257-
with open(initiator.abs_src_path, encoding = "utf-8") as f:
257+
with open(initiator.abs_src_path, encoding = "utf-8-sig") as f:
258258
return [urlparse(url) for url in re.findall(expr, f.read())]
259259

260260
# Parse template or page HTML and find all external links that need to be
@@ -437,7 +437,7 @@ def _fetch(self, file: File, config: MkDocsConfig):
437437

438438
# Patch all links to external assets in the given file
439439
def _patch(self, initiator: File):
440-
with open(initiator.abs_src_path, encoding = "utf-8") as f:
440+
with open(initiator.abs_src_path, encoding = "utf-8-sig") as f:
441441

442442
# Replace callback
443443
def replace(match: Match):

0 commit comments

Comments
 (0)