Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery/Javascript solution for converting wiki-text to HTML and vice versa?

For my web front end I have to implement subsets of the wiki-syntax in my system. Do I need to manually specify rules and reinvent the wheel? Is there an existing javascript library or jquery plugin that could help out with it?

For example a user enters == Header == Since this needs to get converted to a medium header for example (assuming medium is defined in this context as a span as below)

<span class="mediumHeader" id = "Header">Header</span>

Now when the user edits the above text I'm guessing it'll involve replacing the

<span...> ... </span> with ==...==

Now for every system I design this will be as per 'my rules' and will almost always have to reinvent the wheel. Is there something that I could use to ease this wiki to/from HTML transformation using Jquery/Javascript? I'm sure it's a problem with a known solution.

I would prefer to customize what's acceptable and what isn't i.e. I don't everything to be translated into wiki syntax (or HTML) only subsets of it. Should I just roll my own for my application?

like image 427
PhD Avatar asked Jul 01 '12 01:07

PhD


2 Answers

It's been long enough that you may not need this, but yours was the top SO hit when I started looking into it.

There are a couple javascript options - you're probably looking at instaview (check out test/test.js), or maybe Wiky.js (the less fully documented).

If you aren't limited to Javascript, check out the exhaustive list of MediaWiki parsers at http://www.mediawiki.org/wiki/Alternative_parsers - lots of tools for C++, Java, Perl, ruby, and more. That's the link to watch for new developments.

like image 110
henry Avatar answered Nov 09 '22 19:11

henry


At the time of writing, Parsoid seems to be the only one which translates in both directions. This one also powers the visual editor on Wikipedia. But this is no handy client-site lib to include in your app, but a full-blown parsing and transformation server suite. A production version of Parsoid on the Wikimedia cluster can be accessed at http://parsoid-lb.eqiad.wikimedia.org/.

Other JavaScript Libraries, which are translating from WikiText to HTML only (ordered by popularity), are:

  • Wiky.js - doesn't support full WikiText syntax. (by tanin47, not to be confused with Wiki.js from Requarks - a different project completely)
  • wtf_wikipedia - isn't directly translating to HTML but JSON, which results in much more powerful possiblities (e.g. info-boxes as key-value pairs). This is the most up-to-date library and "its a combination of instaview, txtwiki, and uses the inter-language data from Parsoid javascript parser."
  • instaview - no updates in the last 2 years.

Also checkout the current and full list of alternative MediaWiki parsers.

like image 5
david Avatar answered Nov 09 '22 20:11

david