11# Copyright Spack Project Developers. See COPYRIGHT file for details.
22#
33# SPDX-License-Identifier: (Apache-2.0 OR MIT)
4-
54# flake8: noqa
65# -*- coding: utf-8 -*-
76#
1514#
1615# All configuration values have a default; values that are commented out
1716# serve to show the default.
18- import sys
19- import os
2017
21- from sphinx .domains .python import PythonDomain
18+ import os
19+ import sys
2220
21+ from pygments .formatters .html import HtmlFormatter
2322from pygments .lexer import RegexLexer , default
2423from pygments .token import *
25-
24+ from sphinx .domains .python import PythonDomain
25+ from sphinx .highlighting import PygmentsBridge
2626
2727# -- Spack customizations -----------------------------------------------------
2828# Add the Spack bin directory to the path so that we can use its output in docs.
3535
3636sys .path .insert (0 , os .path .abspath ("_spack_root/lib/spack/" ))
3737
38+
39+ class NoWhitespaceHtmlFormatter (HtmlFormatter ):
40+ """HTML formatter that suppresses redundant span elements for Text.Whitespace tokens."""
41+
42+ def _get_css_classes (self , ttype ):
43+ # For Text.Whitespace return an empty string, which avoids <span class="w"> </span>
44+ # elements from being generated.
45+ return "" if ttype is Text .Whitespace else super ()._get_css_classes (ttype )
46+
47+
48+ class CustomPygmentsBridge (PygmentsBridge ):
49+ def get_formatter (self , ** options ):
50+ return NoWhitespaceHtmlFormatter (** options )
51+
52+
53+ # Use custom HTML formatter to avoid redundant <span class="w"> </span> elements.
54+ # See https://github.com/pygments/pygments/issues/1905#issuecomment-3170486995.
55+ PygmentsBridge .html_formatter = NoWhitespaceHtmlFormatter
56+
3857# Enable todo items
3958todo_include_todos = True
4059
@@ -112,12 +131,10 @@ class SpecLexer(RegexLexer):
112131# Disable duplicate cross-reference warnings.
113132#
114133class PatchedPythonDomain (PythonDomain ):
115- def resolve_xref (self , env , fromdocname , builder , typ , target , node , contnode ):
134+ def resolve_xref (self , env , fromdocname , builder , type , target , node , contnode ):
116135 if "refspecific" in node :
117136 del node ["refspecific" ]
118- return super (PatchedPythonDomain , self ).resolve_xref (
119- env , fromdocname , builder , typ , target , node , contnode
120- )
137+ return super ().resolve_xref (env , fromdocname , builder , type , target , node , contnode )
121138
122139
123140def setup (sphinx ):
@@ -127,14 +144,16 @@ def setup(sphinx):
127144
128145# -- General configuration -----------------------------------------------------
129146# If your documentation needs a minimal Sphinx version, state it here.
130- needs_sphinx = "1.8 "
147+ needs_sphinx = "3.4 "
131148
132149# Add any Sphinx extension module names here, as strings. They can be extensions
133150# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
134151extensions = [
135152 "sphinx.ext.graphviz" ,
136153 "sphinx.ext.todo" ,
137154 "sphinx_copybutton" ,
155+ "sphinx_last_updated_by_git" ,
156+ "sphinx_sitemap" ,
138157]
139158
140159# Set default graphviz options
@@ -287,7 +306,7 @@ def setup(sphinx):
287306# html_show_sourcelink = True
288307
289308# If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
290- # html_show_sphinx = False
309+ html_show_sphinx = False
291310
292311# If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
293312# html_show_copyright = True
@@ -300,19 +319,27 @@ def setup(sphinx):
300319# This is the file name suffix for HTML files (e.g. ".xhtml").
301320# html_file_suffix = None
302321
322+ # Base URL for the documentation, used to generate <link rel="canonical"/> for better indexing
323+ html_baseurl = "https://spack-tutorial.readthedocs.io/en/latest/"
324+
303325# Output file base name for HTML help builder.
304326htmlhelp_basename = "Spackdoc"
305327
328+ # Sitemap settings
329+ sitemap_show_lastmod = True
330+ sitemap_url_scheme = "{link}"
331+ sitemap_excludes = ["search.html" ]
332+
306333
307334# -- Options for LaTeX output --------------------------------------------------
308335
309336latex_elements = {
310337 # The paper size ('letterpaper' or 'a4paper').
311- #'papersize': 'letterpaper',
338+ # 'papersize': 'letterpaper',
312339 # The font size ('10pt', '11pt' or '12pt').
313- #'pointsize': '10pt',
340+ # 'pointsize': '10pt',
314341 # Additional stuff for the LaTeX preamble.
315- #'preamble': '',
342+ # 'preamble': '',
316343}
317344
318345# Grouping the document tree into LaTeX files. List of tuples
0 commit comments