refactory-id / bootstrap-markdown

Bootstrap plugin for markdown editing
Apache License 2.0
1.99k stars 371 forks source link

Feature request: support for server side rendered preview via ajax #200

Open aruizca opened 8 years ago

aruizca commented 8 years ago

Currently there is no callback function available to update the preview content once the ajax request to parse the original content has completed. Thanks!

aruizca commented 8 years ago

Something like this:

        onPreview: function (e) {
          var content = e.getContent();
          $.post("/misc/preview",{data: content}, function (data) {
            e.setPreviewContent(data);
          });
        }

at the moment this is what I do, but I might be missing some other steps:

        onPreview: function (e) {
          var content = e.getContent();
          $.post("/misc/preview",{data: content}, function (data) {
            $('.md-preview').html(data);
          });
        }
toopay commented 8 years ago

Hey @aruizca

The onPreview hook expecting string as return value, so i guess you could use synchronuous call to your server, and return the result at the end of the hook callback.

lorentzkim commented 7 years ago

I've made a PR #306 that attempts to implement setPreview() as @aruizca has wanted.

Async call would be helpful so server-side rendering of markdown is identical to in-editor preview. Not all of us render and have javascript stack for whole applications, so this would be really useful.