Skip to content

Commit

Permalink
Prevent adjacent textCombine spans from being merged (#232)
Browse files Browse the repository at this point in the history
Co-authored-by: Nigel Megitt <nigel.megitt@bbc.co.uk>
Co-authored-by: Simon Hailes <simon@yellaumbrella.tv>
  • Loading branch information
3 people committed Nov 21, 2022
1 parent a6ed5f4 commit ce3b1f4
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/js/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@

/* ignore tate-chu-yoku since line break cannot happen within */
e.textContent = isd_element.text;
e._isd_element = isd_element;

if (te) {

Expand Down Expand Up @@ -523,7 +524,7 @@

}

mergeSpans(linelist); // The earlier we can do this the less processing there will be.
mergeSpans(linelist, context); // The earlier we can do this the less processing there will be.

/* fill line gaps linepadding */

Expand Down Expand Up @@ -583,7 +584,7 @@
}
}

function mergeSpans(lineList) {
function mergeSpans(lineList, context) {

for (var i = 0; i < lineList.length; i++) {

Expand All @@ -594,7 +595,7 @@
var previous = line.elements[j - 1];
var span = line.elements[j];

if (spanMerge(previous.node, span.node)) {
if (spanMerge(previous.node, span.node, context)) {

//removed from DOM by spanMerge(), remove from the list too.
line.elements.splice(j, 1);
Expand Down Expand Up @@ -659,11 +660,16 @@
return undefined;
}

function spanMerge(first, second) {
function spanMerge(first, second, context) {

if (first.tagName === "SPAN" &&
second.tagName === "SPAN" &&
first._isd_element === second._isd_element) {
if (! first._isd_element) {
/* we should never get here since every span should have a source ISD element */
reportError(context.errorHandler, "Internal error: HTML span is not linked to a source element; cannot merge spans.");
return false;
}

first.textContent += second.textContent;

Expand Down

0 comments on commit ce3b1f4

Please sign in to comment.