Initializes GEDCOM to Markdown converter project #1

Merged
AlexKucera merged 29 commits from initial_features into main 2025-11-02 17:47:20 +01:00
2 changed files with 49 additions and 10 deletions
Showing only changes of commit cc46f0a523 - Show all commits

No files matched your search

+42 -7
View File
@@ -251,12 +251,12 @@ class Individual:
return events return events
def get_images(self) -> List[str]: def get_images(self) -> List[Dict[str, str]]:
""" """
Get all image/media references for this person. Get all image/media references for this person.
Returns: Returns:
List of image reference IDs List of dictionaries with 'file', 'title', 'format' keys
""" """
images = [] images = []
@@ -264,8 +264,28 @@ class Individual:
if child.get_tag() == 'OBJE': if child.get_tag() == 'OBJE':
# OBJE can have a reference or inline data # OBJE can have a reference or inline data
reference = child.get_value() reference = child.get_value()
if reference: if reference and reference.startswith('@'):
images.append(reference) # Resolve the reference to get actual file info
obje_element = self.gedcom.get_element_dictionary().get(
reference
)
if obje_element:
image_info = {
'file': '',
'title': '',
'format': ''
}
for obje_child in obje_element.get_child_elements():
if obje_child.get_tag() == 'FILE':
image_info['file'] = obje_child.get_value() or ''
elif obje_child.get_tag() == 'TITL':
image_info['title'] = obje_child.get_value() or ''
elif obje_child.get_tag() == 'FORM':
image_info['format'] = obje_child.get_value() or ''
if image_info['file']:
images.append(image_info)
return images return images
@@ -366,10 +386,25 @@ class Individual:
text += '\n' + (cont.get_value() or '') text += '\n' + (cont.get_value() or '')
section_data['text'] = text section_data['text'] = text
elif sts_child.get_tag() == 'OBJE': elif sts_child.get_tag() == 'OBJE':
# Get image reference # Resolve image reference
img_ref = sts_child.get_value() img_ref = sts_child.get_value()
if img_ref: if img_ref and img_ref.startswith('@'):
section_data['images'].append(img_ref) obje_element = self.gedcom.get_element_dictionary().get(img_ref)
if obje_element:
image_info = {
'file': '',
'title': '',
'format': ''
}
for obje_child in obje_element.get_child_elements():
if obje_child.get_tag() == 'FILE':
image_info['file'] = obje_child.get_value() or ''
elif obje_child.get_tag() == 'TITL':
image_info['title'] = obje_child.get_value() or ''
elif obje_child.get_tag() == 'FORM':
image_info['format'] = obje_child.get_value() or ''
if image_info['file']:
section_data['images'].append(image_info)
if section_data['subtitle'] or section_data['text']: if section_data['subtitle'] or section_data['text']:
story['sections'].append(section_data) story['sections'].append(section_data)
+7 -3
View File
2
@@ -238,8 +238,10 @@ class MarkdownGenerator:
f.write("## Images\n") f.write("## Images\n")
for image_ref in images: for image in images:
f.write(f"- {image_ref}\n") title = image['title'] if image['title'] else 'Image'
filename = image['file']
f.write(f"![{title}]({filename})\n\n")
f.write('\n') f.write('\n')
@@ -276,7 +278,9 @@ class MarkdownGenerator:
# Write images for this section # Write images for this section
if section['images']: if section['images']:
for img in section['images']: for img in section['images']:
f.write(f"![Image]({img})\n\n") title = img['title'] if img['title'] else 'Image'
filename = img['file']
f.write(f"![{title}]({filename})\n\n")
f.write('\n') f.write('\n')