Skip to content

Commit

Permalink
Fixed UTF-8 with BOM encoding support
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilkrzyskow authored and squidfunk committed Mar 17, 2024
1 parent 2f1b2e9 commit 022f14c
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion material/plugins/blog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def _resolve_authors(self, config: MkDocsConfig):
return config.authors

# Open file and parse as YAML
with open(file, encoding = "utf-8") as f:
with open(file, encoding = "utf-8-sig") as f:
config.config_file_path = os.path.abspath(file)
try:
config.load_dict(yaml.load(f, SafeLoader) or {})
Expand Down
2 changes: 1 addition & 1 deletion material/plugins/blog/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, file: File, config: MkDocsConfig):
path = os.path.relpath(file.abs_src_path, docs)

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

# Sadly, MkDocs swallows any exceptions that occur during parsing.
Expand Down
4 changes: 2 additions & 2 deletions material/plugins/info/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def _convert_to_abs(path: str, abs_prefix: str = None) -> str:
# logic. Side effect: It converts the INHERIT path to absolute.
def _load_yaml(abs_src_path: str):

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

try:
Expand Down Expand Up @@ -479,7 +479,7 @@ def _resolve_pattern(abspath: str, return_path: bool = False):

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

Expand Down
4 changes: 2 additions & 2 deletions material/plugins/privacy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def _parse_media(self, initiator: File) -> list[URL]:

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

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

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

# Replace callback
def replace(match: Match):
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/blog/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def _resolve_authors(self, config: MkDocsConfig):
return config.authors

# Open file and parse as YAML
with open(file, encoding = "utf-8") as f:
with open(file, encoding = "utf-8-sig") as f:
config.config_file_path = os.path.abspath(file)
try:
config.load_dict(yaml.load(f, SafeLoader) or {})
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/blog/structure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def __init__(self, file: File, config: MkDocsConfig):
path = os.path.relpath(file.abs_src_path, docs)

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

# Sadly, MkDocs swallows any exceptions that occur during parsing.
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/info/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ def _convert_to_abs(path: str, abs_prefix: str = None) -> str:
# logic. Side effect: It converts the INHERIT path to absolute.
def _load_yaml(abs_src_path: str):

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

try:
Expand Down Expand Up @@ -479,7 +479,7 @@ def _resolve_pattern(abspath: str, return_path: bool = False):

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

Expand Down
4 changes: 2 additions & 2 deletions src/plugins/privacy/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ def _parse_media(self, initiator: File) -> list[URL]:

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

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

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

# Replace callback
def replace(match: Match):
Expand Down

0 comments on commit 022f14c

Please sign in to comment.