Skip to content

ContentFormat image HTML source needs to escape attributes #2035

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

Open
thibaudcolas opened this issue Apr 16, 2025 · 1 comment · May be fixed by #2036
Open

ContentFormat image HTML source needs to escape attributes #2035

thibaudcolas opened this issue Apr 16, 2025 · 1 comment · May be fixed by #2036

Comments

@thibaudcolas
Copy link
Member

From #2001 – the alt attribute contents need escaping for HTML, here:

def img(self, url, alt_text):
"""
Generate the source code for an image in the current format
"""
CF = type(self)
return {
CF.REST: f".. image:: {url}\n :alt: {alt_text}",
CF.HTML: f'<img src="{url}" alt="{alt_text}">',
.

As-is, the "Raw HTML" copy button will generate invalid markup when it contains double quotes. For example:

<img src="https://media.djangoproject.com/blog/images/2025/04/20250416-run-your-tests-against.webp" alt="Sage presenting, holding a microphone. To his right his title slide states "Run your tests against Django’s main!", "Django London Meetup", "Thursday, 13 February 2025"">
@bmispelon
Copy link
Member

Good catch, thanks for reporting it! 🎸

I've opened a PR with a fix for this and other escaping issues: #2036

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

Successfully merging a pull request may close this issue.

2 participants