reprexlite.formatting¶
Attributes¶
formatter_registry: Dict[str, Type[Formatter]] = {}
module-attribute
¶
Registry of formatters keyed by venue keywords.
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
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
Functions¶
code_comment() -> str
¶
Render reprexlite advertisement as a comment in Python code.
Source code in reprexlite/formatting.py
281 282 283 | |
html() -> str
¶
Render reprexlite advertisement in HTML.
Source code in reprexlite/formatting.py
274 275 276 277 278 279 | |
markdown() -> str
¶
Render reprexlite advertisement in GitHub Flavored Markdown.
Source code in reprexlite/formatting.py
270 271 272 | |
text() -> str
¶
Render reprexlite advertisement in plain text.
Source code in reprexlite/formatting.py
285 286 287 | |
Formatter
¶
Bases: ABC
Abstract base class for a reprex formatter. Concrete subclasses should implement the
formatting logic appropriate to a specific venue for sharing. Call str(...) on an instance
to return the formatted reprex.
Attributes:
| Name | Type | Description |
|---|---|---|
default_advertise |
bool
|
Whether to render reprexlite advertisement by default |
meta |
FormatterMeta
|
Contains metadata for the formatter, such as label text and an example |
Source code in reprexlite/formatting.py
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 | |
Functions¶
format(reprex_str: str, advertise: Optional[bool] = None, session_info: bool = False) -> str
abstractmethod
classmethod
¶
Format a reprex string for a specific sharing venue.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
reprex_str
|
str
|
String containing rendered reprex output. |
required |
advertise
|
Optional[bool]
|
Whether to include the advertisement for reprexlite. Defaults to None, which uses a per-formatter default. |
None
|
session_info
|
bool
|
Whether to include detailed session information. Defaults to False. |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
String containing formatted reprex code. Ends with newline. |
Source code in reprexlite/formatting.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
GitHubFormatter
¶
Bases: Formatter
Formatter for rendering reprexes in GitHub Flavored Markdown.
Source code in reprexlite/formatting.py
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 | |
HtmlFormatter
¶
Bases: Formatter
Formatter for rendering reprexes in HTML. If optional dependency Pygments is available, the rendered HTML will have syntax highlighting for the Python code.
Source code in reprexlite/formatting.py
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 | |
PyScriptFormatter
¶
Bases: Formatter
Formatter for rendering reprexes as a Python script.
Source code in reprexlite/formatting.py
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 | |
RtfFormatter
¶
Bases: Formatter
Formatter for rendering reprexes in Rich Text Format.
Source code in reprexlite/formatting.py
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 217 | |
SlackFormatter
¶
Bases: Formatter
Formatter for rendering reprexes as Slack markup.
Source code in reprexlite/formatting.py
220 221 222 223 224 225 226 227 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 | |
Functions¶
register_formatter(venue: str, 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
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |