|
| 1 | +from __future__importannotations |
| 2 | + |
| 3 | +importre |
| 4 | +fromcopyimportcopy |
| 5 | +fromtypingimportTYPE_CHECKING,Any,Callable,Final,Iterable,Iterator,cast |
| 6 | + |
| 7 | +fromsphinx.domainsimportstd |
| 8 | +fromdocutilsimportnodes |
| 9 | +fromdocutils.nodesimportElement,Node,system_message |
| 10 | +fromdocutils.parsers.rstimportDirective,directives |
| 11 | +fromdocutils.statemachineimportStringList |
| 12 | + |
| 13 | +fromsphinximportaddnodes |
| 14 | +fromsphinx.addnodesimportdesc_signature,pending_xref |
| 15 | +fromsphinx.directivesimportObjectDescription |
| 16 | +fromsphinx.domainsimportDomain,ObjType,TitleGetter |
| 17 | +fromsphinx.localeimport_,__ |
| 18 | +fromsphinx.rolesimportEmphasizedLiteral,XRefRole |
| 19 | +fromsphinx.utilimportdocname_join,logging,ws_re |
| 20 | +fromsphinx.util.docutilsimportSphinxDirective |
| 21 | +fromsphinx.util.nodesimportclean_astext,make_id,make_refnode |
| 22 | +fromsphinx.util.typingimportOptionSpec,RoleFunction |
| 23 | + |
| 24 | +ifTYPE_CHECKING: |
| 25 | +fromsphinx.applicationimportSphinx |
| 26 | +fromsphinx.buildersimportBuilder |
| 27 | +fromsphinx.environmentimportBuildEnvironment |
| 28 | + |
| 29 | +logger=logging.getLogger(__name__) |
| 30 | + |
| 31 | + |
| 32 | +classGlossary(SphinxDirective): |
| 33 | +""" |
| 34 | + Directive to create a glossary with cross-reference targets for :term: |
| 35 | + roles. |
| 36 | + """ |
| 37 | + |
| 38 | +has_content=True |
| 39 | +required_arguments=0 |
| 40 | +optional_arguments=0 |
| 41 | +final_argument_whitespace=False |
| 42 | +option_spec:OptionSpec= { |
| 43 | +'sorted':directives.flag, |
| 44 | + } |
| 45 | + |
| 46 | +defrun(self)->list[Node]: |
| 47 | +node=addnodes.glossary() |
| 48 | +node.document=self.state.document |
| 49 | +node['sorted']= ('sorted'inself.options) |
| 50 | + |
| 51 | +# This directive implements a custom format of the reST definition list |
| 52 | +# that allows multiple lines of terms before the definition. This is |
| 53 | +# easy to parse since we know that the contents of the glossary *must |
| 54 | +# be* a definition list. |
| 55 | + |
| 56 | +# first, collect single entries |
| 57 | +entries:list[tuple[list[tuple[str,str,int]],StringList]]= [] |
| 58 | +in_definition=True |
| 59 | +in_comment=False |
| 60 | +was_empty=True |
| 61 | +messages:list[Node]= [] |
| 62 | + |
| 63 | +print('self.content',self.content) |
| 64 | +print('self.content.items',self.content.items) |
| 65 | + |
| 66 | +forline, (source,lineno)inzip(self.content,self.content.items): |
| 67 | +# empty line -> add to last definition |
| 68 | +ifnotline: |
| 69 | +ifin_definitionandentries: |
| 70 | +entries[-1][1].append('',source,lineno) |
| 71 | +was_empty=True |
| 72 | +continue |
| 73 | +# unindented line -> a term |
| 74 | +iflineandnotline[0].isspace(): |
| 75 | +# enable comments |
| 76 | +ifline.startswith('.. term::'): |
| 77 | +print('TERM') |
| 78 | +elifline.startswith('..'): |
| 79 | +in_comment=True |
| 80 | +continue |
| 81 | + |
| 82 | +in_comment=False |
| 83 | + |
| 84 | +# first term of definition |
| 85 | +ifin_definition: |
| 86 | +ifnotwas_empty: |
| 87 | +messages.append(self.state.reporter.warning( |
| 88 | +_('glossary term must be preceded by empty line'), |
| 89 | +source=source,line=lineno)) |
| 90 | +entries.append(([(line,source,lineno)],StringList())) |
| 91 | +in_definition=False |
| 92 | +# second term and following |
| 93 | +else: |
| 94 | +ifwas_empty: |
| 95 | +messages.append(self.state.reporter.warning( |
| 96 | +_('glossary terms must not be separated by empty lines'), |
| 97 | +source=source,line=lineno)) |
| 98 | +ifentries: |
| 99 | +entries[-1][0].append((line,source,lineno)) |
| 100 | +else: |
| 101 | +messages.append(self.state.reporter.warning( |
| 102 | +_('glossary seems to be misformatted, check indentation'), |
| 103 | +source=source,line=lineno)) |
| 104 | +elifin_comment: |
| 105 | +pass |
| 106 | +else: |
| 107 | +ifnotin_definition: |
| 108 | +# first line of definition, determines indentation |
| 109 | +in_definition=True |
| 110 | +indent_len=len(line)-len(line.lstrip()) |
| 111 | +ifentries: |
| 112 | +entries[-1][1].append(line[indent_len:],source,lineno) |
| 113 | +else: |
| 114 | +messages.append(self.state.reporter.warning( |
| 115 | +_('glossary seems to be misformatted, check indentation'), |
| 116 | +source=source,line=lineno)) |
| 117 | +was_empty=False |
| 118 | + |
| 119 | +# now, parse all the entries into a big definition list |
| 120 | +items:list[nodes.definition_list_item]= [] |
| 121 | +forterms,definitioninentries: |
| 122 | +termnodes:list[Node]= [] |
| 123 | +system_messages:list[Node]= [] |
| 124 | +forline,source,linenointerms: |
| 125 | +parts=std.split_term_classifiers(line) |
| 126 | +# parse the term with inline markup |
| 127 | +# classifiers (parts[1:]) will not be shown on doctree |
| 128 | +textnodes,sysmsg=self.state.inline_text(parts[0],lineno) |
| 129 | + |
| 130 | +# use first classifier as a index key |
| 131 | +term=std.make_glossary_term(self.env,textnodes,parts[1],source,lineno, |
| 132 | +node_id=None,document=self.state.document) |
| 133 | +term.rawsource=line |
| 134 | +system_messages.extend(sysmsg) |
| 135 | +termnodes.append(term) |
| 136 | + |
| 137 | +termnodes.extend(system_messages) |
| 138 | + |
| 139 | +defnode=nodes.definition() |
| 140 | +ifdefinition: |
| 141 | +self.state.nested_parse(definition,definition.items[0][1], |
| 142 | +defnode) |
| 143 | +termnodes.append(defnode) |
| 144 | +items.append(nodes.definition_list_item('',*termnodes)) |
| 145 | + |
| 146 | +dlist=nodes.definition_list('',*items) |
| 147 | +dlist['classes'].append('glossary') |
| 148 | +node+=dlist |
| 149 | +returnmessages+ [node] |
| 150 | + |
| 151 | + |
| 152 | +std.StandardDomain.directives['glossary']=Glossary |
| 153 | + |
| 154 | +#!/usr/bin/env python3 |
| 155 | +# -*- coding: utf-8 -*- |
| 156 | +# |
| 157 | +# LVGL documentation build configuration file, created by |
| 158 | +# sphinx-quickstart on Wed Jun 12 16:38:40 2019. |
| 159 | +# |
| 160 | +# This file is execfile()d with the current directory set to its |
| 161 | +# containing dir. |
| 162 | +# |
| 163 | +# Note that not all possible configuration values are present in this |
| 164 | +# autogenerated file. |
| 165 | +# |
| 166 | +# All configuration values have a default; values that are commented out |
| 167 | +# serve to show the default. |
| 168 | + |
| 169 | +# If extensions (or modules to document with autodoc) are in another directory, |
| 170 | +# add these directories to sys.path here. If the directory is relative to the |
| 171 | +# documentation root, use os.path.abspath to make it absolute, like shown here. |
| 172 | +# |
| 173 | +importos |
| 174 | +importsys |
| 175 | + |
| 176 | +fromsphinx.builders.htmlimportStandaloneHTMLBuilder |
| 177 | + |
| 178 | +# -- General configuration ------------------------------------------------ |
| 179 | + |
| 180 | +# If your documentation needs a minimal Sphinx version, state it here. |
| 181 | +# |
| 182 | +# needs_sphinx = '1.0' |
| 183 | + |
| 184 | +# Add any Sphinx extension module names here, as strings. They can be |
| 185 | +# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom |
| 186 | +# ones. |
| 187 | +extensions= [ |
| 188 | +'sphinx_rtd_theme', |
| 189 | +'sphinx.ext.autodoc', |
| 190 | +'sphinx.ext.intersphinx', |
| 191 | +'sphinx.ext.todo', |
| 192 | +'sphinx_sitemap', |
| 193 | +'sphinx_design', |
| 194 | +'sphinx_rtd_dark_mode', |
| 195 | +'hoverxref.extension' |
| 196 | +] |
| 197 | + |
| 198 | +default_dark_mode=True |
| 199 | + |
| 200 | +# Add any paths that contain templates here, relative to this directory. |
| 201 | +templates_path= [] |
| 202 | + |
| 203 | +# The default language to highlight source code in. The default is 'python'. |
| 204 | +# The value should be a valid Pygments lexer name, see Showing code examples for more details. |
| 205 | + |
| 206 | + |
| 207 | +highlight_language='c' |
| 208 | + |
| 209 | +# The suffix(es) of source filenames. |
| 210 | +# You can specify multiple suffix as a list of string: |
| 211 | +# |
| 212 | +source_suffix= {'.rst':'restructuredtext'} |
| 213 | + |
| 214 | + |
| 215 | +# The master toctree document. |
| 216 | +master_doc='index' |
| 217 | + |
| 218 | +# General information about the project. |
| 219 | +project='LVGL' |
| 220 | +copyright='' |
| 221 | +author='' |
| 222 | + |
| 223 | + |
| 224 | +# The version info for the project you're documenting, acts as replacement for |
| 225 | +# |version| and |release|, also used in various other places throughout the |
| 226 | +# built documents. |
| 227 | +# |
| 228 | +# The short X.Y version. |
| 229 | +# `version` is extracted from lv_version.h using a cross-platform compatible |
| 230 | +# Python function in build.py, and passed in on `sphinx-build` command line. |
| 231 | + |
| 232 | +version='' |
| 233 | + |
| 234 | +# The language for content autogenerated by Sphinx. Refer to documentation |
| 235 | +# for a list of supported languages. |
| 236 | +# |
| 237 | +# This is also used if you do content translation via gettext catalogs. |
| 238 | +# Usually you set "language" from the command line for these cases. |
| 239 | +language='en' |
| 240 | + |
| 241 | +# List of patterns, relative to source directory, that match files and |
| 242 | +# directories to ignore when looking for source files. |
| 243 | +# This patterns also effect to html_static_path and html_extra_path |
| 244 | +exclude_patterns= [] |
| 245 | + |
| 246 | +# The name of the Pygments (syntax highlighting) style to use. |
| 247 | +pygments_style='sphinx' |
| 248 | + |
| 249 | +# If true, `todo` and `todoList` produce output, else they produce nothing. |
| 250 | +todo_include_todos=True |
| 251 | + |
| 252 | + |
| 253 | +# -- Options for HTML output ---------------------------------------------- |
| 254 | + |
| 255 | +# The theme to use for HTML and HTML Help pages. See the documentation for |
| 256 | +# a list of builtin themes. |
| 257 | +# |
| 258 | +html_theme='sphinx_rtd_theme' |
| 259 | + |
| 260 | +# Theme options are theme-specific and customize the look and feel of a theme |
| 261 | +# further. For a list of options available for each theme, see the |
| 262 | +# documentation. |
| 263 | +# |
| 264 | + |
| 265 | +# Note: 'display_version' option is now obsolete in the current (08-Oct-2024) |
| 266 | +# version of sphinx-rtd-theme (upgraded for Sphinx v8.x). The removed line is |
| 267 | +# preserved by commenting it out in case it is ever needed again. |
| 268 | + |
| 269 | +html_theme_options= { |
| 270 | +# 'display_version': True, |
| 271 | +'prev_next_buttons_location':'both', |
| 272 | +'style_external_links':False, |
| 273 | +# 'vcs_pageview_mode': '', |
| 274 | +# 'style_nav_header_background': 'white', |
| 275 | +# Toc options |
| 276 | +'sticky_navigation':True, |
| 277 | +'navigation_depth':4, |
| 278 | +'includehidden':True, |
| 279 | +'titles_only':False, |
| 280 | + |
| 281 | +'collapse_navigation':False, |
| 282 | +'logo_only':True, |
| 283 | +} |
| 284 | + |
| 285 | + |
| 286 | +html_baseurl=f"" |
| 287 | + |
| 288 | + |
| 289 | +sitemap_url_scheme="{link}" |
| 290 | + |
| 291 | +#lvgl_github_url = f"https://github.com/lvgl/lvgl/blob/{os.environ['LVGL_GITCOMMIT']}/docs" |
| 292 | + |
| 293 | +#extlinks = {'github_link_base': (github_url + '%s', github_url)} |
| 294 | + |
| 295 | + |
| 296 | +html_context= { |
| 297 | +'conf_py_path':'/docs/' |
| 298 | +} |
| 299 | + |
| 300 | + |
| 301 | +# Add any paths that contain custom static files (such as style sheets) here, |
| 302 | +# relative to this directory. They are copied after the builtin static files, |
| 303 | +# so a file named "default.css" will overwrite the builtin "default.css". |
| 304 | +html_static_path= [] |
| 305 | + |
| 306 | +# Custom sidebar templates, must be a dictionary that maps document names |
| 307 | +# to template names. |
| 308 | +# |
| 309 | +# This is required for the alabaster theme |
| 310 | +# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars |
| 311 | +html_sidebars= { |
| 312 | +'**': [ |
| 313 | +'relations.html',# needs 'show_related': True theme option to display |
| 314 | +'searchbox.html', |
| 315 | + ] |
| 316 | +} |
| 317 | + |
| 318 | +# -- Options for HTMLHelp output ------------------------------------------ |
| 319 | + |
| 320 | +# Output file base name for HTML help builder. |
| 321 | +htmlhelp_basename='LVGLdoc' |
| 322 | + |
| 323 | +html_last_updated_fmt='' |
| 324 | + |
| 325 | +# -- Options for LaTeX output --------------------------------------------- |
| 326 | + |
| 327 | +latex_engine='xelatex' |
| 328 | +latex_use_xindy=False |
| 329 | + |
| 330 | + |
| 331 | +# Grouping the document tree into LaTeX files. List of tuples |
| 332 | +# (source start file, target name, title, |
| 333 | +# author, documentclass [howto, manual, or own class]). |
| 334 | +latex_documents= [ |
| 335 | + (master_doc,'LVGL.tex','LVGL Documentation '+version, |
| 336 | +'LVGL community','manual'), |
| 337 | +] |
| 338 | + |
| 339 | + |
| 340 | +# -- Options for manual page output --------------------------------------- |
| 341 | + |
| 342 | +# One entry per manual page. List of tuples |
| 343 | +# (source start file, name, description, authors, manual section). |
| 344 | +man_pages= [ |
| 345 | + (master_doc,'lvgl','LVGL Documentation '+version, |
| 346 | + [author],1) |
| 347 | +] |
| 348 | + |
| 349 | + |
| 350 | +# -- Options for Texinfo output ------------------------------------------- |
| 351 | + |
| 352 | +# Grouping the document tree into Texinfo files. List of tuples |
| 353 | +# (source start file, target name, title, author, |
| 354 | +# dir menu entry, description, category) |
| 355 | +texinfo_documents= [ |
| 356 | + (master_doc,'LVGL','LVGL Documentation '+version, |
| 357 | +author,'Contributors of LVGL','One line description of project.', |
| 358 | +'Miscellaneous'), |
| 359 | +] |
| 360 | + |
| 361 | +StandaloneHTMLBuilder.supported_image_types= [ |
| 362 | +'image/svg+xml', |
| 363 | +'image/gif',#prefer gif over png |
| 364 | +'image/png', |
| 365 | +'image/jpeg' |
| 366 | +] |
| 367 | + |
| 368 | + |
| 369 | +# Enabling smart quotes action to convert -- to en dashes and --- to em dashes. |
| 370 | +# Converting quotation marks and ellipses is NOT done because the default |
| 371 | +# `smartquotes_action` 'qDe' is changed to just 'D' below, which accomplishes |
| 372 | +# the dash conversions as desired. |
| 373 | +# |
| 374 | +# For list of all possible smartquotes_action values, see: |
| 375 | +# https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-smartquotes_action |
| 376 | +smartquotes=True |
| 377 | +smartquotes_action='D' |
| 378 | + |
| 379 | + |
| 380 | +# Example configuration for intersphinx: refer to the Python standard library. |
| 381 | + |
| 382 | +defsetup(app): |
| 383 | +# app.add_config_value('recommonmark_config', { |
| 384 | +# 'enable_eval_rst': True, |
| 385 | +# 'enable_auto_toc_tree': 'True', |
| 386 | +# }, True) |
| 387 | +# app.add_transform(AutoStructify) |
| 388 | +pass |
| 389 | + |
| 390 | + |