wmd / apiExample.html

<!DOCTYPE html>
    <title>WMD API example</title>
    <p>You can disable WMD's auto-start behavior and take charge of creating editors yourself.</p>
    <p>Do "view source" to see the code for this example.</p>
      <a href="javascript:createInstance()">Create</a> -
      <a href="javascript:destroyInstance()">Destroy</a>
    <form id="myForm"></form>
    <script type="text/javascript">
        /***** Tell WMD not to start up automatically *****/
        // Set this *before* you load wmd.js
        // Otherwise you'll end up with two editors on top of each other!
        wmd_options = { autostart: false };
        var instances = [];
        function createInstance() {
            /***** Make sure WMD has finished loading *****/
            if (!Attacklab || !Attacklab.wmd) {
                alert("WMD hasn't finished loading!");
            // build the dom elements
            var form = document.getElementById("myForm");
            var textarea = document.createElement("textarea");
   = "500px";
            textarea.value = "Hi.";
            var previewDiv = document.createElement("div");
            /***** build the preview manager *****/
            var panes = {input:textarea, preview:previewDiv, output:null};
            var previewManager = new Attacklab.wmd.previewManager(panes);
            /***** build the editor and tell it to refresh the preview after commands *****/
            var editor = new Attacklab.wmd.editor(textarea,previewManager.refresh);
            // save everything so we can destroy it all later
            instances.push({ta:textarea, div:previewDiv, ed:editor, pm:previewManager});
        function destroyInstance() {
            var inst = instances.pop();
            if (inst) {
                /***** destroy the editor and preview manager *****/
                // remove the dom elements
    <script type="text/javascript" src="wmd/wmd.js""></script>