WMD - How to get the generated\Markdown HTML Code
Asked Answered
K

2

-1

well i got WMD but i am unable to learn how to get the generated HTML\Markdown Code.... i want to send it to the DB... thats why i am using PHP....

<script src='wmd.js'></script>

<form name="formname" method='POST'>

<textarea id="myTextarea" style="width: 500px; height: 200px;">
*This* example sets WMD's options programmatically.
</textarea>

<input type="submit" name="sub" value="submit">

</form>

<!--Preview Can Be Seen Here-->
<div class="wmd-preview" id="wmd"></div>

<?php
if( isset( $_POST['sub'] ) )
{
       $generated_HTML = "How to get it here";
}
?>

now can anyone please tell me how to get the generated HTML...

Knipe answered 1/9, 2010 at 9:50 Comment(0)
Z
2

The WMD editor is just a client-side text editor that supports the input of markdown-formatted text. To convert markdown to HTML you'll need a markdown parser.

A quick google tells me there's at least one available: http://michelf.com/projects/php-markdown/

Zsolway answered 1/9, 2010 at 9:53 Comment(4)
got to WMD WebSite wmd-editor.com/examples/splitscreen and switch to Advanced Mode... then selct preview HTML from Slectbox\Combo Box... they are not using any parser...Knipe
.. can you gimme some Code Sample pleaseKnipe
I see that demo page is using a client-side markdown parser implemented in Javascript, called "Showdown" (notice a file called "showdown.js" gets downloaded). Try picking the demo apart and see if you can work out how it's done.Zsolway
Stuart you were right the first time... see my self posted answerKnipe
K
0

get these files wmd.js & markdown.php

and use the follwing code

<script src="wmd.js"></script>
<script type="text/javascript">

wmd_options = {output: "HTML",lineLength: 40,buttons: "bold italic | link image | ol ul heading hr",autostart: true};

</script>

<form name="formname" method="post" action="">
<textarea id="myTextarea" style="width: 500px; height: 200px;" name="TA"></textarea>
<br><input type="submit" name="KILL"     value="Submit">
</form>

<?php
if(  isset( $_POST['kil'] ) )
{
    $my_text = $_POST['tr'];
    include ('markdown.php');
    $my_html = Markdown($my_text);
    echo $my_html;
        //$send $myhtml to database or do something with
}
?>
Knipe answered 1/9, 2010 at 11:51 Comment(2)
Yep, this is the approach I was getting at. The demo you sent clearly shows a way to invoke a client-side parser, although the page was pretty impenetrable.Zsolway
impenetrable yeah... some damn coder who knows all the hooks & crooks wrote that code :) so viewing source won't be a help for learners & copiersKnipe

© 2022 - 2024 — McMap. All rights reserved.