user007
user007

Reputation: 81

Google Code Prettify with Markdown is not working

Google Code Prettify is working fine, but when I am using the Markdown content and show the content from the database, Prettify isn't working properly (link of live result).

This is what I am doing:

But in the result, the part I wrote in the code section is working fine if I don't use Markdown, but when I get the content from the textarea and use Markdown, it's not working.

Upvotes: 4

Views: 1546

Answers (2)

HenchHacker
HenchHacker

Reputation: 1626

Look at the HTML code. You missed the class="prettyprint" off the pre tag.

<pre><code>try {
    $db-&gt;beginTransaction();

    $db-&gt;exec("SOME QUERY");

    $stmt = $db-&gt;prepare("SOME OTHER QUERY?");
    $stmt-&gt;execute(array($value));

    $stmt = $db-&gt;prepare("YET ANOTHER QUERY??");
    $stmt-&gt;execute(array($value2, $value3));

    $db-&gt;commit();
} catch(PDOException $ex) {
    //Something went wrong rollback!
    $db-&gt;rollBack();
    echo $ex-&gt;getMessage();
}
</code></pre>

should be

<pre class="prettyprint"><code>try {
    $db-&gt;beginTransaction();

    $db-&gt;exec("SOME QUERY");

    $stmt = $db-&gt;prepare("SOME OTHER QUERY?");
    $stmt-&gt;execute(array($value));

    $stmt = $db-&gt;prepare("YET ANOTHER QUERY??");
    $stmt-&gt;execute(array($value2, $value3));

    $db-&gt;commit();
} catch(PDOException $ex) {
    //Something went wrong rollback!
    $db-&gt;rollBack();
    echo $ex-&gt;getMessage();
}
</code></pre>

To fix the problem of having <pre> auto generated, you can try this:

$newcontent = str_replace('<pre>', '<pre class="prettyprint">', $_POST['article_content']);

Upvotes: 2

suhailvs
suhailvs

Reputation: 21740

For auto generated <pre> you can also use:

$('pre').addClass('prettyprint');

Upvotes: 0

Related Questions