tmbrggmn / deck.js-markdown

A deck.js extension that adds support for Markdown syntax in slides
32 stars 5 forks source link

Markdown support breaks nested slides #1

Open tmbrggmn opened 13 years ago

tmbrggmn commented 13 years ago

Using this Markdown extension breaks the nested slides: nested slides are not displayed correctly any more (they are not displayed in the parent-slide, and are displayed as the next full slide).

tmbrggmn commented 13 years ago

This happens because of the value.html(converter.makeHtml(value.html())); call. In fact, calling value.html(value.html()); has the same effect as well. As soon as the HTML content of a nested section changes, the nested slides are broken and don't work any more (despite being identical to an unaltered set of nested slides).

tmbrggmn commented 13 years ago

This is exactly what happens, when going to the next slide which is a nested slide:

imakewebthings commented 13 years ago

@tmbrggmn Here's the problem: When you're processing a nested slide parent, setting the html with the converted value means you're replacing all of the child nodes with new ones. But the slides array has already been built at this point, and still references the old child slides. This is why the deck states never change on the nested slides, they aren't part of the slides array. (The child-current thing will resolve itself when you solve this problem.) Hope this makes sense.

You might have some preference on how to handle this. I can think of a few different approaches if you would like to hear them.

tmbrggmn commented 13 years ago

@imakewebthings Thanks for the feedback. The obvious solution would be to re-build the slides collection, but that may not be the best solution? I'd love to hear your suggestions!

imakewebthings commented 13 years ago

@tmbrggmn You certainly could, though you would need to look out for a few things:

You could construct a tree structure of the slides, then temporarily detach any children, process, reattach, dive down the tree, and repeat, but it seems like a lot of trouble.

You could just force the user to include the converter stuff before they call init, but that defeats the whole purpose of the plugin.

My preferred way to handle this would be: I add a 'deck.beforeInit' event at the top of the init method, after the options are set but before the slides array is created, where preprocessing like this can occur, and you just change the converter to convert the whole container;

$(document).bind('deck.beforeInit', function() {
   var $c = $.deck('getContainer');

   $c.html(new Markdown.Converter().makeHtml($c.html()));
});

If that sounds good I can add this event later today.

tmbrggmn commented 13 years ago

@imakewebthings Sounds good :-) Thanks for the help.

imakewebthings commented 13 years ago

@tmbrggmn Try the latest on my master branch. The event name is the same as I mentioned above.