Skip to content

Commit

Permalink
Fix issues with displaying figures (sillsdev#742)
Browse files Browse the repository at this point in the history
* HACK: Add NO_CAPTION to figs without captions and don't render it
* Always display figures or videos in non-scripture books
  • Loading branch information
chrisvire authored Dec 2, 2024
1 parent 7879900 commit fa30de5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
27 changes: 27 additions & 0 deletions convert/convertBooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,32 @@ function removeMissingVerses(text: string, _bcId: string, _bookId: string): stri
});
}

// This is a HACK!!!
// See https://github.com/Proskomma/proskomma-json-tools/issues/63
//
function handleNoCaptionFigures(text: string, _bcId: string, _bookId: string): string {
// Regular expression to match \fig markers
const figRegex = /\\fig\s(.*?)\\fig\*/g;

// Replace each \fig marker with the appropriate action
return text.replace(figRegex, (match, figContent) => {
// Split the content of the \fig marker by pipe (|)
const parts = figContent.split('|');

// Extract the image caption
let imageCaption = parts[0];

// Check if the image caption is missing
if (!imageCaption) {
// Caption is missing, return "NO_CAPTION" as the caption inside of the original \fig marker
return match.replace('|', 'NO_CAPTION|');
} else {
// Caption is present, return the original \fig marker
return match;
}
});
}

function removeMissingFigures(text: string, _bcId: string, _bookId: string): string {
// Regular expression to match \fig markers
const figRegex = /\\fig\s(.*?)\\fig\*/g;
Expand Down Expand Up @@ -158,6 +184,7 @@ const usfmFilterFunctions: FilterFunction[] = [
replaceVideoTags,
replacePageTags,
convertMarkdownsToMilestones,
handleNoCaptionFigures,
removeMissingFigures,
trimTrailingWhitespace
];
Expand Down
16 changes: 12 additions & 4 deletions src/lib/components/ScriptureViewSofria.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -835,13 +835,16 @@ LOGGING:
return source;
}
function showImage() {
return viewShowIllustrations && showImageInBook();
}
function showImageInBook() {
const showBibleImage = viewShowBibleImages === 'normal';
const showImages = currentIsBibleBook && showBibleImage && viewShowIllustrations;
const showImages = !currentIsBibleBook || showBibleImage;
return showImages;
}
function showVideo() {
const showBibleVideo = viewShowBibleVideos === 'normal';
const showVideos = currentIsBibleBook && showBibleVideo;
const showVideos = !currentIsBibleBook || showBibleVideo;
return showVideos;
}
function addFigureDiv(source: string, workspace: any) {
Expand Down Expand Up @@ -1358,8 +1361,13 @@ LOGGING:
break;
}
case 'fig': {
const divFigureText = createIllustrationCaptionBlock(text);
workspace.figureDiv.append(divFigureText);
// This is a HACK!
// see https://github.com/Proskomma/proskomma-json-tools/issues/63
if (text !== 'NO_CAPTION') {
const divFigureText =
createIllustrationCaptionBlock(text);
workspace.figureDiv.append(divFigureText);
}
break;
}
case 'audioc':
Expand Down

0 comments on commit fa30de5

Please sign in to comment.