New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
For jinja autoescape, mark HTML strings as safe, not needing escaping #126
Conversation
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.
|
Thanks, will release after the weekend! |
Done. Thanks again! |
The changes in this PR break the native integration with Material for MkDocs, see #127 |
Markup('<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-%s">%s</span>') | ||
% (date_type, date_string) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the bad change.
I tried out the plugin only in the default config without overrides, and it kept working.
On the linked site, a non-default style is probably used, that's why it's observed there.
My mistake is as follows:
I assumed that the date_string
string is text, not HTML. I intentionally added Markup
in a way that would escape that string. However there is one type of date_string that is HTML, it's here:
mkdocs-git-revision-date-localized-plugin/mkdocs_git_revision_date_localized_plugin/dates.py
Line 44 in fe156ff
"timeago": '<span class="timeago" datetime="%s" locale="%s"></span>' % (loc_revision_date.isoformat(), locale), |
I could've added Markup
in a simpler and more careful way and should've just done that.
Bad:
Markup('<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-%s">%s</span>')
% (date_type, date_string)
Good:
Markup(
'<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-%s">%s</span>')
% (date_type, date_string)
)
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, without this change, the HTML will be pasted like this into the doc:
When Jinja's autoescape is not enabled, there's no change in behavior.