#line 3592 "/home/travis/build/felix-lang/felix/src/packages/flx_web.fdoc"
  include "./edit-interface";
  
  fun setup(config_data:string) = {
    eprintln$ "Setup fdoc_edit " + config_data;
    return 0;
  }
  
  var mime-to-file =
    list (
      ("text/x-felix", "flx_codemirror/mode/felix/felix.js"),
      ("text/x-ocaml", "codemirror/mode/mllike/mllike.js"),
      ("text/x-csrc", "codemirror/mode/clike/clike.js"),
      ("text/x-c++src", "codemirror/mode/clike/clike.js"),
      ("text/x-python", "codemirror/mode/python/python.js"),
      ("text/html", "codemirror/mode/htmlmixed/htmlmixed.js"),
      ("application/xml", "codemirror/mode/xml/xml.js"),
      ("text/s-tex", "codemirror/mode/stex/stex.js"),
      ("text/css", "codemirror/mode/css/css.js")
    )
  ;
  
  object fdoc_edit () implements edit-interface_t = {
    method fun whatami () => "fdoc edit";
    method fun get_header (filename:string, mimetype:string) =>
      let modefile =
         match Assoc_list::find mime-to-file mimetype with
         | Some f => f
         | #None => "flx_codemirror/felix/felix.js"
         endmatch
      in
  
      "<title>"+filename+"</title>" +
      '''
      <link rel="stylesheet" href="/share/src/codemirror/lib/codemirror.css">
      <link rel="stylesheet" href="/share/src/codemirror/addon/fold/foldgutter.css">
      <script src="/share/src/codemirror/lib/codemirror.js"></script>
      <script src="/share/src/'''+modefile+'''"></script>
      <script src="/share/src/codemirror/addon/edit/matchbrackets.js"></script>
      <script src="/share/src/codemirror/addon/fold/foldcode.js"></script>
      <script src="/share/src/codemirror/addon/fold/foldgutter.js"></script>
      <script src="/share/src/codemirror/addon/fold/brace-fold.js"></script>
      <script src="/share/src/codemirror/addon/fold/comment-fold.js"></script>
      <style>.CodeMirror {border: 2px inset #dee; height:auto; }</style>
      <style>.CodeMirror-scroll {overflow-x: hidden; overflow-y:auto; }</style>
      '''
    ;
    method fun get_body (id:string, mime:string, text:string) =>
     '<form action="doedit" method="post" enctype="text/plain">'+
     '<input type="submit" value="Save"><br>'+
     '<textarea id="'+id+'" name="code">'+
     text +
     '</textarea></form>' +
      '''
      <script>
        var editor = CodeMirror.fromTextArea(document.getElementById("'''+id+'''"), {
          lineNumbers: true,
          lineWrapping: true,
          matchBrackets: true,
          smartIndent: false,
          viewportMargin: Infinity,
          extraKeys: {"Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor()); }},
          foldGutter:true,
          gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
          mode: "'''+mime+'''"
        });
      </script>
      '''
    ;
  
  }
  
  export fun setup of (string) as "fdoc_edit_setup";
  export fun fdoc_edit of () as "fdoc_edit";