This is quite a talked about problem on the jQuery forums but I can\'t figure out a solution for my situation.
I have an unordered list with some text elements in th
Here is a far simpler solution to convert any HTML into plain text with line breaks based on the use of or tags.
function htmlDecodeWithLineBreaks(html) {
var breakToken = '_______break_______',
lineBreakedHtml = html.replace(/
/gi, breakToken).replace(/(.*?)<\/p>/gi, breakToken + '$1' + breakToken);
return $('
').html(lineBreakedHtml).text().replace(new RegExp(breakToken, 'g'), '\n');
}
For example, calling the following method:
htmlDecodeWithLineBreaks('line 1
line & 2
' +
'line > 3paragraph 1
line 4')
returns:
line 1
line & 2
line > 3
paragraph 1
line 4
Hope that helps ;)