MCPcopy
hub / github.com/langroid/langroid / format_footnote_text

Function format_footnote_text

langroid/utils/output/citations.py:49–90  ·  view source on GitHub ↗

Formats the content so that each original line is individually processed. - If width=0, no wrapping is done (lines remain as is). - If width>0, lines are wrapped to that width. - Blank lines remain blank (with indentation). - Everything is indented by 4 spaces (for markdown foot

(content: str, width: int = 0)

Source from the content-addressed store, hash-verified

47
48
49def format_footnote_text(content: str, width: int = 0) -> str:
50 """
51 Formats the content so that each original line is individually processed.
52 - If width=0, no wrapping is done (lines remain as is).
53 - If width>0, lines are wrapped to that width.
54 - Blank lines remain blank (with indentation).
55 - Everything is indented by 4 spaces (for markdown footnotes).
56
57 Args:
58 content (str): The text of the footnote to be formatted.
59 width (int): Maximum width of the text lines. If 0, lines are not wrapped.
60
61 Returns:
62 str: Properly formatted markdown footnote text.
63 """
64 import textwrap
65
66 indent = " " # 4 spaces for markdown footnotes
67 lines = content.split("\n") # keep original line structure
68
69 output_lines = []
70 for line in lines:
71 # If the line is empty (or just spaces), keep it blank (but indented)
72 if not line.strip():
73 output_lines.append(indent)
74 continue
75
76 if width > 0:
77 # Wrap each non-empty line to the specified width
78 wrapped = textwrap.wrap(line, width=width)
79 if not wrapped:
80 # If textwrap gives nothing, add a blank (indented) line
81 output_lines.append(indent)
82 else:
83 for subline in wrapped:
84 output_lines.append(indent + subline)
85 else:
86 # No wrapping: just indent the original line
87 output_lines.append(indent + line)
88
89 # Join them with newline so we preserve the paragraph/blank line structure
90 return "\n".join(output_lines)
91
92
93def format_cited_references(

Callers 1

format_cited_referencesFunction · 0.85

Calls 1

splitMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…