Skip to content

Commit 8889891

Browse files
committed
Format pandoc module with black
1 parent bf43936 commit 8889891

File tree

6 files changed

+162
-86
lines changed

6 files changed

+162
-86
lines changed

quartodoc/pandoc/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@
55
supported by lua [filters](https://pandoc.org/lua-filters.html). Specifically
66
the [pandoc-module](https://pandoc.org/lua-filters.html#module-pandoc)
77
"""
8-

quartodoc/pandoc/blocks.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from textwrap import indent
1111
from dataclasses import dataclass
1212
from typing import Literal, Optional, Sequence, Union
13+
1314
if sys.version_info >= (3, 10):
1415
from typing import TypeAlias
1516
else:
@@ -50,9 +51,7 @@ def __str__(self):
5051
"""
5152
Return Inline element as markdown
5253
"""
53-
raise NotImplementedError(
54-
f"__str__ method not implemented for: {type(self)}"
55-
)
54+
raise NotImplementedError(f"__str__ method not implemented for: {type(self)}")
5655

5756
@property
5857
def html(self):
@@ -102,6 +101,7 @@ def __str__(self):
102101
:::\
103102
"""
104103

104+
105105
@dataclass
106106
class Div(Block):
107107
"""
@@ -175,6 +175,7 @@ class Plain(Block):
175175
"""
176176
Plain text (not a paragraph)
177177
"""
178+
178179
content: Optional[InlineContent] = None
179180

180181
def __str__(self):
@@ -186,7 +187,9 @@ class Para(Block):
186187
"""
187188
Paragraph
188189
"""
190+
189191
content: Optional[InlineContent] = None
192+
190193
def __str__(self):
191194
content = inlinecontent_to_str(self.content)
192195
return f"{SEP}{content}{SEP}"
@@ -202,6 +205,7 @@ class Header(Block):
202205
"""
203206
Header
204207
"""
208+
205209
level: int
206210
content: Optional[InlineContent] = None
207211
attr: Optional[Attr] = None
@@ -230,6 +234,7 @@ class CodeBlock(Block):
230234
"""
231235
Header
232236
"""
237+
233238
content: Optional[str] = None
234239
attr: Optional[Attr] = None
235240

@@ -240,9 +245,9 @@ def __str__(self):
240245
# other attributes, use a short form to open it
241246
# e.g. ```python instead of ``` {.python}
242247
no_curly_braces = (
243-
self.attr.classes and
244-
len(self.attr.classes) == 1 and
245-
not self.attr.attributes
248+
self.attr.classes
249+
and len(self.attr.classes) == 1
250+
and not self.attr.attributes
246251
)
247252

248253
if self.attr.classes and no_curly_braces:
@@ -278,6 +283,7 @@ class BulletList(Block):
278283
"""
279284
A bullet list
280285
"""
286+
281287
content: Optional[BlockContent] = None
282288

283289
def __str__(self):
@@ -294,6 +300,7 @@ class OrderedList(Block):
294300
"""
295301
An Ordered list
296302
"""
303+
297304
content: Optional[BlockContent] = None
298305

299306
def __str__(self):
@@ -307,6 +314,7 @@ def __str__(self):
307314

308315
# Helper functions
309316

317+
310318
def join_block_content(content: Sequence[BlockContent]) -> str:
311319
"""
312320
Join a sequence of blocks into one string
@@ -335,8 +343,7 @@ def blockcontent_to_str(content: Optional[BlockContent]) -> str:
335343

336344

337345
def blockcontent_to_str_items(
338-
content: Optional[BlockContent],
339-
kind: Literal["bullet", "ordered"]
346+
content: Optional[BlockContent], kind: Literal["bullet", "ordered"]
340347
) -> str:
341348
"""
342349
Convert block content to strings of items
@@ -350,7 +357,7 @@ def blockcontent_to_str_items(
350357
How to mark (prefix) each item in the of content.
351358
"""
352359

353-
def fmt(s:str, pfx: str):
360+
def fmt(s: str, pfx: str):
354361
"""
355362
Format as a list item with one or more blocks
356363
"""
@@ -379,7 +386,7 @@ def fmt(s:str, pfx: str):
379386
return ""
380387

381388
if kind == "bullet":
382-
pfx_it = itertools.cycle("*")
389+
pfx_it = itertools.cycle("*")
383390
else:
384391
pfx_it = (f"{i}." for i in itertools.count(1))
385392

quartodoc/pandoc/components.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
if typing.TYPE_CHECKING:
1010
from typing import Optional, Sequence
1111

12-
__all__ = (
13-
"Attr",
14-
)
12+
__all__ = ("Attr",)
1513

1614

1715
@dataclass
1816
class Attr:
1917
"""
2018
Create a new set of attributes (Attr)
2119
"""
20+
2221
identifier: Optional[str] = None
2322
classes: Optional[Sequence[str]] = None
2423
attributes: Optional[dict[str, str]] = None
@@ -43,13 +42,10 @@ def __str__(self):
4342
parts.append(" ".join(f".{c}" for c in self.classes))
4443

4544
if self.attributes:
46-
parts.append(
47-
" ".join(f'{k}="{v}"' for k, v in self.attributes.items())
48-
)
45+
parts.append(" ".join(f'{k}="{v}"' for k, v in self.attributes.items()))
4946

5047
return " ".join(parts)
5148

52-
5349
@property
5450
def html(self):
5551
"""
@@ -69,9 +65,7 @@ def html(self):
6965
parts.append(f'class="{s}"')
7066

7167
if self.attributes:
72-
parts.append(
73-
" ".join(f'{k}="{v}"' for k, v in self.attributes.items())
74-
)
68+
parts.append(" ".join(f'{k}="{v}"' for k, v in self.attributes.items()))
7569
return " ".join(parts)
7670

7771
@property

quartodoc/pandoc/inlines.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from dataclasses import dataclass
1010
from pathlib import Path
1111
from typing import Optional, Sequence, Union
12+
1213
if sys.version_info >= (3, 10):
1314
from typing import TypeAlias
1415
else:
@@ -25,7 +26,7 @@
2526
"Link",
2627
"Span",
2728
"Str",
28-
"Strong"
29+
"Strong",
2930
)
3031

3132
SEP = " "
@@ -40,9 +41,7 @@ def __str__(self):
4041
"""
4142
Return Inline element as markdown
4243
"""
43-
raise NotImplementedError(
44-
f"__str__ method not implemented for: {type(self)}"
45-
)
44+
raise NotImplementedError(f"__str__ method not implemented for: {type(self)}")
4645

4746
@property
4847
def html(self):
@@ -74,6 +73,7 @@ class Inlines(Inline):
7473
"""
7574
Sequence of inline elements
7675
"""
76+
7777
elements: Optional[Sequence[InlineContent]] = None
7878

7979
def __str__(self):
@@ -87,6 +87,7 @@ class Str(Inline):
8787
"""
8888
A String
8989
"""
90+
9091
content: Optional[str] = None
9192

9293
def __str__(self):
@@ -98,6 +99,7 @@ class Span(Inline):
9899
"""
99100
A Span
100101
"""
102+
101103
content: Optional[InlineContent] = None
102104
attr: Optional[Attr] = None
103105

@@ -115,6 +117,7 @@ class Link(Inline):
115117
"""
116118
A Link
117119
"""
120+
118121
content: Optional[InlineContent] = None
119122
target: Optional[str] = None
120123
title: Optional[str] = None
@@ -126,7 +129,7 @@ def __str__(self):
126129
"""
127130
title = f' "{self.title}"' if self.title else ""
128131
content = inlinecontent_to_str(self.content)
129-
attr = f"{{{self.attr}}}" if self.attr else ""
132+
attr = f"{{{self.attr}}}" if self.attr else ""
130133
return f"[{content}]({self.target}{title}){attr}"
131134

132135

@@ -135,6 +138,7 @@ class Code(Inline):
135138
"""
136139
Code (inline)
137140
"""
141+
138142
text: Optional[str] = None
139143
attr: Optional[Attr] = None
140144

@@ -143,7 +147,7 @@ def __str__(self):
143147
Return link as markdown
144148
"""
145149
content = self.text or ""
146-
attr = f"{{{self.attr}}}" if self.attr else ""
150+
attr = f"{{{self.attr}}}" if self.attr else ""
147151
return f"`{content}`{attr}"
148152

149153
@property
@@ -166,6 +170,7 @@ class Strong(Inline):
166170
"""
167171
Strongly emphasized text
168172
"""
173+
169174
content: Optional[InlineContent] = None
170175

171176
def __str__(self):
@@ -184,6 +189,7 @@ class Emph(Inline):
184189
"""
185190
Emphasized text
186191
"""
192+
187193
content: Optional[InlineContent] = None
188194

189195
def __str__(self):
@@ -215,12 +221,13 @@ def __str__(self):
215221
caption = self.caption or ""
216222
src = self.src or ""
217223
title = f' "{self.title}"' if self.title else ""
218-
attr = f"{{{self.attr}}}" if self.attr else ""
224+
attr = f"{{{self.attr}}}" if self.attr else ""
219225
return f"![{caption}]({src}{title}){attr}"
220226

221227

222228
# Helper functions
223229

230+
224231
def join_inline_content(content: Sequence[InlineContent]) -> str:
225232
"""
226233
Join a sequence of inlines into one string

0 commit comments

Comments
 (0)