I'm writing an userscript that should add some functionality to the main textarea (WMD) used to post and edit answers and questions. The functionality will usually need to do things like insert text on caret position, do something with selection and so on.

I'm pretty sure these features are already abstractly implemented in the script associated with the textarea. How can I figure what functions should I call?

1 Answer 1


The markdown code supposedly lives at the pagedown project on code.google.com. (Reference)

You may also find these files to be useful:

Personally, I find it easier to just use normal <textarea> processing followed by a call to StackExchange.MarkdownEditor.refreshAllPreviews(). You can see that in action in this handy userscript.

StackExchange.MarkdownEditor has these tempting functions (¿not particularly documented?):

  • balanceTags()
  • refreshAllPreviews()
  • sanitizeHtml()

Tangential PS: To help with related searches...

WMD stands for Wysiwym MarkDown.

From wmd-editor.com (archived):

So WMD is something new: a Wysiwym Markdown editor.

  • Wysiwym stands for What You See Is What You Mean. WMD produces clean semantic HTML, leaving presentation details like fonts and colors up to style sheets. But you're not left in the dark about cosmetics; as you type, WMD's live preview shows you exactly what your text will look like after the current styles have been applied.
  • I really want to avoid re-inventing caret operations. I went through this once and even adapting the old code sounds like too much work for me. But thanks anyway, I'll surely return to this post. Commented Nov 19, 2014 at 0:45
  • Well, you don't have to reinvent anything. The first half of the answer gives the source and the files where SE uses it. Commented Nov 19, 2014 at 0:49
  • Oh sorry, I thought these are markdown source codes. Commented Nov 19, 2014 at 0:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .