pdoc3 / pdoc

:snake: :arrow_right: :scroll: Auto-generate API documentation for Python projects
https://pdoc3.github.io/pdoc/
GNU Affero General Public License v3.0
1.12k stars 145 forks source link

Introduce option for hljs-meta tags to not be user-selectable. #372

Open sg495 opened 2 years ago

sg495 commented 2 years ago

Currently, the >>> and ... in Python REPL snippets are selectable in HTML docs (much as they are here, on Github):

>>> mylist = [
... 0, 1, 2, 3,
... 4, 5, 6, 7
... ]
>>> mylist
[0, 1, 2, 3, 4, 5, 6, 7]

This is inconvenient for people wanting to copy-paste the code, e.g. to reproduce the results: they have to manually remove the >>> and .... Lately, I've noticed snippets on Read the Docs where the >>> and ... are conveniently excluded from the selection. I have looked at the CSS of this snippet, and adding the following to css.mako seems to do the trick:

  .hljs-meta {
    user-select: none;
    pointer-events: none;
  }

I'm not sure about the impact of making hljs-meta tags not user-selectable across the board, but to me this seems sufficiently useful a feature to at least deserve a config entry. If this needs further investigation, I'm happy to have a deeper look and make a pull request 😄.

sg495 commented 2 years ago

On Firefox 95.0, the hljs-meta spans are replaced with blank lines when the text is copied (this also happens in the Read the Docs snippet I linked previously, so I think it's an issue with user-select: none, perhaps specifically inside HTML <code> tags). On latest Chrome/Edge it works fine.

I tried the following, but it doesn't fix this issue on Firefox:

  .hljs-meta {
    user-select: none;
    -moz-user-select: none;
    -webkit-user-select: none;
    -ms-user-select: none;
    pointer-events: none;
  }

I'll investigate further.

kernc commented 2 years ago

I don't mind using above snippet (the one without vendor prefixes). Some blank lines (BMO#1273836) are still better than nothing. PR welcome.

kernc commented 2 years ago

Is there an issue with making .hljs-meta tags not user-selectable as you proposed? I think it a legitimate request, and it should find its way into the codebase eventually. :smile: