Last chance before blackout
I've changed tab with spaces and re-made the diff (couldn't test it, though).
As for my changes, you can just replace your '__add_kobo_spans_to_node()' with mine and add '__append_kobo_spans_from_text()' just before it.
(There is a minor change in 'add_kobo_spans()', I initialize 'segment_counter' to 1 instead than 0, but this should not be a problem)