Added support for CONT and CONC continuations

This commit is contained in:
Przemek Wiech
2019-03-14 23:50:49 +01:00
parent 0b0c017c99
commit 750cb394e7

View File

@@ -137,6 +137,23 @@ function joinLines(lines: (JSX.Element | string)[]) {
); );
} }
/**
* Returns the data for the given GEDCOM entry as an array of lines. Supports
* continuations with CONT and CONC.
*/
function getData(entry: GedcomEntry) {
const result = [entry.data];
entry.tree.forEach((subentry) => {
if (subentry.tag === 'CONC' && subentry.data) {
const last = result.length - 1;
result[last] += subentry.data;
} else if (subentry.tag === 'CONT' && subentry.data) {
result.push(subentry.data);
}
});
return result;
}
function eventDetails(entry: GedcomEntry, intl: InjectedIntl) { function eventDetails(entry: GedcomEntry, intl: InjectedIntl) {
const lines = []; const lines = [];
const date = entry.tree.find((subentry) => subentry.tag === 'DATE'); const date = entry.tree.find((subentry) => subentry.tag === 'DATE');
@@ -145,13 +162,13 @@ function eventDetails(entry: GedcomEntry, intl: InjectedIntl) {
} }
const place = entry.tree.find((subentry) => subentry.tag === 'PLAC'); const place = entry.tree.find((subentry) => subentry.tag === 'PLAC');
if (place && place.data) { if (place && place.data) {
lines.push(place.data); lines.push(...getData(place));
} }
entry.tree entry.tree
.filter((subentry) => subentry.tag === 'NOTE') .filter((subentry) => subentry.tag === 'NOTE')
.forEach((note) => { .forEach((note) =>
lines.push(<i>{note.data}</i>); getData(note).forEach((line) => lines.push(<i>{line}</i>)),
}); );
if (!lines.length) { if (!lines.length) {
return null; return null;
} }
@@ -166,13 +183,13 @@ function eventDetails(entry: GedcomEntry, intl: InjectedIntl) {
function dataDetails(entry: GedcomEntry) { function dataDetails(entry: GedcomEntry) {
const lines = []; const lines = [];
if (entry.data) { if (entry.data) {
lines.push(entry.data); lines.push(...getData(entry));
} }
entry.tree entry.tree
.filter((subentry) => subentry.tag === 'NOTE') .filter((subentry) => subentry.tag === 'NOTE')
.forEach((note) => { .forEach((note) =>
lines.push(<i>{note.data}</i>); getData(note).forEach((line) => lines.push(<i>{line}</i>)),
}); );
if (!lines.length) { if (!lines.length) {
return null; return null;
} }
@@ -185,14 +202,7 @@ function dataDetails(entry: GedcomEntry) {
} }
function noteDetails(entry: GedcomEntry) { function noteDetails(entry: GedcomEntry) {
const lines = []; return joinLines(getData(entry).map((line) => <i>{line}</i>));
if (entry.data) {
lines.push(entry.data);
}
if (!lines.length) {
return null;
}
return <i>{joinLines(lines)}</i>;
} }
function nameDetails(entry: GedcomEntry) { function nameDetails(entry: GedcomEntry) {