I’m relatively new to Elm, and I’m trying to make an engine to display text annotations. For a given text, I have character offset locations which describe places in the text that are highlighted and annotated. For example, (251, 542, "This part is especially interesting!)
and (300, 642, "and also this part!)
, representing overlapping regions of text.
How would I go about approaching this problem? I know that overlapping tags aren’t allowed in HTML or the DOM, or any kind of tree structure. So one solution might be to wrap all text in <span>
s, avoiding any other tags, such that this:
Here is some text to be annotated. And now the parargraph ends. </p>
<p>And another paragraph begins, with some <emph>emphasized</emph> text.</p>
becomes this:
<span class="highlight">Here is some text to be annotated. And now the parargraph ends. </span></p>
<p><span class="highlight">And another paragraph begins, with some </span><emph><span class="highlight">emphasized</span></emph><span class="highlight"> text.</span></p>
But this is already getting really complex, and I wouldn’t know how to do that in Elm. Would it be:
- treat the DOM HTML as a string, and find the text corresponding to its character offsets,
- then find all the elements within those offsets
- then surround their inner HTML with
<span>
?
Alternatively, maybe there’s a way to draw rectangles over text, corresponding to a region of text, such that the rectangles can overlap?
Or, has anyone successfully integrated something like [annotator}(GitHub - openannotation/annotator: Annotation tools for the web. Select text, images, or (nearly) anything else, and add your notes.) into an Elm project?
I have a feeling that Elm would be a tool for this, but I’m at a loss for how to begin even thinking about it.