Disable all custom code in theme
This commit is contained in:
@@ -27,53 +27,11 @@ def setup_edit_url(app, pagename, templatename, context, doctree):
|
||||
def get_edit_url():
|
||||
"""Return a URL for an "edit this page" link."""
|
||||
doc_context = dict()
|
||||
doc_context.update(**context)
|
||||
|
||||
# Make sure that doc_path has a path separator only if it exists (to avoid //)
|
||||
doc_path = doc_context.get("doc_path", "")
|
||||
if doc_path and not doc_path.endswith("/"):
|
||||
doc_path = f"{doc_path}/"
|
||||
|
||||
# ensure custom URL is checked first, if given
|
||||
url_template = doc_context.get("edit_page_url_template")
|
||||
|
||||
if url_template is not None:
|
||||
if "file_name" not in url_template:
|
||||
raise ExtensionError(
|
||||
"Missing required value for `use_edit_page_button`. "
|
||||
"Ensure `file_name` appears in `edit_page_url_template`: "
|
||||
f"{url_template}"
|
||||
)
|
||||
return jinja2.Template(url_template).render(**doc_context)
|
||||
|
||||
url_template = '{{ github_url }}/{{ github_user }}/{{ github_repo }}' \
|
||||
'/edit/{{ github_version }}/{{ doc_path }}{{ file_name }}'
|
||||
|
||||
doxygen_mapping_file = app.config.html_context.get('doxygen_mapping_file')
|
||||
rst_name = pagename.rsplit('-')[0]
|
||||
file_name = doxygen_mapping_file[rst_name]
|
||||
parent_folder = Path(os.path.dirname(file_name)).parts[0]
|
||||
file_name = Path(*Path(file_name).parts[1:]).as_posix()
|
||||
|
||||
doc_context.update(doc_path=doc_path, file_name=file_name)
|
||||
try:
|
||||
repositories = app.config.repositories
|
||||
except AttributeError:
|
||||
raise ExtensionError("Missing required value for `use_edit_page_button`. "
|
||||
"Ensure `repositories` is set in conf.py.")
|
||||
|
||||
required = ['github_user', 'github_repo', 'github_version', 'host_url']
|
||||
for repo, config in repositories.items():
|
||||
for key, val in config.items():
|
||||
if key not in required or not val:
|
||||
raise ExtensionError(f'Missing required value for `{repo}` entry in `repositories`'
|
||||
f'Ensure {required} all set.')
|
||||
if parent_folder == repo:
|
||||
doc_context.update(github_user=config['github_user'])
|
||||
doc_context.update(github_repo=config['github_repo'])
|
||||
doc_context.update(github_version=config['github_version'])
|
||||
doc_context.update(github_url=config['host_url'])
|
||||
return jinja2.Template(url_template).render(**doc_context)
|
||||
return jinja2.Template(url_template).render(**doc_context)
|
||||
|
||||
context["get_edit_url"] = get_edit_url
|
||||
context['has_github_page'] = has_github_page()
|
||||
@@ -86,52 +44,6 @@ def get_theme_path():
|
||||
theme_path = os.path.abspath(os.path.dirname(__file__))
|
||||
return theme_path
|
||||
|
||||
|
||||
# override pydata_sphinx_theme
|
||||
def _add_collapse_checkboxes(soup, open_first=False):
|
||||
# based on https://github.com/pradyunsg/furo
|
||||
|
||||
toctree_checkbox_count = 0
|
||||
|
||||
for element in soup.find_all("li", recursive=True):
|
||||
# We check all "li" elements, to add a "current-page" to the correct li.
|
||||
classes = element.get("class", [])
|
||||
|
||||
# Nothing more to do, unless this has "children"
|
||||
if not element.find("ul"):
|
||||
continue
|
||||
|
||||
# Add a class to indicate that this has children.
|
||||
element["class"] = classes + ["has-children"]
|
||||
|
||||
# We're gonna add a checkbox.
|
||||
toctree_checkbox_count += 1
|
||||
checkbox_name = f"toctree-checkbox-{toctree_checkbox_count}"
|
||||
|
||||
# Add the "label" for the checkbox which will get filled.
|
||||
if soup.new_tag is None:
|
||||
continue
|
||||
label = soup.new_tag("label", attrs={"for": checkbox_name})
|
||||
label.append(soup.new_tag("i", attrs={"class": "fas fa-chevron-down"}))
|
||||
element.insert(1, label)
|
||||
|
||||
# Add the checkbox that's used to store expanded/collapsed state.
|
||||
checkbox = soup.new_tag(
|
||||
"input",
|
||||
attrs={
|
||||
"type": "checkbox",
|
||||
"class": ["toctree-checkbox"],
|
||||
"id": checkbox_name,
|
||||
"name": checkbox_name,
|
||||
},
|
||||
)
|
||||
# if this has a "current" class, be expanded by default
|
||||
# (by checking the checkbox)
|
||||
if "current" in classes or (open_first and toctree_checkbox_count == 1):
|
||||
checkbox.attrs["checked"] = ""
|
||||
element.insert(1, checkbox)
|
||||
|
||||
|
||||
def add_toctree_functions(app, pagename, templatename, context, doctree):
|
||||
|
||||
# override pydata_sphinx_theme
|
||||
@@ -160,66 +72,13 @@ def add_toctree_functions(app, pagename, templatename, context, doctree):
|
||||
or BeautifulSoup object (if kind == "raw")
|
||||
"""
|
||||
|
||||
open_first = False
|
||||
if 'open_first' in kwargs:
|
||||
open_first = kwargs.pop('open_first')
|
||||
|
||||
if startdepth is None:
|
||||
startdepth = 1 if kind == "sidebar" else 0
|
||||
|
||||
if startdepth == 0:
|
||||
toc_sphinx = context["toctree"](**kwargs)
|
||||
else:
|
||||
# select the "active" subset of the navigation tree for the sidebar
|
||||
toc_sphinx = index_toctree(app, pagename, startdepth, **kwargs)
|
||||
|
||||
soup = bs(toc_sphinx, "html.parser")
|
||||
|
||||
# pair "current" with "active" since that's what we use w/ bootstrap
|
||||
for li in soup("li", {"class": "current"}):
|
||||
li["class"].append("active")
|
||||
|
||||
# Remove navbar/sidebar links to sub-headers on the page
|
||||
for li in soup.select("li"):
|
||||
# Remove
|
||||
if li.find("a"):
|
||||
href = li.find("a")["href"]
|
||||
if "#" in href and href != "#":
|
||||
li.decompose()
|
||||
|
||||
if kind == "navbar":
|
||||
# Add CSS for bootstrap
|
||||
for li in soup("li"):
|
||||
li["class"].append("nav-item")
|
||||
li.find("a")["class"].append("nav-link")
|
||||
# only select li items (not eg captions)
|
||||
out = "\n".join([ii.prettify() for ii in soup.find_all("li")])
|
||||
|
||||
elif kind == "sidebar":
|
||||
# Add bootstrap classes for first `ul` items
|
||||
for ul in soup("ul", recursive=False):
|
||||
ul.attrs["class"] = ul.attrs.get("class", []) + ["nav", "bd-sidenav"]
|
||||
|
||||
# Add icons and labels for collapsible nested sections
|
||||
_add_collapse_checkboxes(soup, open_first=open_first)
|
||||
|
||||
out = soup.prettify()
|
||||
|
||||
elif kind == "raw":
|
||||
out = soup
|
||||
|
||||
return out
|
||||
return ''
|
||||
|
||||
context["generate_sidebar_nav"] = generate_sidebar_nav
|
||||
|
||||
|
||||
def read_doxygen_configs(app, env, docnames):
|
||||
if app.config.html_context.get('doxygen_mapping_file'):
|
||||
try:
|
||||
with open(app.config.html_context.get('doxygen_mapping_file'), 'r', encoding='utf-8') as f:
|
||||
app.config.html_context['doxygen_mapping_file'] = json.load(f)
|
||||
except (JSONDecodeError, FileNotFoundError):
|
||||
app.config.html_context['doxygen_mapping_file'] = dict()
|
||||
app.config.html_context['doxygen_mapping_file'] = dict()
|
||||
|
||||
|
||||
def setup(app):
|
||||
|
||||
@@ -16,61 +16,4 @@ class DoxygenSnippet(LiteralInclude):
|
||||
option_spec = dict({'fragment': directives.unchanged_required}, **LiteralInclude.option_spec)
|
||||
|
||||
def run(self) -> List[Node]:
|
||||
if 'fragment' in self.options:
|
||||
self.options['start-after'] = self.options['fragment']
|
||||
self.options['end-before'] = self.options['fragment']
|
||||
document = self.state.document
|
||||
if not document.settings.file_insertion_enabled:
|
||||
return [document.reporter.warning('File insertion disabled',
|
||||
line=self.lineno)]
|
||||
# convert options['diff'] to absolute path
|
||||
if 'diff' in self.options:
|
||||
_, path = self.env.relfn2path(self.options['diff'])
|
||||
self.options['diff'] = path
|
||||
|
||||
try:
|
||||
location = self.state_machine.get_source_and_line(self.lineno)
|
||||
doxygen_snippet_root = self.config.html_context.get('doxygen_snippet_root')
|
||||
|
||||
if doxygen_snippet_root and os.path.exists(doxygen_snippet_root):
|
||||
rel_filename = self.arguments[0]
|
||||
filename = os.path.join(doxygen_snippet_root, rel_filename)
|
||||
else:
|
||||
rel_filename, filename = self.env.relfn2path(self.arguments[0])
|
||||
self.env.note_dependency(rel_filename)
|
||||
|
||||
reader = LiteralIncludeReader(filename, self.options, self.config)
|
||||
text, lines = reader.read(location=location)
|
||||
|
||||
retnode = nodes.literal_block(text, text, source=filename) # type: Element
|
||||
retnode['force'] = 'force' in self.options
|
||||
self.set_source_info(retnode)
|
||||
if self.options.get('diff'): # if diff is set, set udiff
|
||||
retnode['language'] = 'udiff'
|
||||
elif 'language' in self.options:
|
||||
retnode['language'] = self.options['language']
|
||||
if ('linenos' in self.options or 'lineno-start' in self.options or
|
||||
'lineno-match' in self.options):
|
||||
retnode['linenos'] = True
|
||||
retnode['classes'] += self.options.get('class', [])
|
||||
extra_args = retnode['highlight_args'] = {}
|
||||
if 'emphasize-lines' in self.options:
|
||||
hl_lines = parselinenos(self.options['emphasize-lines'], lines)
|
||||
if any(i >= lines for i in hl_lines):
|
||||
logger.warning(__('line number spec is out of range(1-%d): %r') %
|
||||
(lines, self.options['emphasize-lines']),
|
||||
location=location)
|
||||
extra_args['hl_lines'] = [x + 1 for x in hl_lines if x < lines]
|
||||
extra_args['linenostart'] = reader.lineno_start
|
||||
|
||||
if 'caption' in self.options:
|
||||
caption = self.options['caption'] or self.arguments[0]
|
||||
retnode = container_wrapper(self, retnode, caption)
|
||||
|
||||
# retnode will be note_implicit_target that is linked from caption and numref.
|
||||
# when options['name'] is provided, it should be primary ID.
|
||||
self.add_name(retnode)
|
||||
|
||||
return [retnode]
|
||||
except Exception as exc:
|
||||
return [document.reporter.warning(exc, line=self.lineno)]
|
||||
return []
|
||||
|
||||
Reference in New Issue
Block a user