MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / clean_extracted_text

Function clean_extracted_text

skills/pdf-parser/scripts/parse_pdf.py:141–167  ·  view source on GitHub ↗

Normalize PDF text so downstream regexes behave predictably.

(text: str)

Source from the content-addressed store, hash-verified

139
140
141def clean_extracted_text(text: str) -> str:
142 """Normalize PDF text so downstream regexes behave predictably."""
143 if not text:
144 return ""
145
146 text = (
147 text.replace("\r\n", "\n")
148 .replace("\r", "\n")
149 .replace("\u200b", "")
150 .replace("\u200c", "")
151 .replace("\u200d", "")
152 .replace("\ufeff", "")
153 )
154
155 cleaned_lines: List[str] = []
156 previous_blank = False
157 for raw_line in text.split("\n"):
158 line = re.sub(r"[ \t]+", " ", raw_line).strip()
159 if not line:
160 if not previous_blank:
161 cleaned_lines.append("")
162 previous_blank = True
163 continue
164 cleaned_lines.append(line)
165 previous_blank = False
166
167 return "\n".join(cleaned_lines).strip()
168
169
170def _normalize_heading_line(line: str) -> str:

Calls

no outgoing calls

Tested by

no test coverage detected