reprexlite.formatting¶
Classes¶
Advertisement
¶
Class for generating the advertisement note for reprexlite.
Attributes:
Name | Type | Description |
---|---|---|
timestamp |
str
|
Timestamp of instance instantiation |
version |
str
|
Version of reprexlite |
Source code in reprexlite/formatting.py
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
|
Functions¶
code_comment() -> str
¶
Render reprexlite advertisement as a comment in Python code.
Source code in reprexlite/formatting.py
254 255 256 |
|
html() -> str
¶
Render reprexlite advertisement in HTML.
Source code in reprexlite/formatting.py
247 248 249 250 251 252 |
|
markdown() -> str
¶
Render reprexlite advertisement in GitHub Flavored Markdown.
Source code in reprexlite/formatting.py
243 244 245 |
|
text() -> str
¶
Render reprexlite advertisement in plain text.
Source code in reprexlite/formatting.py
258 259 260 |
|
FormatterRegistry
¶
Registry of formatters keyed by venue keywords.
Source code in reprexlite/formatting.py
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 |
|
Functions¶
register(venue: Venue, label: str)
¶
Decorator that registers a formatter implementation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
venue
|
str
|
Venue keyword that formatter will be registered to. |
required |
label
|
str
|
Short human-readable label explaining the venue. |
required |
Source code in reprexlite/formatting.py
41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
Functions¶
format_as_html(reprex_str: str, config: Optional[ReprexConfig] = None) -> str
¶
Format a rendered reprex reprex as an HTML code block. If optional dependency Pygments is available, the rendered HTML will have syntax highlighting for the Python code. By default, includes a footer that credits reprexlite.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reprex_str
|
str
|
The reprex string to render. |
required |
config
|
Optional[ReprexConfig]
|
Configuration for the reprex. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The rendered reprex |
Example
2+2
#> 4
Source code in reprexlite/formatting.py
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 |
|
format_as_markdown(reprex_str: str, config: Optional[ReprexConfig] = None) -> str
¶
Format a rendered reprex reprex as a GitHub-Flavored Markdown code block. By default, includes a footer that credits reprexlite.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reprex_str
|
str
|
The reprex string to render. |
required |
config
|
Optional[ReprexConfig]
|
Configuration for the reprex. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The rendered reprex |
Example
2+2
#> 4
Source code in reprexlite/formatting.py
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 |
|
format_as_python_script(reprex_str: str, config: Optional[ReprexConfig] = None) -> str
¶
Format a rendered reprex reprex as a Python script.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reprex_str
|
str
|
The reprex string to render. |
required |
config
|
Optional[ReprexConfig]
|
Configuration for the reprex. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The rendered reprex |
Source code in reprexlite/formatting.py
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 |
|
format_as_rtf(reprex_str: str, config: Optional[ReprexConfig] = None) -> str
¶
Format a rendered reprex reprex as a Rich Text Format (RTF) document. Requires dependency Pygments.
Source code in reprexlite/formatting.py
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
|
format_for_slack(reprex_str: str, config: Optional[ReprexConfig] = None) -> str
¶
Format a rendered reprex as Slack markup.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reprex_str
|
str
|
The reprex string to render. |
required |
config
|
Optional[ReprexConfig]
|
Configuration for the reprex. Defaults to None. |
None
|
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The rendered reprex |
Example
2+2
#> 4
Source code in reprexlite/formatting.py
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
|