@@ -56,19 +56,30 @@ def _footnote_ref_renderer(node: RenderTreeNode, context: RenderContext) -> str:
5656def _footnote_renderer (node : RenderTreeNode , context : RenderContext ) -> str :
5757 first_line = f"[^{ node .meta ['label' ]} ]:"
5858 indent = " " * 4
59- elements = []
59+
60+ children = [c for c in node .children if c .type != "footnote_anchor" ]
61+
62+ if children and children [0 ].type == "paragraph" :
63+ with context .indented (len (first_line ) + 1 ):
64+ first_element = children [0 ].render (context )
65+
66+ first_para_first_line , * first_para_rest_lines = first_element .split ("\n " )
67+
68+ with context .indented (len (indent )):
69+ elements = [child .render (context ) for child in children [1 :]]
70+
71+ result = first_line + " " + first_para_first_line
72+ if first_para_rest_lines :
73+ result += "\n " + textwrap .indent ("\n " .join (first_para_rest_lines ), indent )
74+ if elements :
75+ result += "\n \n " + textwrap .indent ("\n \n " .join (elements ), indent )
76+ return result
77+
6078 with context .indented (len (indent )):
61- for child in node .children :
62- if child .type == "footnote_anchor" :
63- continue
64- elements .append (child .render (context ))
79+ elements = [child .render (context ) for child in children ]
6580 body = textwrap .indent ("\n \n " .join (elements ), indent )
66- # if the first body element is a paragraph, we can start on the first line,
67- # otherwise we start on the second line
68- if body and node .children and node .children [0 ].type != "paragraph" :
81+ if body :
6982 body = "\n " + body
70- else :
71- body = " " + body .lstrip ()
7283 return first_line + body
7384
7485
0 commit comments