If you type the following characters into the WMD editor: [some] by themselves without wrapping them in backticks, firebug throws the following error:

K.replace is not a function

The odd thing is that I've only been able to reproduce this bug by typing those exact characters. Any other combination of letters inside the brackets do not produce the error.

It looks like the return statement in _DoAnchors() does a regex replace using the method writeAnchorTag, which does this:

m4 = escapeCharacters(m4, '*_');

The error happens at escapeCharacters on this line:

return text.replace(regex, escapeCharacters_callback);
  • It seems to be if you type any member of the Array type, so [concat] and [map] mess up too. some just happens to be one of them.
    – Tim Stone
    Commented Sep 15, 2010 at 21:48

2 Answers 2


The problem manifests itself in the g_urls cache array, which is used to lookup referenced URLs from elsewhere in the Markdown block when you use syntax like this:

[link text][id]

[id]: http://stackoverflow.com/

Markdown's syntax also lets you be lazy, which allowed you to more easily notice this bug. Consider the following, which also works:

[link text]

[link text]: http://stackoverflow.com/

You weren't trying to do that, but WMD can't read minds (...yet), so it went to look for the referenced URL anyway (since one wasn't specified yet), as part of writeAnchorTag():

if (url == "") {
    if (link_id == "") {
        // lower-case and turn embedded newlines into spaces
        link_id = link_text.toLowerCase().replace(/ ?\n/g," ");
    url = "#"+link_id;

    if (g_urls[link_id] != undefined) {
        url = g_urls[link_id];
        // ...
    // ...

Based on the above, [some] results in a link_id of some, and g_urls['some'] is defined, because g_urls is an array. This means that url becomes a reference to g_urls's some function, which makes it a pretty poor candidate for performing a string replace on in escapeCharacters().

A possible solution would either be to replace the array objects with plain ones, or use some sort of prefixing scheme on the keys.

  • Neat-o! Good of you to look into it so thoroughly. Worth coding in a conditional to catch these? maybe, maybe not.
    – Stephen
    Commented Sep 16, 2010 at 1:44
  • @Stephen: It does seem to break the preview box, so I think it would be nice to at least prevent the exception condition...but I'm just a curious investigator, so I guess we'll just have to wait and see if it's anything worth fixing. :)
    – Tim Stone
    Commented Sep 16, 2010 at 1:56

This will be fixed in the next build; thanks to Tim Stone for debugging this. We now use a prefix on the keys; just going with Object() instead of Array() would still have left __proto__ and constructor as a (albeit small) problem.

You must log in to answer this question.

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