I'm trying to load a text file to display in a pre
tag using jQuery. I would like to display all the text including the escape sequences like new line, tab and so on. If I use jQuery.get('log.cpp', function(data) { ...
and I try to display the text with:
var str = data.replace(/(?:\r\n|\r|\n)/g, '<br>');
$('#fileName').html(str);
Then many characters s like <>
and the text surrounded by those chars are not displayed at all. Since I try to load and display some source code, a line with #include <header>
will be presented as #include
only.
If i try to use the following:
var str = data.replace(/(?:\r\n|\r|\n)/g, '\n');
$('#fileName').text(str);
No tabs or new lines are presented on screen and the text is shown as one line only.
Any hint? Thank you very much