1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
|
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# http://www.sphinx-doc.org/en/master/config
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#
# import os
# import sys
# sys.path.insert(0, os.path.abspath('.'))
# -- Project information -----------------------------------------------------
project = 'Tui Widgets'
copyright = '2022, Martin Hostettler'
author = 'Martin Hostettler'
# The full version, including alpha/beta/rc tags
release = '0.3.0'
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
# 'sphinxcontrib.images',
'sphinx.ext.intersphinx',
]
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
cpp_index_common_prefix = ['Tui::']
highlight_language = 'c++'
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
html_theme = 'alabaster'
html_theme_options = {
'show_relbar_bottom': True,
'show_relbar_top': False,
'page_width': '1340px',
'sidebar_width': '190px',
'github_user': 'tuiwidgets',
'github_repo': 'tuiwidgets',
'github_banner': True,
'github_button': False,
'body_max_width': 950,
}
html_show_copyright = False
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
manpages_url = "https://man7.org/linux/man-pages/man{section}/{page}.{section}.html"
intersphinx_mapping = {'qt': ('https://doc.qt.io/qt-5', 'qt5.inv'),
'termpaint': ('https://termpaint.namepad.de/latest/', '/usr/share/doc/libtermpaint-dev/html/objects.inv')}
section_pages_titles = ['Widgets', 'Misc']
#cpp_debug_lookup = True
#cpp_debug_show_tree = True
from sphinx.util.docutils import SphinxDirective
from sphinx.transforms import SphinxTransform
import sphinx.addnodes
from docutils import nodes
import os, sys
x = os.path.abspath(os.path.dirname(__file__))
#print(f"Path {x}")
sys.path.append(x)
from custom import *
class AdhocDef(SphinxDirective):
has_content = True
required_arguments = 1
final_argument_whitespace = True
def run(self):
node = sphinx.addnodes.desc()
sig = sphinx.addnodes.desc_signature()
sig += nodes.Text(self.arguments[0])
node.append(sig)
contentnode = sphinx.addnodes.desc_content()
node.append(contentnode)
self.state.nested_parse(self.content, self.content_offset, contentnode)
return [node]
class CollapsableDef(SphinxDirective):
has_content = True
required_arguments = 1
final_argument_whitespace = True
def run(self):
node = collapsable()
node.summary = self.arguments[0]
self.state.nested_parse(self.content, self.content_offset, node)
return [node]
from sphinx.util.osutil import ensuredir
import subprocess
import hashlib
class TpiConverter(SphinxTransform):
default_priority = 10
def apply(self, **kwargs) -> None:
for node in self.document.findall(nodes.image):
if node['uri'].endswith('.tpi'):
srcpath = node['uri']
self.app.env.note_dependency(srcpath)
with open(srcpath, 'rb') as f:
contenthash = hashlib.sha256(f.read()).hexdigest()[:10]
filename = os.path.basename(srcpath) + '.' + contenthash + '.png'
imagedir = os.path.join(self.app.doctreedir, '_image_tmp')
ensuredir(imagedir)
destpath = os.path.join(imagedir, filename)
subprocess.run([x + '/tpi2png.py', srcpath, destpath])
source = os.path.dirname(self.document["source"])
destpath = os.path.relpath(destpath, source)
node['uri'] = destpath
from bs4 import BeautifulSoup
def fixup_sidebar_toc(html):
soup = BeautifulSoup(html, "html.parser")
core_section_point = None
core_open = False
seen_real_section = False
for element in soup.ul.children:
if element.name == 'li':
if len(element.contents) > 0 and element.contents[0].name == 'a' and element.contents[0].text in section_pages_titles:
seen_real_section = True
element['class'] += ['tw-subsection']
else:
# otherwise enforce maxdepth = 2
for sub_ul in element.select('ul ul ul'):
sub_ul.decompose()
if len(element.contents) > 0 and element.contents[0].name == 'a' and element.contents[0].text == 'ZTerminal':
core_section_point = element
if not seen_real_section and 'current' in element['class']:
core_open = True
pseudo_section = False
for element in soup.ul.children:
if element.name == 'li':
if element is core_section_point:
pseudo_section = True
if 'tw-subsection' in element['class']:
pseudo_section = False
if pseudo_section:
if core_open:
element['class'] += ['tw-pseudosection-item']
else:
element['class'] += ['tw-pseudosection-hidden']
if core_section_point:
new_li = soup.new_tag('li')
new_li['class'] = ['toctree-l1', 'tw-subsection']
if core_open:
new_li['class'] += ['tw-pseudosection-open']
new_a = soup.new_tag('a')
new_a['class'] = ['reference', 'internal']
new_a['href'] = core_section_point.contents[0]['href']
new_a.string = 'Core'
new_li.append(new_a)
core_section_point.insert_before(new_li)
return str(soup)
def html_page_context(app, pagename, templatename, context, doctree):
orig_toctree = context['toctree']
context['toctree'] = lambda **kwargs: fixup_sidebar_toc(orig_toctree(**kwargs))
def setup(app):
app.add_directive('adhoc-def', AdhocDef)
app.add_directive('collapsable', CollapsableDef)
app.add_role('colorchip', colorchip_role)
app.add_node(colorchip, html=(visit_colorchip, depart_colorchip))
app.add_node(collapsable, html=(visit_collapsable, depart_collapsable))
app.add_transform(TpiConverter)
app.connect('html-page-context', html_page_context)
|