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

"Q&A against documentation" on the datasette.io homepage #13

Closed
simonw opened this issue Jan 27, 2023 · 8 comments
Closed

"Q&A against documentation" on the datasette.io homepage #13

simonw opened this issue Jan 27, 2023 · 8 comments
Labels
bug Something isn't working

Comments

@simonw
Copy link
Owner

simonw commented Jan 27, 2023

Screenshot 2023-01-27 at 2 54 55 PM

@simonw simonw added the bug Something isn't working label Jan 27, 2023
@simonw
Copy link
Owner Author

simonw commented Jan 27, 2023

So it looks like datasette-render-markdown is the thing that renders & as & in this context.

It uses https://python-markdown.github.io/

@simonw simonw changed the title "Q&A against documentation" on the homepage "Q&A against documentation" on the datasette.io homepage Jan 27, 2023
@simonw simonw transferred this issue from simonw/datasette.io Jan 27, 2023
@simonw
Copy link
Owner Author

simonw commented Jan 27, 2023

I think this is likely a bug in the interaction between the markdown rendering and Bleach in this plugin:

html = bleach.linkify(
cleaner.clean(
markdown.markdown(value, output_format="html5", extensions=extensions or [])
),
skip_tags=["pre"],
)

I can recreate it locally like this:

>>> from datasette_render_markdown import render_markdown
>>> render_markdown('[this & that](https://www.example.com/)')
Markup('<div style="white-space: normal"><p><a href="https://www.example.com/" rel="nofollow">this &amp;amp; that</a></p></div>')

Note this &amp;amp; that in the output.

@simonw
Copy link
Owner Author

simonw commented Jan 27, 2023

Confirmed: I removed the calls to bleach and got this:

<div style="white-space: normal"><p><a href="https://www.example.com/">this &amp; that</a></p></div>

@simonw
Copy link
Owner Author

simonw commented Jan 27, 2023

After more exploration, it turns out it's the call to bleach.linkify(...) that causes the double escaping of the ampersand.

@simonw
Copy link
Owner Author

simonw commented Jan 27, 2023

https://bleach.readthedocs.io/en/latest/linkify.html says:

If you plan to sanitize/clean the text and linkify it, you should do that in a single pass using LinkifyFilter. This is faster and it'll use the list of allowed tags from clean.

@simonw simonw closed this as completed in 2ab34c3 Jan 27, 2023
simonw added a commit that referenced this issue Jan 27, 2023
simonw added a commit to simonw/datasette.io that referenced this issue Jan 27, 2023
Fix for double-escaped ampersand bug, refs simonw/datasette-render-markdown#13
@simonw
Copy link
Owner Author

simonw commented Jan 27, 2023

Deployed that fix to https://datasette.io/

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant