Skip to content

Commit b7952f4

Browse files
committed
. r Standardize headers before removing sections. Tweak regep's to match various "(in)active co-author" headers
1 parent cb8a959 commit b7952f4

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

src/session_notes_cleanup/session_notes_cleaner.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,20 @@ def __init__(self):
99
pass
1010

1111
def contains_inactive_coauthors(self, text):
12-
return bool(re.search(r'^#+\s*Inactive Co-Authors', text, re.IGNORECASE | re.MULTILINE))
12+
return bool(re.search(r'^#+\s*Inactive( Co-Authors)?', text, re.IGNORECASE | re.MULTILINE))
1313

1414
def delete_inactive_coauthors(self, text):
15-
return re.sub(r'^#+\s*Inactive Co-Authors.*?(?=^#|\Z)', '', text,
15+
return re.sub(r'^#+\s*Inactive( Co-Authors)?.*?(?=^#|\Z)', '', text,
1616
flags=re.IGNORECASE | re.MULTILINE | re.DOTALL)
1717

1818
def contains_active_coauthors(self, text):
19-
return bool(re.search(r'^#+\s*Active Co-Authors', text, re.IGNORECASE | re.MULTILINE))
19+
return bool(re.search(r'^#+\s*(Active )?Co-Authors', text, re.IGNORECASE | re.MULTILINE))
2020

2121
def standardize_coauthor_heading(self, text):
22-
return re.sub(r'^#+\s*.*Co-?Author.*', '## Co-Authors',
22+
return re.sub(r'^#+\s*.*?((?:Inactive\s+)?)\s*Co-?Author.*', r'## \1Co-Authors',
2323
text,
2424
flags=re.IGNORECASE | re.MULTILINE)
2525

26-
import re
27-
2826
def remove_coauthor_headings(self, text):
2927
# Regular expression to match 1st and 2nd level headings with "Co-Authors"
3028
# Assumes Markdown formatting where 1st level is '# ' and 2nd level is '## '
@@ -34,7 +32,6 @@ def remove_coauthor_headings(self, text):
3432

3533
return cleaned_text
3634

37-
3835
def add_coauthor_heading_before_co_authored_by_list(self, text):
3936
search_pattern = r'^(Co-Authored-By.*)$'
4037
replace_pattern = r'## Co-Authors\n\1'
@@ -43,10 +40,6 @@ def add_coauthor_heading_before_co_authored_by_list(self, text):
4340
flags=re.IGNORECASE | re.MULTILINE)
4441
return cleaned_text
4542

46-
def applesauce(self, text):
47-
pattern = r'^#+\s*Co-Author$'
48-
re.sub(pattern, text,flags=re.IGNORECASE )
49-
5043
def get_date_from_filename(self, filename):
5144
match = re.search(r'(\d{4}-\d{2}-\d{2})', filename, re.IGNORECASE)
5245
return match.group(1) if match else None
@@ -64,9 +57,9 @@ def contains_session_date(self, text):
6457
def cleanup_contents(self, text, session_date):
6558
if not self.contains_session_date(text):
6659
text = f"# Session Date: {session_date}\n" + text
60+
text = self.standardize_coauthor_heading(text)
6761
if self.contains_active_coauthors(text) and self.contains_inactive_coauthors(text):
6862
text = self.delete_inactive_coauthors(text)
69-
text = self.standardize_coauthor_heading(text)
7063
text = self.remove_coauthor_headings(text)
7164
text = self.add_coauthor_heading_before_co_authored_by_list(text)
7265
return text

tests/test_session_notes_cleaner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def test_delete_inactive_coauthors(self):
4040
def test_normalize_coauthor_heading(self):
4141
cleaner = SessionNotesCleaner()
4242
text = "## Coauthors\n## Active Co-Authors\n## Today's Co-Authors\n## Co-Authors (today)\n"
43+
text += "## Inactive\n## Inactive Co-Authors\n## Inactive CoAuthors\n"
4344
clean_text = cleaner.standardize_coauthor_heading(text)
4445
acceptance_text = f'Before\n{text}====\nAfter\n{clean_text}====\n'
4546
verify(acceptance_text)

0 commit comments

Comments
 (0)