Git Product home page Git Product logo

meg's Introduction

meg.js

meg.js is a parsing expression parser for HTML and Markdown. It is based on the insanely great peg.js by David Majda (@dmajda).

Note: While the transformatiom from Markdown to HTML is lossless, parsing HTML to Markdown is not. meg.js is designed to be used to help save data inside contenteditable elements in a (hopefully) more universal format.

Gettings Started

You have to install node.js if you haven't already.

After you have setup node run npm install. When all packages have been installed you can run:

  • grunt or grunt release to build the project (minified)
  • grunt test to run the test suite (via Karma).
  • grunt dev will build the project unminified.
  • grunt tdd if you want to write new tests and work on the project.

Grammar

For reference here is the grammar used to transform HTML to Markdown:

Char <- /[^<]/
LowerCase <- /[a-z]/
TagName <- LowerCase+
TextNode <- Char*
StartTag <- '<' TagName '>'
ClosingTag <- '</' TagName '>'
Element <- StartTag Content ClosingTag
Content <- Element / TextNode

while Content is the only starting expression. Char and LowerCase are terminal symbols.

Example Usage

var parser = meg(),
    result = parser.fromHTML('<div>This is an <em>example</em>!</div>');

    // result is "This is an *example*!"

You can also pass additional mutation rules to meg.js:

var parser = meg({ exp: /^sup$/, start: '^', end: '' }),
    result = parser.fromHTML('I am n<sup>2</sup>.');

    // result is "i am n²."

Warning: This feature is experimental, because it is not tested! For more informations see the tests.

meg's People

Contributors

sebald avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.