endpnt / andoc

collaborative web tool to enrich content
GNU General Public License v3.0
11 stars 1 forks source link

html escaping and text selections #8

Open endpnt opened 12 years ago

endpnt commented 12 years ago

For every saved selection, the start and end position based on the original raw plain text data is calculated and saved. As soon as the raw data has to be escaped for HTML rendering, those start and end positions become invalid.

The single char < or > or & becomes a & a m p ; etc and JS seems to count those as 5 instead of 1 in the range object.

This is messing up all offsets and the selections don't get applied or wrongly applied while rendering selections.

Also, new selections by the user will probably contain wrong start and end positions if there is any escaped character in the document.

currently < and > are translated as [ and ] to avoid the problem.

related function: https://github.com/endpnt/andoc/blob/master/static/andoc.js#L115

this code finds all escaped chars https://github.com/endpnt/andoc/blob/master/static/andoc.js#L124

here the html should be escaped with |e instead of the |replace(... hack https://github.com/endpnt/andoc/blob/master/templates/doc/raw.html#L46