开发者

How does the WMD editor like the one StackOverFlow uses work?

I'm interested in knowing how does the text you type on the text box doesn't require a page refresh? Some similar alternatives include:

开发者_Go百科

lixlpixel

But they tend to do a page refresh every time a keystroke is pressed...


They have a Markdown to HTML translator implemented in Javascript. Whenever the content of the 'textarea' changes the preview area is updated with the result of running the Markdown to HTML converter. There's obviously more to it than that -- making this sort of thing perform well can be tricky -- but that's the essence of it.

If you inspect the textarea in a browser like Safari you can see that they are using Javascript event handlers for drop, input, keydown, keypress, keyup, mousedown and paste events. When one of these events happen the script responds appropriately, including to run the Javacript Markdown-to-HTML converter and putting the resulting HTML into the preview area.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜