More progress with apparatus rendering
Added some refinements to the code which provides the apparatus interactivity. The key problem we're solving is the requirement that when the user clicks on the lemma in an apparatus item, the poem line should pop up, with the lemma highlighted inside it. This has a couple of implications:
- We can only work with the plain text of the line, not the actual HTML tags in the line, because we need to match the text of the lemma against the text of the line in order to provide the highlighting. Therefore...
- ...we can't show a fully rendered line (with e.g. deletions showing a line-through) because the HTML tags have to be removed.
- For an effective comparison (enabling highlighting), both the lemma and the line must be normalized (all spaces and returns reduced to a single space, and leading and trailing spaces trimmed), otherwise a potential match between a lemma and the line that contains it could be derailed by some ignorable whitespace that's carried over from the XML, or is a byproduct of the XSLT transformation.
Further, we have to make sure that only some of the text which is actually in the line is rendered; for instance, the explanations of abbreviations must be suppressed, as must line numbers.
This morning, I've expanded the JavaScript considerably, to provide normalization functions. I've also refined the routine that renders the line HTML to text (getElementText()), so that you can supply it with an argument consisting of an array of classnames to be ignored. That enables us to extract only the bits of text we want, and ignore, for instance, explanations of abbreviations. Finally, I've tweaked the XSLT so that lines with an empty lemma (where, say, the line doesn't exist in the base text) are not made into links at all.