Skip to content
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

Merged
merged 1 commit into from Feb 1, 2024

Conversation

oprypin
Copy link
Contributor

@oprypin oprypin commented Feb 1, 2024

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:

<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.

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.
@oprypin
Copy link
Contributor Author

oprypin commented Feb 1, 2024

@timvink timvink merged commit ce28e85 into timvink:master Feb 1, 2024
15 checks passed
@timvink
Copy link
Owner

timvink commented Feb 1, 2024

Thanks, will release after the weekend!

@oprypin oprypin deleted the esc branch February 1, 2024 22:24
@timvink
Copy link
Owner

timvink commented Feb 2, 2024

Done. Thanks again!

@squidfunk
Copy link
Sponsor Collaborator

squidfunk commented Feb 3, 2024

The changes in this PR break the native integration with Material for MkDocs, see #127

Comment on lines +188 to 189
Markup('<span class="git-revision-date-localized-plugin git-revision-date-localized-plugin-%s">%s</span>')
% (date_type, date_string)
Copy link
Contributor Author

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:

"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)
             )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants