Client side HTML conversion

I am trying to create a client-side editor that allows the end user to create content in html or markdown. The user has two tabs for switching between them. I managed to find javascript that converts markdown to html, so if a user writes markdown and switches to the html tab, html equivilant is displayed. I could not find javascript that converts html to markdown, only a python script.

The python script is obviously a server. Tabs are just hyperlinks from a script. Is there any way to convert markdown HTML code when a user clicks on a tab?

+3
source share
4 answers

AJAX, , . jQuery , :

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

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

+2
source

Source: https://habr.com/ru/post/1736910/


All Articles