OscarGodson / EpicEditor

EpicEditor is an embeddable JavaScript Markdown editor with split fullscreen editing, live previewing, automatic draft saving, offline support, and more. For developers, it offers a robust API, can be easily themed, and allows you to swap out the bundled Markdown parser with anything you throw at it.
http://epiceditor.com
MIT License
4.25k stars 334 forks source link

No documentation for custom parser? #291

Closed mattiasnordqvist closed 11 years ago

mattiasnordqvist commented 11 years ago

Wiki seems empty: https://github.com/OscarGodson/EpicEditor/wiki/Using-A-Custom-Parser

Would like to know how I am intended to extend the standard parser.

OscarGodson commented 11 years ago

Yeah, and it wasn't always empty and for some reason Github lost the history. I'll add some docs here and if you say they make sense to you I'll put them on http://epiceditor.com/#custom-parsers


Custom Parsers

EpicEditor is set up to allow you to use any parser that accepts and returns a string. This means you can use any flavor of Markdown, process Textile, or even create a simple HTML editor/previewer (parser: false). The possibilities are endless. Just make the parser available and pass its parsing function to the EpicEditor setting and you should be all set. You can output plain text or HTML. Here's an example of a parser that could remove "bad words" from the preview:

var editor = new EpicEditor({
  parser: function (str) {
    var blacklist = ['foo', 'bar', 'baz'];
    return str.split(' ').map(function (word) {
      // If the word exists, replace with asterisks
      if (blacklist.indexOf(word) > -1) {
        return '****'
      }
      return word;
    }).join(' ');
  }
}).load();

Here's a Wiki to HTML parser by Remy Sharp used with EpicEditor:

var editor = new EpicEditor({
  parser: function (str) {
    return str.wiki2html();
  }
}).load();

For even more customization and optimization you can replace the default built-in processor on build. Running jake build parser=path/to/parser.js will override the default Marked build and replace it with your custom script.

mattiasnordqvist commented 11 years ago

Sure, it makes sense to me, but I have not verified that it actually works.

OscarGodson commented 11 years ago

OK, added to the README and index.html docs. If, whenever you use it, you find some bug with it or typo or something let me know.