Skip to content

Commit 77bff0c

Browse files
committed
For jinja autoescape, mark HTML strings as safe, not needing escaping
For contexts where Jinja's autoescape is enabled, this is necessary for keeping this string working without it being escaped. (This might become the default behavior in the next version of MkDocs) If so, the HTML will be pasted like this into the doc: <span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-date">March 17, 2022</span> When Jinja's autoescape is not enabled, there's no change in behavior.
1 parent abfc750 commit 77bff0c

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

mkdocs_git_revision_date_localized_plugin/util.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
import time
55

6+
from markupsafe import Markup
7+
68
from mkdocs_git_revision_date_localized_plugin.ci import raise_ci_warnings
79
from mkdocs_git_revision_date_localized_plugin.dates import get_date_formats
810

@@ -85,7 +87,7 @@ def get_git_commit_timestamp(
8587
commit_timestamp = git.log(
8688
realpath, date="unix", format="%at", diff_filter="A", no_show_signature=True, follow=True
8789
)
88-
# A file can be created multiple times, through a file renamed.
90+
# A file can be created multiple times, through a file renamed.
8991
# Commits are ordered with most recent commit first
9092
# Get the oldest commit only
9193
if commit_timestamp != "":
@@ -165,7 +167,7 @@ def get_date_formats_for_timestamp(
165167
dict: Localized date variants.
166168
"""
167169
date_formats = get_date_formats(
168-
unix_timestamp=commit_timestamp,
170+
unix_timestamp=commit_timestamp,
169171
time_zone=self.config.get("timezone"),
170172
locale=locale,
171173
custom_format=self.config.get('custom_format')
@@ -183,7 +185,7 @@ def add_spans(date_formats: Dict[str, str]) -> Dict[str, str]:
183185
"""
184186
for date_type, date_string in date_formats.items():
185187
date_formats[date_type] = (
186-
'<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-%s">%s</span>'
188+
Markup('<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-%s">%s</span>')
187189
% (date_type, date_string)
188190
)
189191
return date_formats

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
mkdocs>=1.0
22
GitPython
33
babel>=2.7.0
4-
pytz
4+
pytz
5+
markupsafe

0 commit comments

Comments
 (0)