additional_samples_with_very_long_name
Various examples of styling applied to Sphinx constructs. You can view the source of this page to see the specific reStructuredText used to create these examples.
Headings
This is a second level heading (h2).
Sub-Heading
This is a third level heading (h3).
Sub-Sub-Heading
This is a fourth level heading (h4).
Code
The theme uses pygments for inline code text and
multiline
code text
Here’s an included example with line numbers.
1"""MDAnalysis Sphinx theme."""
2
3import os
4import pathlib
5
6import sass
7from sass import SassColor
8from sphinx.util import console
9
10from ._version import get_versions
11
12__version__ = get_versions()["version"]
13del get_versions
14
15
16def setup(app):
17 """Setup connects events to the sitemap builder"""
18 app.connect("build-finished", compile_css)
19
20 app.site_pages = []
21 app.add_html_theme(
22 "mdanalysis_sphinx_theme", html_theme_path()[0]
23 )
24 return {
25 "version": __version__,
26 "parallel_read_safe": True,
27 "parallel_write_safe": True,
28 }
29
30
31def compile_css(app, exception):
32 """Compile Bulma SASS into CSS"""
33 if exception is not None:
34 return
35
36 theme_path = pathlib.Path(html_theme_path()[0])
37 src = theme_path / "sass/site.sass"
38 dest = pathlib.Path(app.outdir) / "_static/site.css"
39
40 if not dest.parent.exists():
41 return
42
43 accent_color = app.config["html_theme_options"].get(
44 "color_accent", "mdanalysis-orange"
45 )
46 accent_color = {
47 "mdanalysis-orange": (255, 146, 0),
48 }.get(accent_color, accent_color)
49
50 if app.config["html_theme_options"].get("css_minify", False):
51 output_style = "compressed"
52 source_comments = False
53 else:
54 output_style = "expanded"
55 source_comments = True
56
57 css = sass.compile(
58 filename=str(src),
59 output_style=output_style,
60 custom_functions={
61 "accent_color": lambda: SassColor(*accent_color, 1),
62 "hyphenate": lambda: app.config["html_theme_options"].get(
63 "html_hyphenate_and_justify", False
64 ),
65 },
66 )
67
68 print(f"Writing compiled SASS to {console.colorize('blue', str(dest))}")
69
70 with open(dest, "w") as f:
71 print(css, file=f)
72
73
74def html_theme_path():
75 return [os.path.dirname(os.path.abspath(__file__))]
76
It also works with existing Sphinx highlighting:
<html>
<body>Hello World</body>
</html>
def hello():
"""Greet."""
return "Hello World"
/**
* Greet.
*/
function hello(): {
return "Hello World";
}
Admonitions
The theme uses the admonition classes for the standard Sphinx admonitions.
Warning
Warning
This is a warning.
Attention
Attention
Do I have your attention?
Caution
Caution
Use caution!
Danger
Danger
This is danger-ous.
Error
Error
You have made a grave error.
Hint
Hint
Can you take a hint?
Important
Important
It is important to correctly use admonitions.
Note
Note
This is a note.
Tip
Tip
Please tip your waiter.
Deprecated
Deprecated since version 999.999.999: This API point was deprecated.
Todo
Todo
This is something we are yet to do.
Custom Admonitions
An admonition of my own making
You can create your own admonitions with the accent color.
Example
But lots of custom admonition styles are also defined.
Quote
The needs of the many outweigh the needs of the few
Bug
Bugs weren’t always a metaphor
Success
Woohoo!
Experimental
Experiments are the heart of science
Footnotes
I have footnoted a first item [1] and second item [2]. This also references the second item [2].
Footnotes
Icons
Font Awesome and Academicons are both available:
<i class="fa fa-camera-retro fa-lg"></i>
<i class="fa fa-camera-retro fa-2x"></i>
<i class="fa fa-camera-retro fa-3x"></i>
<i class="fa fa-camera-retro fa-4x"></i>
<i class="fa fa-camera-retro fa-5x"></i>
<i class="ai ai-google-scholar-square ai-3x"></i>
<i class="ai ai-zenodo ai-3x" style="color: red"></i>
Tables
Here are some examples of Sphinx tables.
Grid
A grid table:
Header1 |
Header2 |
Header3 |
Header4 |
|---|---|---|---|
row1, cell1 |
cell2 |
cell3 |
cell4 |
row2 … |
… |
… |
|
… |
… |
… |
Simple
A simple table:
H1 |
H2 |
H3 |
|---|---|---|
cell1 |
cell2 |
cell3 |
… |
… |
… |
… |
… |
… |
List Tables
Column 1 |
Column 2 |
|---|---|
Item 1 |
Item 2 |
One fifth width column |
Four fifths width column |
|---|---|
Item 1 |
Item 2 |
Alignment
Column 1 |
Column 2 |
|---|---|
Item 1 |
Item 2 |
Column 1 |
Column 2 |
|---|---|
Item 1 |
Item 2 |
Treat |
Quantity |
|---|---|
Albatross |
2.99 |
Crunchy Frog |
1.49 |
Gannet Ripple |
1.99 |
Code Documentation
An example Python function.
- format_exception(etype, value, tb[, limit=None])
Format the exception with a traceback.
- Parameters:
etype – exception type
value – exception value
tb – traceback object
limit (integer or None) – maximum number of stack frames to show
- Return type:
list of strings
An example JavaScript function.
- class MyAnimal(name[, age])
- Arguments:
name (
string()) – The name of the animalage (
number()) – an optional age for the animal
Glossaries
- environment
A structure where information about all documents under the root is saved, and used for cross-referencing. The environment is pickled after the parsing stage, so that successive runs only need to read and parse new and changed documents.
- source directory
The directory which, including its subdirectories, contains all source files for one Sphinx project.
Math
Production Lists
try_stmt ::= try1_stmt | try2_stmt try1_stmt ::= "try" ":"suite("except" [expression[","target]] ":"suite)+ ["else" ":"suite] ["finally" ":"suite] try2_stmt ::= "try" ":"suite"finally" ":"suite