Which data structure are used for commenting text and which algorithms take care for updating the comment position? A commenting feature is present in every good word processor such as Microsoft Word, Google Docs etc.
I can imagine two approaches: One would be surrounding the commented text with some sort of markup (e.g. XML tags), which implicitly stores the position of the comment inside of the commented text. The user doesn't get to see the the XML tags, since it gets parsed beforehand by the word processor.
The other approach could be storing an array of all comments and their positions and updating the positions as the commented text changes.
Are there other possible approaches? What could be the caveats of a specific implementation?