Skip to content

Commit 3997ec6

Browse files
denisbukanovyahuaska
authored andcommitted
gh-127276: add embedded styles to documentation pages created by a 'python -m pydoc -w' call
1 parent 26ff32b commit 3997ec6

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Lib/pydoc.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class or function within a module or module in a package. If the
5858
import importlib._bootstrap
5959
import importlib._bootstrap_external
6060
import importlib.machinery
61+
import importlib.resources
6162
import importlib.util
6263
import inspect
6364
import io
@@ -631,15 +632,19 @@ class HTMLDoc(Doc):
631632

632633
def page(self, title, contents):
633634
"""Format an HTML page."""
635+
css_data = importlib.resources.files('pydoc_data').joinpath('_pydoc.css').read_text()
634636
return '''\
635637
<!DOCTYPE html>
636638
<html lang="en">
637639
<head>
638640
<meta charset="utf-8">
639641
<title>Python: %s</title>
642+
<style>
643+
%s
644+
</style>
640645
</head><body>
641646
%s
642-
</body></html>''' % (title, contents)
647+
</body></html>''' % (title, css_data, contents)
643648

644649
def heading(self, title, extras=''):
645650
"""Format a page heading."""

0 commit comments

Comments
 (0)