@@ -32,47 +32,18 @@ def _footnote_renderer(node: RenderTreeNode, context: RenderContext) -> str:
3232 first_line = f"[^{ node .meta ['label' ]} ]:"
3333 indent = " " * 4
3434 elements = []
35-
36- first_child_idx = 0
37- while (
38- first_child_idx < len (node .children )
39- and node .children [first_child_idx ].type == "footnote_anchor"
40- ):
41- first_child_idx += 1
42-
43- if (
44- first_child_idx < len (node .children )
45- and node .children [first_child_idx ].type == "paragraph"
46- ):
47- with context .indented (len (first_line ) + 1 ):
48- first_element = node .children [first_child_idx ].render (context )
49-
50- first_element_lines = first_element .split ("\n " )
51- first_para_first_line = first_element_lines [0 ]
52- first_para_rest_lines = first_element_lines [1 :]
53-
54- with context .indented (len (indent )):
55- for child in node .children [first_child_idx + 1 :]:
56- if child .type == "footnote_anchor" :
57- continue
58- elements .append (child .render (context ))
59-
60- result = first_line + " " + first_para_first_line
61- if first_para_rest_lines :
62- indented_rest = textwrap .indent ("\n " .join (first_para_rest_lines ), indent )
63- result += "\n " + indented_rest
64- if elements :
65- result += "\n \n " + textwrap .indent ("\n \n " .join (elements ), indent )
66- return result
67-
6835 with context .indented (len (indent )):
6936 for child in node .children :
7037 if child .type == "footnote_anchor" :
7138 continue
7239 elements .append (child .render (context ))
7340 body = textwrap .indent ("\n \n " .join (elements ), indent )
74- if body :
41+ # if the first body element is a paragraph, we can start on the first line,
42+ # otherwise we start on the second line
43+ if body and node .children and node .children [0 ].type != "paragraph" :
7544 body = "\n " + body
45+ else :
46+ body = " " + body .lstrip ()
7647 return first_line + body
7748
7849
0 commit comments