Download & Extend

markItUp Markdown editor integration

Project:Wysiwyg
Version:6.x-2.x-dev
Component:Editor - markItUp
Category:task
Priority:normal
Assigned:Unassigned
Status:needs work

Issue Summary

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

Comments

#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.

AttachmentSize
markitup_markdown_2.patch 12.34 KB

#3

Title:Enable buttons requiring functions in Drupal.settings» markItUp Markdown editor integration

#4

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

AttachmentSize
397994_markitup_markdown_4.patch 12.11 KB

#5

Great to see we go towards more supported editors !

#6

I added more buttons. Namely the picture button, color palette, lorem ipsum and preview. The files placed in "markitup-markdown.zip" should go to the "sites/.../modules/wysiwyg/editors" folder. Then I also attached the button pictures (placed in "images.zip") that should go to "all/libraries/markitup/markitup/sets/markdown/images/".

AttachmentSize
markitup-markitdown.zip 4.97 KB
images.zip 785 bytes

#7

I think the patch in #5 is the best solution so far (however it has one small mistake, on line 13 it had an extra */). However both #5 #6 make assumptions about the location of the libraries folder relative to their current position and so break on my install (were i have contrib. in sites/.../contrib/), so some thought might need to be given to this.

#5 implements all the buttons made available by the stock markdown set available on the markitup site. However i think we should look for a more complete button set (as http://drupal.org/project/markdowneditor has).

Additionally (for what its worth), i REALLY dont like the popup method of adding URLS (i think just injecting some text with areas to edit would be better) and the code/blockquote button seems not to work?

#8

whoops, forgot the patch :)

AttachmentSize
397994_markitup_markdown_5.patch 12.11 KB

#9

subscribe

#10

Subscribe

#11

I took the patch from comment 8 and refactored it to work with the latest 7.x-2.x branch.

AttachmentSize
397994_markitup-markdown_11.patch 11.17 KB

#12

Subscribing

#13

subscribing

nobody click here