Skip to content

Commit

Permalink
Merge branch 'staging' into dependabot/npm_and_yarn/follow-redirects-…
Browse files Browse the repository at this point in the history
…1.15.6
  • Loading branch information
angrave authored Apr 29, 2024
2 parents 4d7f441 + d6ae442 commit 779bbe5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/screens/EPub/controllers/file-builders/HTMLFileBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ class HTMLFileBuilder {
// let transcriptStart = curText.indexOf('<p>'); // use DOM
let transcriptAllPara = Array.prototype.slice.call(currText_dom.getElementsByTagName("p"),0); // gets all paragraph tags
let combinedImagePara = allImages.concat(transcriptAllPara);

// Span tags contain LaTeX, which cannot currently be rendered properly in PDFs. Thus, we remove them
let span_tags = Array.prototype.slice.call(currText_dom.getElementsByTagName("span"));
for (let span_idx = 0; span_idx < span_tags.length; span_idx+=1) {
let curr_span_tag = span_tags[span_idx];
curr_span_tag.replaceWith("");
}

for(let k = 0; k < combinedImagePara.length; k+=1) {
let currElement = combinedImagePara[k];
if(currElement.tagName.toLowerCase() === "img") {
Expand Down
21 changes: 20 additions & 1 deletion src/screens/EPub/controllers/file-builders/ScreenshotsBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,29 @@ class ScreenshotsBuilder {
// let transcriptStart = chapter.text.indexOf("<p>");
// let transcriptEnd = chapter.text.indexOf("</p>");
let all_text = parser.parseFromString(chapter.text, "text/html");

// Replace MathML with P tags containing the LaTeX
let latex = Array.prototype.slice.call(all_text.getElementsByTagName("span"));
for (let latex_idx = 0; latex_idx < latex.length; latex_idx+=1) {
let curr_tag = latex[latex_idx];
if (curr_tag.getAttribute("title")) {
let annotation = `$$${curr_tag.getAttribute("title")}$$`;
let new_p_tag = document.createElement('p');
new_p_tag.innerHTML = annotation;
curr_tag.replaceWith(new_p_tag);
} else if (curr_tag.parentElement.tagName === "P") {
let annotation = curr_tag.getElementsByTagName("annotation");
if (annotation) {
annotation = `$${annotation[0].innerHTML}$`;
curr_tag.replaceWith(annotation);
}
}
}

let all_paragraphs = Array.prototype.slice.call(all_text.getElementsByTagName("p"),0);

for(let ind = 0; ind < all_paragraphs.length; ind+=1) {
let transcript = all_paragraphs[0].innerHTML; // get the inner html of each paragraph transcript
let transcript = all_paragraphs[ind].innerHTML; // get the inner html of each paragraph transcript
transcript = transcript.replaceAll("%", "\\%");
chapterContent = chapterContent.concat(transcript, '\n');
}
Expand Down

0 comments on commit 779bbe5

Please sign in to comment.