Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
aws
GitHub Repository: aws/aws-cli
Path: blob/develop/doc/source/guzzle_sphinx_theme/__init__.py
1567 views
1
"""Sphinx Guzzle theme."""
2
3
import os
4
import xml.etree.ElementTree as ET
5
6
from docutils import nodes
7
from sphinx.locale import admonitionlabels
8
from sphinx.writers.html import HTMLTranslator as SphinxHTMLTranslator
9
10
from pygments.style import Style
11
from pygments.token import Keyword, Name, Comment, String, Error, \
12
Number, Operator, Generic, Whitespace, Punctuation, Other, Literal
13
14
15
def setup(app):
16
"""Setup connects events to the sitemap builder"""
17
app.connect('html-page-context', add_html_link)
18
app.connect('build-finished', create_sitemap)
19
app.sitemap_links = []
20
app.set_translator('html', HTMLTranslator)
21
22
23
def add_html_link(app, pagename, templatename, context, doctree):
24
"""As each page is built, collect page names for the sitemap"""
25
base_url = app.config['html_theme_options'].get('base_url', '')
26
if base_url:
27
app.sitemap_links.append(base_url + pagename + ".html")
28
29
30
def create_sitemap(app, exception):
31
"""Generates the sitemap.xml from the collected HTML page links"""
32
if (not app.config['html_theme_options'].get('base_url', '') or
33
exception is not None or
34
not app.sitemap_links):
35
return
36
37
filename = app.outdir + "/sitemap.xml"
38
print("Generating sitemap.xml in %s" % filename)
39
40
root = ET.Element("urlset")
41
root.set("xmlns", "http://www.sitemaps.org/schemas/sitemap/0.9")
42
43
for link in app.sitemap_links:
44
url = ET.SubElement(root, "url")
45
ET.SubElement(url, "loc").text = link
46
47
ET.ElementTree(root).write(filename)
48
49
50
def html_theme_path():
51
return [os.path.dirname(os.path.abspath(__file__))]
52
53
54
class HTMLTranslator(SphinxHTMLTranslator):
55
def visit_admonition(self, node, name=''):
56
"""Uses the h3 tag for admonition titles instead of the p tag"""
57
self.body.append(self.starttag(
58
node, 'div', CLASS=('admonition ' + name)))
59
if name:
60
title = (
61
f"<h3 class='admonition-title'>"
62
f"{admonitionlabels[name]}</h3>"
63
)
64
self.body.append(title)
65
self.set_first_last(node)
66
67
68
class GuzzleStyle(Style):
69
background_color = "#f8f8f8"
70
default_style = ""
71
72
styles = {
73
# No corresponding class for the following:
74
#Text: "", # class: ''
75
Whitespace: "underline #f8f8f8", # class: 'w'
76
Error: "#a40000 border:#ef2929", # class: 'err'
77
Other: "#000000", # class 'x'
78
79
Comment: "italic #8f5902", # class: 'c'
80
Comment.Preproc: "noitalic", # class: 'cp'
81
82
Keyword: "bold #004461", # class: 'k'
83
Keyword.Constant: "bold #004461", # class: 'kc'
84
Keyword.Declaration: "bold #004461", # class: 'kd'
85
Keyword.Namespace: "bold #004461", # class: 'kn'
86
Keyword.Pseudo: "bold #004461", # class: 'kp'
87
Keyword.Reserved: "bold #004461", # class: 'kr'
88
Keyword.Type: "bold #004461", # class: 'kt'
89
90
Operator: "#582800", # class: 'o'
91
Operator.Word: "bold #004461", # class: 'ow' - like keywords
92
93
Punctuation: "bold #000000", # class: 'p'
94
95
# because special names such as Name.Class, Name.Function, etc.
96
# are not recognized as such later in the parsing, we choose them
97
# to look the same as ordinary variables.
98
Name: "#000000", # class: 'n'
99
Name.Attribute: "#006EC4", # class: 'na' - to be revised
100
Name.Builtin: "#004461", # class: 'nb'
101
Name.Builtin.Pseudo: "#3465a4", # class: 'bp'
102
Name.Class: "#000000", # class: 'nc' - to be revised
103
Name.Constant: "#000000", # class: 'no' - to be revised
104
Name.Decorator: "#888", # class: 'nd' - to be revised
105
Name.Entity: "#ce5c00", # class: 'ni'
106
Name.Exception: "bold #cc0000", # class: 'ne'
107
Name.Function: "#000000", # class: 'nf'
108
Name.Property: "#000000", # class: 'py'
109
Name.Label: "#f57900", # class: 'nl'
110
Name.Namespace: "#000000", # class: 'nn' - to be revised
111
Name.Other: "#000000", # class: 'nx'
112
Name.Tag: "bold #004461", # class: 'nt' - like a keyword
113
Name.Variable: "#000000", # class: 'nv' - to be revised
114
Name.Variable.Class: "#000000", # class: 'vc' - to be revised
115
Name.Variable.Global: "#000000", # class: 'vg' - to be revised
116
Name.Variable.Instance: "#000000", # class: 'vi' - to be revised
117
118
Number: "#990000", # class: 'm'
119
120
Literal: "#000000", # class: 'l'
121
Literal.Date: "#000000", # class: 'ld'
122
123
String: "#4e9a06", # class: 's'
124
String.Backtick: "#4e9a06", # class: 'sb'
125
String.Char: "#4e9a06", # class: 'sc'
126
String.Doc: "italic #8f5902", # class: 'sd' - like a comment
127
String.Double: "#4e9a06", # class: 's2'
128
String.Escape: "#4e9a06", # class: 'se'
129
String.Heredoc: "#4e9a06", # class: 'sh'
130
String.Interpol: "#4e9a06", # class: 'si'
131
String.Other: "#4e9a06", # class: 'sx'
132
String.Regex: "#4e9a06", # class: 'sr'
133
String.Single: "#4e9a06", # class: 's1'
134
String.Symbol: "#4e9a06", # class: 'ss'
135
136
Generic: "#000000", # class: 'g'
137
Generic.Deleted: "#a40000", # class: 'gd'
138
Generic.Emph: "italic #000000", # class: 'ge'
139
Generic.Error: "#ef2929", # class: 'gr'
140
Generic.Heading: "bold #000080", # class: 'gh'
141
Generic.Inserted: "#00A000", # class: 'gi'
142
Generic.Output: "#888", # class: 'go'
143
Generic.Prompt: "#745334", # class: 'gp'
144
Generic.Strong: "bold #000000", # class: 'gs'
145
Generic.Subheading: "bold #800080", # class: 'gu'
146
Generic.Traceback: "bold #a40000", # class: 'gt'
147
}
148
149