MCPcopy Create free account
hub / github.com/RASAAS/docmcp-knowledge / clean_footnotes

Function clean_footnotes

scripts/remove_footnote_links.py:11–31  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

9raw_url_pattern = re.compile(r'https?://\S+')
10
11def clean_footnotes(text):
12 if "**Footnotes**" not in text:
13 return text
14
15 parts = text.split("**Footnotes**")
16 pre_footnotes = parts[0]
17 footnotes = parts[1]
18
19 # Process footnotes line by line
20 cleaned_lines = []
21 for line in footnotes.split('\n'):
22 # 1. Replace [text](url) with just text
23 line = markdown_link_pattern.sub(r'\1', line)
24 # 2. Remove raw URLs
25 line = raw_url_pattern.sub('', line)
26
27 # strip excessive spaces that might have been left
28 line = line.replace(' :', ':').replace(' ,', ',').replace(' .', '.')
29 cleaned_lines.append(line)
30
31 return pre_footnotes + "**Footnotes**" + '\n'.join(cleaned_lines)
32
33changed_files = 0
34for file_path in dir_path.glob("*.md"):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected