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

Allow specific class values only #201

Closed
wants to merge 8 commits into from

Conversation

ewjoachim
Copy link
Member

@ewjoachim ewjoachim commented Jun 5, 2021

In order to avoid strange things, it would be better to ensure that rendered READMEs only contain the subset of classes that we expect them to contain.

@@ -41,9 +41,7 @@

# Custom Additions
"*": ["id"],
"hr": ["class"],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to find out why hr was expected to contain a class. It was added at the same time when hr was authorized as a tag itself, by @dstufft in #21 . If you happen to remember what it was about, I'm interested. But I couldn't find a relevant hr.<somthing> rule in Warehouse CSS.

@@ -52,19 +50,43 @@
"h4": ["align"],
"h5": ["align"],
"h6": ["align"],
"code": ["class"],
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we have a <code class=language-python>print("hello")</code> in the output of the Markdown rendering, we expressly change it to pygmentize before the bleaching is done, so at bleaching time we should not expect that tag.

r'<pre><code class="language-(?P<lang>.+?)">(?P<code>.+?)'

# Class is a specific attribute because not only do we want to allow it only
# on certain tags, but we also want to control possible values.
ALLOWED_CLASSES = {
"img": {"align-left", "align-right", "align-center"},
Copy link
Member Author

@ewjoachim ewjoachim Jun 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you look at https://github.com/pypa/warehouse/blob/master/warehouse/static/sass/blocks/_project-description.scss#L207-L209, you may find a discrepancy:

Warehouse CSS alignment rule will trigger on 3 possible conditions:

  • img.align-left which is the one we target here
  • .figure.align-left which according to Styles for image alignment (pypa/warehouse#4023) pypi/warehouse#4391 (comment) will be applied on a div element, but it's already broken as of today because div element doesn't allow class without our current bleaching rules, even before this PR. This could be fixed in a subsequent PR
  • object.align-left but object tags are not even allowed!
    So authorizing only those classes and only on img seems to not be a restriction compared to what we have today.

"bp c c1 ch cm cp cpf cs dl err esc fm g gd ge gh gi go gp gr gs gt "
"gu il k kc kd kn kp kr kt l ld m mb mf mh mi mo n na nb nc nd ne nf "
"ni nl nn no nt nv nx o ow p py s s1 s2 sa sb sc sd se sh si sr ss sx "
"vc vg vi vm w x".split()
Copy link
Member Author

@ewjoachim ewjoachim Jun 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you wonder, if pygmetize gets new CSS classes, it's not a problem that we won't have them here unless we want to style them in Warehouse, and in this case, we'll have to add them both here and in Warehouse CSS.

@@ -9,7 +9,7 @@ commands =
extras = md

[testenv:pep8]
basepython = python3.6
basepython = python3
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CI was launched using python 3.x but this tox target wanted 3.6 specifically, so it couldn't work. Don't know why it did so far. If you want this in a different PR, let me know.

@jboarman
Copy link

@ewjoachim

The latest cmarkgfm release makes an adjustment to how code blocks are rendered by removing CSS class assignments and favoring a lang attribute instead.

I've not studied the code here, but I did notice your earlier reference to the code class and this section of related code:

r'<pre><code class="language-(?P<lang>.+?)">(?P<code>.+?)'

I'm sharing this in case there is any related concern to what you are working on here in this PR.

@ewjoachim
Copy link
Member Author

Indeed! A good thing the dependency is restricted to <0.6.0 in setup.py, so our code won't have to handle both versions!

I guess it's something we'll have to look at when we upgrade but hopefully, when we do this, the impacts will be studied.

@ewjoachim
Copy link
Member Author

Oh there's an overlap with #120 !

@ewjoachim ewjoachim closed this May 15, 2023
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.

2 participants