phpwmd-editor

WMD editor not working in edit form


I am using WMD editor. This one.

It is working fine. But issue is, i want to get it working with edit form.

Right now i am getting html instead of markdown text. My code is like following in my edit page.

<div id="wmd-editor" class="wmd-panel">
    <div id="wmd-button-bar"></div>
            <textarea id="wmd-input"><?php echo $row['description']?></textarea>
    </div>
    <div id="wmd-preview" class="wmd-panel"></div>
    <div id="wmd-output" class="wmd-panel"></div>

Not sure what is wrong here.


Solution

  • First off: the repository is not maintained (and apparently has not been updated for over 7 years) so you should consider switching to an active branch. WMD was renamed to Page Down but there are many alternative editors out there you can use.

    As timclutton commented you are probably storing HTML in your database. WMD does not support conversion from HTML to Markdown. So the best solution would be to store the content as Markdown.

    To do this change your create page. Since I have no code I'll just give you an example on how it could look:

    <form action="/create" method="POST">
        <div id="wmd-editor" class="wmd-panel">
            <div id="wmd-button-bar"></div>
                <textarea name="content" id="wmd-input"></textarea>
            </div>
        <div id="wmd-preview" class="wmd-panel"></div>
        <div id="wmd-output" class="wmd-panel"></div>
        <button type="submit">Send</button>
    </form>
    

    Server-side you can now store the content of $_POST['content'] in your database and later output it exactly the way you are doing it right now to the edit page.


    Lastly a security note from the Page Down wiki:

    It should be noted that Markdown is not safe as far as user-entered input goes. Pretty much anything is valid in Markdown, in particular something like <script>doEvil();</script>. This PageDown repository includes the two plugins that Stack Exchange uses to sanitize the user's input; see the description of Markdown.Sanitizer.js below.