Remove existing formatting of csv cell copied into text editor in django

217 Views Asked by At

I have made a forums website in Django. The textarea for entering question has NicEdit integrated for formatting purpose. However if I copy a cell from a CSV file and paste it into the textarea and save it, the database has some extra tags added along with it. Example: On copying a cell which contains this info:

Audio in this file is not clear. Not only in this file but also in some files. Please check it.

and pasting it in textarea and saving, the way it is getting saved in the database is

\r\n\t\r\n\t\r\n\t\r\n\t\tbody,div,table,thead,tbody,tfoot,tr,th,td,p { font-family:"Liberation Sans"; font-size:x-small }\r\n\t\ta.comment-indicator:hover + comment { background:#ffd; position:absolute; display:block; border:1px solid black; padding:0.5em; } \r\n\t\ta.comment-indicator { background:red; display:inline-block; border:1px solid black; width:0.5em; height:0.5em; } \r\n\t\tcomment { display:none; } \r\n\t\r\n\t\r\n\r\n\r\n\r\n\r\n\t\r\n\t\r\n\t\t\r\n\t\r\nAudio in this file is not clear. Not only in this file but also in some files. Please check it.

As a result, I'm unable to get the proper results for further use of this data. Is there any way I can remove this excessive formatting in python? As I'm working in django and fetching data from views.py I need to do this in python and I'm unable to do it till now. Currently I have a regex filter to remove html tags but it'd be better if I'm able to remove this complete formatting(html+css) in one go.

0

There are 0 best solutions below