Skip to content

Commit 0702ec8

Browse files
committed
Slight clean up
Use format strings and check for None text
1 parent 606d324 commit 0702ec8

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

markdown/extensions/md_in_html.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -180,17 +180,16 @@ def handle_endtag(self, tag):
180180
state = child.attrib.get('markdown', 'off')
181181

182182
# If the tail is just a new line, omit it.
183-
if tail == '\n':
184-
tail = ''
183+
tail = '' if tail == '\n' else '\n' + tail
185184

186185
# Process the block nested under the span appropriately
187186
if state in ('span', 'block'):
188-
current.text = text + '\n' + self.md.htmlStash.store(child) + '\n' + tail
187+
current.text = f'{text}\n{self.md.htmlStash.store(child)}{tail}'
189188
last.append(child)
190189
else:
191190
child.attrib.pop('markdown')
192191
[c.attrib.pop('markdown', None) for c in child.iter()]
193-
current.text = text + '\n' + self.md.htmlStash.store(child) + '\n' + tail
192+
current.text = f'{text}\n{self.md.htmlStash.store(child)}{tail}'
194193
current = last.pop(0) if last else None
195194

196195
self.cleandoc.append(self.md.htmlStash.store(element))
@@ -311,7 +310,7 @@ def parse_element_content(self, element: etree.Element) -> None:
311310
# as their content is not normally accessed by block processors, so expand stashed
312311
# HTML under the span. Span content itself will not be parsed here, but will await
313312
# the inline parser.
314-
block = element.text
313+
block = element.text if element.text is not None else ''
315314
element.text = ''
316315
child = None
317316
start = 0
@@ -327,7 +326,7 @@ def parse_element_content(self, element: etree.Element) -> None:
327326
if child is None:
328327
element.text = block[start:end]
329328
else:
330-
child.tail = (child.tail if child.tail is not None else '') + block[start:end]
329+
child.tail = f"{child.tail if child.tail is not None else ''}{block[start:end]}"
331330
element.append(el)
332331
self.parse_element_content(el)
333332
child = el
@@ -339,7 +338,7 @@ def parse_element_content(self, element: etree.Element) -> None:
339338
if child is None:
340339
element.text = block[start:end]
341340
else:
342-
child.tail = (child.tail if child.tail is not None else '') + block[start:end]
341+
child.tail = f"{child.tail if child.tail is not None else ''}{block[start:end]}"
343342
start = end
344343

345344
# Insert anything left after last element

0 commit comments

Comments
 (0)