From 3a9112de601120d343ad9dff139e826f15e165f0 Mon Sep 17 00:00:00 2001 From: Alexander Kucera Date: Fri, 31 Oct 2025 15:02:12 +0100 Subject: [PATCH] Enhances GEDCOM story parsing and markdown generation Improves individual story extraction to support: - More detailed story structure with sections - Subtitle and description metadata - Inline image references Updates README with GEDCOM version compatibility guidelines and line ending troubleshooting tips --- README.md | 12 +++++++- src/individual.py | 58 ++++++++++++++++++++++++++++----------- src/markdown_generator.py | 19 +++++++++++-- 3 files changed, 69 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 6f6ec1b..2cc0e2a 100644 --- a/README.md +++ b/README.md @@ -65,7 +65,9 @@ src/ - Python 3.7+ - python-gedcom==1.0.0 -## Line Ending Issue +## Common Issues + +### Line Ending Issue **Important**: Some GEDCOM files exported from macOS applications may use old Mac-style line endings (CR only). If the parser finds 0 individuals, convert line endings first: @@ -77,3 +79,11 @@ with open('file.ged', 'wb') as f: f.write(content.replace(b'\r', b'\n')) " ``` + +### GEDCOM Version Compatibility + +This tool works best with **GEDCOM version 5.5.x or 5.x**. If you're using GEDCOM 7.0+, you may encounter issues with custom tags and story extraction. When exporting from your genealogy software: + +1. Choose GEDCOM version 5.5.1 or 5.1.0 if available +2. Avoid GEDCOM version 7.0+ for better compatibility +3. After export, check and fix line endings if needed (see above) diff --git a/src/individual.py b/src/individual.py index c3f56db..4fd84c4 100644 --- a/src/individual.py +++ b/src/individual.py @@ -307,7 +307,7 @@ class Individual: return notes - def get_stories(self) -> List[Dict[str, str]]: + def get_stories(self) -> List[Dict]: """ Get stories/narratives for this person. @@ -315,7 +315,8 @@ class Individual: tags for storing longer narratives and stories about individuals. Returns: - List of dictionaries with 'title' and 'text' keys + List of dictionaries with 'title', 'sections' keys + Each section has 'subtitle', 'text', 'images' """ stories = [] @@ -331,24 +332,49 @@ class Individual: if story_element: story = { 'title': '', - 'text': '' + 'description': '', + 'sections': [] } - # Get title and text sections + # Get main title and metadata for section in story_element.get_child_elements(): - if section.get_tag() == 'TITL': - story['title'] = section.get_value() or '' - elif section.get_tag() in ['_STS', 'TEXT']: - # Get text content - for text_part in section.get_child_elements(): - if text_part.get_tag() == 'TEXT': - story['text'] = text_part.get_value() or '' - # Check for CONT lines - for cont in text_part.get_child_elements(): - if cont.get_tag() in ['CONT', 'CONC']: - story['text'] += '\n' + (cont.get_value() or '') + tag = section.get_tag() - if story['title'] or story['text']: + if tag == 'TITL': + story['title'] = section.get_value() or '' + elif tag == 'DESC': + story['description'] = section.get_value() or '' + elif tag == '_STS': + # Story section with inline content + # Format: "1 @12375128@ _STS" + # Children at level 2 contain TITL, TEXT, OBJE + section_data = { + 'subtitle': '', + 'text': '', + 'images': [] + } + + # Extract content directly from child elements + for sts_child in section.get_child_elements(): + if sts_child.get_tag() == 'TITL': + section_data['subtitle'] = sts_child.get_value() or '' + elif sts_child.get_tag() == 'TEXT': + text = sts_child.get_value() or '' + # Get CONT lines + for cont in sts_child.get_child_elements(): + if cont.get_tag() in ['CONT', 'CONC']: + text += '\n' + (cont.get_value() or '') + section_data['text'] = text + elif sts_child.get_tag() == 'OBJE': + # Get image reference + img_ref = sts_child.get_value() + if img_ref: + section_data['images'].append(img_ref) + + if section_data['subtitle'] or section_data['text']: + story['sections'].append(section_data) + + if story['title'] or story['sections']: stories.append(story) return stories diff --git a/src/markdown_generator.py b/src/markdown_generator.py index 84e6365..e2c4b16 100644 --- a/src/markdown_generator.py +++ b/src/markdown_generator.py @@ -257,13 +257,26 @@ class MarkdownGenerator: for note in notes: f.write(f"{note}\n\n") - # Write stories with titles + # Write stories with their sections for story in stories: if story['title']: f.write(f"### {story['title']}\n\n") - if story['text']: - f.write(f"{story['text']}\n\n") + if story['description']: + f.write(f"*{story['description']}*\n\n") + + # Write each section + for section in story['sections']: + if section['subtitle']: + f.write(f"#### {section['subtitle']}\n\n") + + if section['text']: + f.write(f"{section['text']}\n\n") + + # Write images for this section + if section['images']: + for img in section['images']: + f.write(f"![Image]({img})\n\n") f.write('\n')