|
1 | 1 | # -*- coding: utf-8 -*- |
2 | 2 |
|
3 | | -from html import escape as html_escape |
4 | 3 | import re |
5 | 4 | from os import getenv, listdir |
6 | 5 | import pickle |
7 | 6 | import importlib |
8 | | -import pkgutil |
9 | 7 |
|
10 | 8 | from mathics import settings |
| 9 | +from html import escape as html_escape |
11 | 10 |
|
12 | 11 | from mathics import builtin |
13 | 12 | from mathics.builtin import get_module_doc |
|
111 | 110 | except IOError: |
112 | 111 | xml_data = {} |
113 | 112 |
|
114 | | -def get_submodule_names(object): |
115 | | - modpkgs = [] |
116 | | - if hasattr(object, '__path__'): |
117 | | - for importer, modname, ispkg in pkgutil.iter_modules(object.__path__): |
118 | | - modpkgs.append(modname) |
119 | | - modpkgs.sort() |
120 | | - return modpkgs |
121 | | - |
122 | | - |
123 | 113 |
|
124 | 114 | def filter_comments(doc): |
125 | 115 | return "\n".join( |
@@ -252,23 +242,15 @@ def repl_list(match): |
252 | 242 | [ |
253 | 243 | ("$", r"\$"), |
254 | 244 | ("\u03c0", r"$\pi$"), |
255 | | - (" ", r"$\ge$"), |
256 | | - (" ", r"$\le$"), |
257 | | - (" ", r"$\ne$"), |
258 | | - |
| 245 | + ("≥", r"$\ge$"), |
| 246 | + ("≤", r"$\le$"), |
| 247 | + ("≠", r"$\ne$"), |
259 | 248 | ("ç", r"\c{c}"), |
260 | 249 | ("é", r"\'e"), |
261 | 250 | ("ê", r"\^e"), |
262 | 251 | ("ñ", r"\~n"), |
263 | 252 | ("∫", r"\int"), |
264 | 253 | ("", r"d"), |
265 | | - # Redo above as something like: |
266 | | - # ("\u00e7", r"\c{c}"), |
267 | | - # ("\u00e9", r"\'e"), |
268 | | - # ("\u00ea", r"\^e"), |
269 | | - # ("\00f1", r"\~n"), |
270 | | - # ("\u222b", r"\int"), |
271 | | - # ("\uf74c", r"d"), |
272 | 254 | ], |
273 | 255 | ) |
274 | 256 |
|
@@ -495,7 +477,6 @@ def post_sub(text, post_substitutions): |
495 | 477 | return text |
496 | 478 |
|
497 | 479 |
|
498 | | -# FIXME: can we replace this with Python 3's html.escape ? |
499 | 480 | def escape_html(text, verbatim_mode=False, counters=None, single_line=False): |
500 | 481 | def repl_python(match): |
501 | 482 | return ( |
@@ -636,7 +617,6 @@ def repl_subsection(match): |
636 | 617 | text = text.replace("\\" + key, xml) |
637 | 618 |
|
638 | 619 | if not single_line: |
639 | | - # FIXME: linebreaks() is not defined |
640 | 620 | # text = linebreaks(text) |
641 | 621 | text = text.replace("<br />", "\n").replace("<br>", "<br />") |
642 | 622 |
|
@@ -677,7 +657,7 @@ def get_prev_next(self): |
677 | 657 | return prev, next |
678 | 658 |
|
679 | 659 | def get_title_html(self): |
680 | | - return escape_html(self.title, single_line=True) |
| 660 | + return html_escape(self.title, single_line=True) |
681 | 661 |
|
682 | 662 |
|
683 | 663 | class Documentation(DocElement): |
@@ -811,36 +791,21 @@ def __init__(self): |
811 | 791 | title, text = get_module_doc(module) |
812 | 792 | chapter = DocChapter(builtin_part, title, Doc(text)) |
813 | 793 | builtins = builtins_by_module[module.__name__] |
814 | | - |
815 | | - if module.__file__.endswith("__init__.py"): |
816 | | - section_names = get_submodule_names(module) |
817 | | - else: |
818 | | - section_names = builtins |
819 | | - |
820 | | - for instance in section_names: |
| 794 | + for instance in builtins: |
821 | 795 | installed = True |
822 | 796 | for package in getattr(instance, "requires", []): |
823 | 797 | try: |
824 | 798 | importlib.import_module(package) |
825 | 799 | except ImportError: |
826 | 800 | installed = False |
827 | 801 | break |
828 | | - if isinstance(instance, str): |
829 | | - section = DocSection( |
830 | | - chapter, |
831 | | - instance, |
832 | | - "", |
833 | | - None, |
834 | | - installed=installed, |
835 | | - ) |
836 | | - else: |
837 | | - section = DocSection( |
838 | | - chapter, |
839 | | - strip_system_prefix(instance.get_name()), |
840 | | - instance.__doc__ or "", |
841 | | - operator=instance.get_operator(), |
842 | | - installed=installed, |
843 | | - ) |
| 802 | + section = DocSection( |
| 803 | + chapter, |
| 804 | + strip_system_prefix(instance.get_name()), |
| 805 | + instance.__doc__ or "", |
| 806 | + operator=instance.get_operator(), |
| 807 | + installed=installed, |
| 808 | + ) |
844 | 809 | chapter.sections.append(section) |
845 | 810 | builtin_part.chapters.append(chapter) |
846 | 811 | self.parts.append(builtin_part) |
@@ -1205,7 +1170,7 @@ def latex(self, output): |
1205 | 1170 |
|
1206 | 1171 | def html(self): |
1207 | 1172 | counters = {} |
1208 | | - return html_escape( |
| 1173 | + return escape_html( |
1209 | 1174 | "\n".join( |
1210 | 1175 | item.html(counters) for item in self.items if not item.is_private() |
1211 | 1176 | ) |
|
0 commit comments