markItUp Markdown editor integration

deviantintegral - March 11, 2009 - 02:03
Project:Wysiwyg
Version:6.x-2.x-dev
Component:Editor - markItUp
Category:task
Priority:normal
Assigned:Unassigned
Status:needs work
Description

Hi,

I'm trying to make markitup work with Markdown. I'm running in to the fact that drupal_add_js() doesn't support passing in a function to evaluate at run time. I know that bigger things are in store for configs, but for now I'm just trying to get something functional. What I've done so far is create a new editor include for the markdown-version of markitup. Then, in the wysiwyg settings, you can choose between "markitup" and "markitup (markdown)" as needed.

To attempt to make functions work, the attached simply looks for strings starting with 'function' and attempts to eval() them. Obviously a better key would need to be used :). The problem though is that the for() loop breaks the anonymous function, as the value is the same for all applied instances.

Any suggestions for how to make this work? Or am I going off track? I really hope that your TODO note means you know how to do it and just haven't done it yet :)

AttachmentSize
markitup_markdown.patch10.57 KB

#1

sun - March 11, 2009 - 02:50

Interesting approach.

No, I don't have a master-plan for that @todo yet. However, since markItUp does

eval(button.call)();

...a possible approach would be to define a call interceptor in JS
var Drupal.wysiwyg.markitup.call = function () {
  var tryToDetermineClickedButton = this.caller;
  ...
};

But honestly, I don't know.

@see https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Ob...

#2

deviantintegral - March 11, 2009 - 16:11

Well, I got closer. To get it to work you have to "seal" variables by copying. However, I then ran into issues of scope; the closure didn't have access to the markItUp object so it couldn't properly query it.

Here what I have so far:

for (var ms in settings['markupSet']) {
    if (typeof(settings['markupSet'][ms].openWith) != 'undefined' && settings['markupSet'][ms].openWith.indexOf("function(") == 0) {
      var current = ms;
      var openString = settings['markupSet'][ms].openWith.substring(9, settings['markupSet'][ms].openWith.length - 1);
      settings['markupSet'][ms].openWith = function() {
        return eval(openString);
      };
    }

@sun, I couldn't determine what objecto to try attaching that to, as the 'markitup' object doesn't exist.

As I need this working now, I've hard-coded settings into the JS. I've attached that in case anyone else finds it interesting. While this implements the UI still for settings, if you use this note that none of them are actually used.

AttachmentSize
markitup_markdown_2.patch 12.34 KB

#3

sun - March 11, 2009 - 19:53
Title:Enable buttons requiring functions in Drupal.settings» markItUp Markdown editor integration

#4

deviantintegral - October 26, 2009 - 23:46

No major changes, just rerolling from the module folder as it should be.

AttachmentSize
397994_markitup_markdown_4.patch 12.11 KB

#5

jide - October 27, 2009 - 11:16

Great to see we go towards more supported editors !

 
 

Drupal is a registered trademark of Dries Buytaert.