Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the easiest way to convert Wiki markup to HTML? [closed]

Tags:

html

markup

wiki

I'm building a website that requires very basic markup capabilities. I can't use any 3rd party plugins, so I just need a simple way to convert markup to HTML. I might have a total of 3 tags that I'll allow.

What is the best way to convert ==Heading== to <h2>Heading</h2>, or --bold-- to <b>bold</b>? Can this be done simply with Regex, or does somebody have a simple function?

I'm writing this in C#, but examples from other languages would probably work.

like image 491
Jim Avatar asked Sep 05 '08 15:09

Jim


3 Answers

Maybe this is what you need.

This page is a compilation of links, descriptions, and status reports of the various alternative MediaWiki parsers — that is, programs and projects, other than MediaWiki itself, which are able or intended to translate MediaWiki's text markup syntax into something else.

like image 134
wener Avatar answered Oct 01 '22 03:10

wener


This really depends on the Wiki syntax you're using as there are several different ones. Obviously the wiki software has this functionality somewhere; if you can't find a software package that does this for you, you could start looking for the relevant code in your wiki software.

like image 27
pix0r Avatar answered Oct 01 '22 02:10

pix0r


It's not really a simple problem, because if you're going to display things back to the user, you'll need to also sanitise the input to ensure you don't create any cross site scripting vulnerabilities.

That said, you could probably do something pretty simple as you describe most easily with a regular expression replacement.

For example

replace the pattern ==([^=]*)== with <h2>\1</h2>
like image 31
Matt Sheppard Avatar answered Oct 01 '22 02:10

Matt Sheppard