pypa / readme_renderer

Safely render long_description/README files in Warehouse
Apache License 2.0
157 stars 88 forks source link

Official PyPI way to render strikethru in .rst description? #141

Closed pfalcon closed 2 years ago

pfalcon commented 5 years ago

Describe the bug

I'm unable to render strike-thru text in long_description in reStructuredText: https://pypi.org/project/picoweb/1.5/ . Given that there's no builtin strike-thru support in .rst (big-big sigh), I was using one of the methods described in https://stackoverflow.com/questions/15989218/how-to-do-strikethrough-in-a-restructuredtext-file-hosted-on-github , that happened to be:

.. raw:: html

   <strike>

Well, that doesn't work with PyPI. And I hope I can be kindly guided re: what would work. I both tried to search on google regarding that, and here in bug tracker, in vain.

Keywords for search: strikethru, strike

Expected behavior

I hope I can render strikethru.

To Reproduce URL: https://pypi.org/project/picoweb/1.5/

Problem spot is:

.. raw:: html

   <strike>

Paragraph of text.

.. raw:: html

   </strike>
pfalcon commented 5 years ago

Was kindly and promptly helped by @ewdurbin and @di with my previous similar issue https://github.com/pypa/warehouse/issues/4855, so dare to ping them directly. Thanks in advance.

di commented 5 years ago

Moved this issue to pypa/readme_renderer.

The raw directive is not supported, so if there's not a standard way to do this with rST, it seems unlikely that it will be possible.

This isn't a real answer to your question, but are you aware that you can write your description in Markdown instead, which does support strikethrough?

dstufft commented 5 years ago

We might be able to support the raw directive unless it takes a file or something. We're not relying on rst producing good HTML anymore since we have bleach.

pfalcon commented 5 years ago

The linked issue has other alternatives, but they involve suitable class defined in CSS:

 .. role:: strike
    :class: strike

And using something like this in the CSS file:

.strike {
  text-decoration: line-through;
}

And do strikethrough like this:

:strike:`This text is crossed out`

I understand that supporting raw blocks may be dangerous, but perhaps above could be supported.

Well, I guess I could experiment with it, it's just end of my day, I wanted to announce a new release, and suddenly noticed .rst formatting is broken, so just tried to ask a quick question instead...

pfalcon commented 5 years ago

but are you aware that you can write your description in Markdown instead, which does support strikethrough?

Actually I didn't, I thought Python is tightly coupled with .rst ;-). I'll explore that possibility, thanks.

In that case I hope that maybe this ticket can be left as a kind of feature request...

pfalcon commented 5 years ago

but they involve suitable class defined in CSS:

And yes, then it wouldn't be portable between sites. My original concern was making it render on Github, that's why I chose raw block. A chance that there's a similarly named CSS class for strikethru on both Github and PyPI (and that it stay that way) is slim...

miketheman commented 2 years ago

Reviewing older issues. <strike> is no longer the recommended way to represent struck text. See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/strike Preferred are <del> and <s> - but still nothing specific in docutils. We currently allow the del attribute through our sanitizer, so this works:

.. role:: del

:del:`This text is crossed out`

turns into:

<p><del>This text is crossed out</del></p>

With the appropriate changes on the warehouse CSS side, this would render as desired.

From a portability perspective, as a custom RST role it'd have to be implemented in any system using it. There's a Sphinx extension that conforms to del as well.

miketheman commented 2 years ago

Double-checked this today, and it turns out that we don't need any explicit CSS on warehouse unless we want it, because the major browsers support del natively already! 🎉