cakephpwmd-editor

Using the WMD editor with CakePHP


I'm using the WMD editor https://github.com/derobins/wmd/ (similar to as used on Stack Overflow) to create a WYSIWIG editor to allow users to create HTML-based posts on my application.

It works fine when posting and saves the HTML into the DB great. The problem is when I come to edit the post again it shows the actual HTML inside the textarea. How do I stop this?

EDIT: After some thought it would seem I have to save the content AS markdown in the database and NOT as HTML right? Hence why the Html is coming back rather than nice content?


Solution

  • According to this blog and this StackOverflow answer, you can tell WMD to save as markdown instead of HTML by opening the wmd.js file and changing

    Attacklab.wmd_defaults = {version:1, output:"HTML", lineLength:40, delayLoad:false};
    

    to

    Attacklab.wmd_defaults = {version:1, output:"markdown", lineLength:40, delayLoad:false};
    

    NOTE: It seems common practice (and supposedly what StackOverflow does) to save both the markdown version and the sanitized html version in the database so you don't need to translate it before showing each time. (Then, when it's edited, just overwrite the HTML version as well).