Skip to content

Commit 64c698b

Browse files
committed
Code to start folding in built-in subdirs
Not complete, but it is a start.
1 parent b39e27c commit 64c698b

File tree

2 files changed

+39
-12
lines changed

2 files changed

+39
-12
lines changed

mathics/builtin/lists.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,7 @@ def apply_pattern(self, items, sel, pattern, evaluation):
19691969

19701970

19711971
class Cases(Builtin):
1972-
"""
1972+
r"""
19731973
<dl>
19741974
<dt>'Cases[$list$, $pattern$]'
19751975
<dd>returns the elements of $list$ that match $pattern$.

mathics/doc/doc.py

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
# -*- coding: utf-8 -*-
22

3+
from html import escape as html_escape
34
import re
45
from os import getenv, listdir
56
import pickle
67
import importlib
8+
import pkgutil
79

810
from mathics import settings
9-
from html import escape as html_escape
1011

1112
from mathics import builtin
1213
from mathics.builtin import get_module_doc
@@ -110,6 +111,15 @@
110111
except IOError:
111112
xml_data = {}
112113

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+
113123

114124
def filter_comments(doc):
115125
return "\n".join(
@@ -477,6 +487,7 @@ def post_sub(text, post_substitutions):
477487
return text
478488

479489

490+
# FIXME: can we replace this with Python 3's html.escape ?
480491
def escape_html(text, verbatim_mode=False, counters=None, single_line=False):
481492
def repl_python(match):
482493
return (
@@ -617,6 +628,7 @@ def repl_subsection(match):
617628
text = text.replace("\\" + key, xml)
618629

619630
if not single_line:
631+
# FIXME: linebreaks() is not defined
620632
# text = linebreaks(text)
621633
text = text.replace("<br />", "\n").replace("<br>", "<br />")
622634

@@ -657,7 +669,7 @@ def get_prev_next(self):
657669
return prev, next
658670

659671
def get_title_html(self):
660-
return html_escape(self.title, single_line=True)
672+
return escape_html(self.title, single_line=True)
661673

662674

663675
class Documentation(DocElement):
@@ -791,21 +803,36 @@ def __init__(self):
791803
title, text = get_module_doc(module)
792804
chapter = DocChapter(builtin_part, title, Doc(text))
793805
builtins = builtins_by_module[module.__name__]
794-
for instance in builtins:
806+
807+
if module.__file__.endswith("__init__.py"):
808+
section_names = get_submodule_names(module)
809+
else:
810+
section_names = builtins
811+
812+
for instance in section_names:
795813
installed = True
796814
for package in getattr(instance, "requires", []):
797815
try:
798816
importlib.import_module(package)
799817
except ImportError:
800818
installed = False
801819
break
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-
)
820+
if isinstance(instance, str):
821+
section = DocSection(
822+
chapter,
823+
instance,
824+
"",
825+
None,
826+
installed=installed,
827+
)
828+
else:
829+
section = DocSection(
830+
chapter,
831+
strip_system_prefix(instance.get_name()),
832+
instance.__doc__ or "",
833+
operator=instance.get_operator(),
834+
installed=installed,
835+
)
809836
chapter.sections.append(section)
810837
builtin_part.chapters.append(chapter)
811838
self.parts.append(builtin_part)
@@ -1170,7 +1197,7 @@ def latex(self, output):
11701197

11711198
def html(self):
11721199
counters = {}
1173-
return escape_html(
1200+
return html_escape(
11741201
"\n".join(
11751202
item.html(counters) for item in self.items if not item.is_private()
11761203
)

0 commit comments

Comments
 (0)