markItUp Markdown editor integration
| Project: | Wysiwyg |
| Version: | 6.x-2.x-dev |
| Component: | Editor - markItUp |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
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 :)
| Attachment | Size |
|---|---|
| markitup_markdown.patch | 10.57 KB |

#1
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
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.
#3
#4
No major changes, just rerolling from the module folder as it should be.
#5
Great to see we go towards more supported editors !