Skip to content

gh-127276: add embedded styles to documentation pages created by a 'python -m pydoc -w' call #127277

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
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Lib/pydoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class or function within a module or module in a package. If the
import importlib._bootstrap
import importlib._bootstrap_external
import importlib.machinery
import importlib.resources
import importlib.util
import inspect
import io
Expand Down Expand Up @@ -631,15 +632,19 @@ class HTMLDoc(Doc):

def page(self, title, contents):
"""Format an HTML page."""
css_data = importlib.resources.files('pydoc_data').joinpath('_pydoc.css').read_text()
Copy link
Member

Choose a reason for hiding this comment

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

Can this fail on any envs?

Copy link
Member

Choose a reason for hiding this comment

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

Ideally rhis should also be documented (i.e. you should say which file we are looking for). Maybe we can have a list of allowed files?

return '''\
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Python: %s</title>
<style>
%s
</style>
</head><body>
%s
</body></html>''' % (title, contents)
</body></html>''' % (title, css_data, contents)

def heading(self, title, extras=''):
"""Format a page heading."""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add embedded styles to documentation pages created by a 'python -m pydoc -w' call
Copy link
Member

Choose a reason for hiding this comment

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

I'm on mobile but this new feature warrants a What's New entry as well.

By the way, I'd suggest using back quotes to format the command line rather than single quotes as well as adding a period at the end of the sentence:

Allow to specify embedded styles for documentation pages created by :option:`pydoc -w`.

Please check that pydoc is documented as a program (with the .. program:: directive) and that -w is also a documented option (with the .. option:: directive). If not, you can just use

... created by the ``-w`` option of the :mod:`pydoc` program.

Loading