Skip to content

Commit f3f2f4d

Browse files
committed
add symbols to html help from pydoc
1 parent d419cad commit f3f2f4d

2 files changed

Lines changed: 25 additions & 4 deletions

File tree

‎Lib/pydoc.py‎

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ class or function within a module or module in a package. If the
7171
import textwrap
7272
import time
7373
import tokenize
74+
import urllib.parse
7475
import warnings
7576
from annotationlib import Format
7677
from collections import deque
@@ -2314,6 +2315,9 @@ def _gettopic(self, topic, more_xrefs=''):
23142315
Sorry, topic and keyword documentation is not available because the
23152316
module "pydoc_data.topics" could not be found.
23162317
''' , '')
2318+
if topic in self.symbols:
2319+
topic, _, xrefs = self.symbols[topic].partition(' ')
2320+
more_xrefs = ' '.join([xrefs, more_xrefs]).strip()
23172321
target = self.topics.get(topic, self.keywords.get(topic))
23182322
if not target:
23192323
raise ValueError('could not find topic')
@@ -2687,14 +2691,14 @@ def onerror(modname):
26872691

26882692
# format page
26892693
def bltinlink(name):
2690-
return '<a href="%s.html">%s</a>' % (name, name)
2694+
return '<a href="%s.html">%s</a>' % (urllib.parse.quote(name), html.escape(name))
26912695

26922696
results = []
26932697
heading = html.heading('Search Results')
26942698
for name, desc in search_result:
26952699
results.append('<li>%s%s</li>' % (bltinlink(name), desc))
26962700
contents = heading + html.bigsection(
2697-
'key = %s' % key, 'index', '<ul>\n%s\n</ul>' % '\n'.join(results))
2701+
'key = %s' % html.escape(key), 'index', '<ul>\n%s\n</ul>' % '\n'.join(results))
26982702
return 'Search Results', contents
26992703

27002704
def html_topics():
@@ -2720,13 +2724,27 @@ def bltinlink(name):
27202724
contents = heading + html.multicolumn(names, bltinlink)
27212725
return 'Keywords', contents
27222726

2727+
def html_symbols():
2728+
"""Index of symbols available."""
2729+
2730+
def bltinlink(name):
2731+
return '<a href="topic?key=%s">%s</a>' % (urllib.parse.quote(name), html.escape(name))
2732+
2733+
heading = html.heading('Symbols')
2734+
names = sorted(Helper.symbols.keys())
2735+
2736+
contents = heading + html.multicolumn(names, bltinlink)
2737+
return 'Symbols', contents
2738+
27232739
def html_topicpage(topic):
27242740
"""Topic or keyword help page."""
27252741
buf = io.StringIO()
27262742
htmlhelp = Helper(buf, buf)
27272743
contents, xrefs = htmlhelp._gettopic(topic)
27282744
if topic in htmlhelp.keywords:
27292745
title = 'KEYWORD'
2746+
elif topic in htmlhelp.symbols:
2747+
title = 'SYMBOL'
27302748
else:
27312749
title = 'TOPIC'
27322750
heading = html.heading('%s %s' % (title.capitalize(), topic))
@@ -2755,7 +2773,7 @@ def html_error(url, exc):
27552773
heading = html.heading('Error')
27562774
contents = '<br>'.join(html.escape(line) for line in
27572775
format_exception_only(type(exc), exc))
2758-
contents = heading + html.bigsection(url, 'error', contents)
2776+
contents = heading + html.bigsection(html.escape(url), 'error', contents)
27592777
return "Error - %s" % url, contents
27602778

27612779
def get_html_page(url):
@@ -2770,8 +2788,11 @@ def get_html_page(url):
27702788
title, content = html_topics()
27712789
elif url == "keywords":
27722790
title, content = html_keywords()
2791+
elif url == "symbols":
2792+
title, content = html_symbols()
27732793
elif '=' in url:
27742794
op, _, url = url.partition('=')
2795+
url = urllib.parse.unquote(url).strip()
27752796
if op == "search?key":
27762797
title, content = html_search(url)
27772798
elif op == "topic?key":

‎Lib/pydoc_data/_pydoc.css‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ section section {
127127
margin: 0.3em 0;
128128
}
129129

130-
pre.topic, pre.keyword {
130+
pre.topic, pre.keyword, pre.symbol {
131131
background-color: var(--block-background-color);
132132
border: 1px solid var(--block-border-color);
133133
border-radius: 3px;

0 commit comments

Comments
 (0)