javascript showdown, markdown not parsing correctly

I have a confusing problem.

I have two files, both that run showdown. However, it seems that only one file parses correctly.

Here’s the deal.

File 1 is run through PHP and AJAX.

File 2 is grabbed via an AJAX request. The file that processes the ajax request contains this code.

Here is the ajax

As you can see, the jQuery code that puts the details onto the screen are exactly the same apart from the variables and the JSON string instead of a direct string from the database.

Now file #1 doesn’t parse the markdown correctly, where file two does…

Here is a screenshot of files #1 and #2

File #1

file one not working

File #2

file two working

Any idea on what could possibly be causing this? Also, any ideas on a fix?

Answer

Ok,

So it seems it was the parsing of the line breaks in the file… However we have changed it from
as this is causing the issue of the markdown parsing incorrectly to double escaped

so it now reads

$copy = preg_replace("/n/", "\\n", $js_r->copy);
$copy = preg_replace("/r/", "\\r", $copy);

which works correctly and parses both files efficiently