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:
Getting content with
<textarea name="article_content" id="wmd-input" class="wmd-panel"></textarea>
Then store output after (I am using PDO)
Markdown($_POST['article_content'])
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.
Advertisement
Answer
Look at the HTML code. You missed the class=”prettyprint” off the pre tag.
<pre><code>try { $db->beginTransaction(); $db->exec("SOME QUERY"); $stmt = $db->prepare("SOME OTHER QUERY?"); $stmt->execute(array($value)); $stmt = $db->prepare("YET ANOTHER QUERY??"); $stmt->execute(array($value2, $value3)); $db->commit(); } catch(PDOException $ex) { //Something went wrong rollback! $db->rollBack(); echo $ex->getMessage(); } </code></pre>
should be
<pre class="prettyprint"><code>try { $db->beginTransaction(); $db->exec("SOME QUERY"); $stmt = $db->prepare("SOME OTHER QUERY?"); $stmt->execute(array($value)); $stmt = $db->prepare("YET ANOTHER QUERY??"); $stmt->execute(array($value2, $value3)); $db->commit(); } catch(PDOException $ex) { //Something went wrong rollback! $db->rollBack(); echo $ex->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']);