MCPcopy Create free account
hub / github.com/conda/constructor / txt_to_rtf

Function txt_to_rtf

constructor/briefcase.py:129–153  ·  view source on GitHub ↗

Convert plain text to RTF with Segoe UI font. Uses Segoe UI at 9pt for better readability than Briefcase's default Courier.

(txt: str)

Source from the content-addressed store, hash-verified

127
128
129def txt_to_rtf(txt: str) -> str:
130 """Convert plain text to RTF with Segoe UI font.
131
132 Uses Segoe UI at 9pt for better readability than Briefcase's default Courier.
133 """
134 # Escape RTF special characters: \ { }
135 escaped = txt.replace("\\", "\\\\").replace("{", "\\{").replace("}", "\\}")
136
137 # RTF header breakdown:
138 # \rtf1 - RTF version 1
139 # \ansi - ANSI character set
140 # \deff0 - default font is font 0
141 # \fonttbl - font table definition
142 # \f0 - use font 0 (Segoe UI)
143 # \fs18 - font size 18 half-points (9pt)
144 rtf_lines = ["{\\rtf1\\ansi\\deff0 {\\fonttbl {\\f0 Segoe UI;}}\\f0\\fs18"]
145 for line in escaped.split("\n"):
146 if line.strip():
147 rtf_lines.append(line.rstrip() + " ")
148 else:
149 # \par = paragraph break (two for visual separation between paragraphs)
150 rtf_lines.append("\\par\\par")
151 rtf_lines.append("}")
152
153 return "\n".join(rtf_lines)
154
155
156def get_license(info, root: Path = None):

Callers 2

test_txt_to_rtfFunction · 0.90
get_licenseFunction · 0.85

Calls

no outgoing calls

Tested by 1

test_txt_to_rtfFunction · 0.72