From 77bff0c760ff6906b83d3908028621b8cf3da8b0 Mon Sep 17 00:00:00 2001 From: Oleh Prypin Date: Thu, 1 Feb 2024 22:41:40 +0100 Subject: [PATCH] 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. --- mkdocs_git_revision_date_localized_plugin/util.py | 8 +++++--- requirements.txt | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/mkdocs_git_revision_date_localized_plugin/util.py b/mkdocs_git_revision_date_localized_plugin/util.py index 1cbb474..b963013 100644 --- a/mkdocs_git_revision_date_localized_plugin/util.py +++ b/mkdocs_git_revision_date_localized_plugin/util.py @@ -3,6 +3,8 @@ import os import time +from markupsafe import Markup + from mkdocs_git_revision_date_localized_plugin.ci import raise_ci_warnings from mkdocs_git_revision_date_localized_plugin.dates import get_date_formats @@ -85,7 +87,7 @@ def get_git_commit_timestamp( commit_timestamp = git.log( realpath, date="unix", format="%at", diff_filter="A", no_show_signature=True, follow=True ) - # A file can be created multiple times, through a file renamed. + # A file can be created multiple times, through a file renamed. # Commits are ordered with most recent commit first # Get the oldest commit only if commit_timestamp != "": @@ -165,7 +167,7 @@ def get_date_formats_for_timestamp( dict: Localized date variants. """ date_formats = get_date_formats( - unix_timestamp=commit_timestamp, + unix_timestamp=commit_timestamp, time_zone=self.config.get("timezone"), locale=locale, custom_format=self.config.get('custom_format') @@ -183,7 +185,7 @@ def add_spans(date_formats: Dict[str, str]) -> Dict[str, str]: """ for date_type, date_string in date_formats.items(): date_formats[date_type] = ( - '%s' + Markup('%s') % (date_type, date_string) ) return date_formats diff --git a/requirements.txt b/requirements.txt index 45ba908..38a8da5 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,5 @@ mkdocs>=1.0 GitPython babel>=2.7.0 -pytz \ No newline at end of file +pytz +markupsafe