views:

114

answers:

2

Hello, I've been trying to create a client side editor which allows the end user to create content in html or markdown. The user has two tabs for switching between the two. I managed to find some javascript that converts markdown to html, so if a user has been writing markdown and switches to the html tab, the html equivilant is shown. I haven't been able to find a javascript that converts html to markdown, only a python script.

The python script is obviously server side. The tabs are just hyperlinks with script in there. Is there any way I can convert the markdown html when the user clicks the tab?

+2  A: 

You only have to send data to server using AJAX, perform conversion on server and then return results back to the browser. In jQuery this is as simple as e.g.:

$.ajax({
    type: "GET",
    url: <converter url>,
    data: <html>
    success: function(markdown_text){
        $('#id_container').text(markdown_text);
    }
    error: function(XMLHttpRequest, textStatus, errorThrown){
             alert('Error!');
    }
});
Tomasz Zielinski
A: 

Why don't you use WMD-Editor? It has the ability to preview the html.

jpartogi