adam-p / markdown-here

Google Chrome, Firefox, and Thunderbird extension that lets you write email in Markdown and render it before sending.
http://markdown-here.com
MIT License
59.64k stars 11.26k forks source link

Support Zotero standalone #92

Open jlegewie opened 11 years ago

jlegewie commented 11 years ago

Hi! Markdown here is great and I would like to get it to work in Zotero notes. Zotero is a great, open source reference manager. It exists as a Firefox addon and a standalone version that is also based on Firefox. Accordingly, Firefox addon can easily run in Zotero with some small adjustments. Markdown here already works in Zotero Firefox but it doesn't for the Standalone version. Adding this code to the install.rdf allows to install markdown here as a zotero addon but it still produces some errors in the console and it's also not possible to access any of the functions. I think one of the problem is related to the overlay files and I get an error TypeError: win.gBrowser is undefined in the console.

    <em:targetApplication>
        <Description>
            <em:id>zotero@chnm.gmu.edu</em:id>
            <em:minVersion>3.0b1</em:minVersion>
            <em:maxVersion>4.*</em:maxVersion>
        </Description>
    </em:targetApplication>

Are the markdown here developers interested in making it compatible with Zotero. It would take some time but I could look into the code and maybe prepare a pull request if the developer are interested in supporting Zotero.

adam-p commented 11 years ago

I spent some time trying to get this to work. You can see the branch changes here: https://github.com/adam-p/markdown-here/compare/master...zotero-support

How it works and doesn't:

Debugging was a total pain.

I need to do some regression testing on the other platforms (note to self: especially this), but I could probably roll these changes out in a release. It kinda works.

It's unlikely that I'm going to make this work right by myself (except maybe the rendering problem). Hopefully someone else (you, @jlegewie?) will take over.

jlegewie commented 11 years ago

This is great! I also did some work on a fork, which you can see here. So unfortunately, we worked on this separately so far. My approach uses a toolbar button based on XUL overlay. The solution is okay but placing it in the TinyMCE stuff would be better. I am not sure whether that is possible though. One limitation of overlaying Zotero is that markdown here doesn't work in separate note windows (notes open in separate windows when you double click on them).

I also added a 'Markdown Options' menu item, which opens the options window but it's impossible to change anything. I tried to understand what the problem is but wasn't able to pin it down. You suggest that it's the contentscript-backgroundscript message passing but I am not sure how to solve this.

I also wasn't able to get the optionsURL in install.rdf to work in Zotero Standalone. Maybe you found a solution for that.

Anyways, I suggest that I integrate my overlay code into your fork. I think the main limitation is the problem with the options window but I am not sure how to solve this. Also note that I changed the icon because your really nice icon didn't really fit into the zotero UI (the small size of the Zotero icons and the slightly grey background). I will revert that change for the pull request so that you can see for yourself.

adam-p commented 11 years ago

Did you manage to get DOMInspector or any other debugging extensions installed? It's driving me nuts to have to work blind.

The solution is okay but placing it in the TinyMCE stuff would be better. I am not sure whether that is possible though.

Yeah, I really don't know if it's possible. Maybe something like this?

  1. Create a XBL widget that inherits from Zotero's note-editor widget.
  2. Overlay note.xul and replace the default zoteronoteeditor element with a markdownherezoteronoteeditor (or whatever) element. (I don't know how to "replace" with an overlay, but surely it's possible?)
  3. In our overlay.css file (don't click that -- it's an empty file), map markdownherezoteronoteeditor to our new XBL widget -- like Zotero does with its widget.
  4. Do something magical in our XBL widget that allows us to add to the context menu and formatting toolbar. And maybe hotkeys.
  5. ...profit!

Alternate: Assuming our overlay CSS takes precedence, instead of replacing the zoteronoteeditor element, we can override its CSS binding rule to point to our inherited binding. And... I tried that with the main window edit pane and the editor disappeared completely. I think the inheritance isn't working. Dunno why.

One limitation of overlaying Zotero is that markdown here doesn't work in separate note windows (notes open in separate windows when you double click on them).

I failed to notice that last night. I tried overlaying note.xul, which I believe is the separate note window, but I can't seem to get it to actually do anything. Like, it seems that the overlay is non-functional. (Maybe I'm screwing it up. I'm not a pro-star at this.)

I also added a 'Markdown Options' menu item, which opens the options window but it's impossible to change anything.

Did you get the options values loading? Or just a bunch of empty text boxes?

I tried to understand what the problem is but wasn't able to pin it down. You suggest that it's the contentscript-backgroundscript message passing but I am not sure how to solve this.

Yeah, dunno. The problem seems to be that the message (event) sent here is not being received here.

(I only have the vaguest sense of how that stuff works in the first place. Like, how can a listener in the background script document really get events fired in a different document? But it works in Firefox and Thunderbird...)

I also wasn't able to get the optionsURL in install.rdf to work in Zotero Standalone. Maybe you found a solution for that.

https://github.com/adam-p/markdown-here/blob/zotero-support/src/install.rdf#L73

I think the main limitation is the problem with the options window but I am not sure how to solve this.

I think "doesn't work in the popup editor" is pretty bad too.

jlegewie commented 11 years ago

There is way to use a DOM inspector for Zotero. Install Zotero for FF and open Zotero as a tab. In this mode, the build in DOM inspector (or firebug) should work. Let me know if you are having problems with this solution and I can send more precise instructions.

I have no idea about the XBL widget approach but I will look at the note.xul overlay idea and see whether I can figure something out about that.

Nothing loaded in the options window except preview and the "reset to default bottom worked for other parts. By the way, you can also check about:config in Zotero Standalone through Actions->Preferences->Advanced->Open about:config. The markdown here options don't show up among the preferences.

It's also the case

adam-p commented 11 years ago

@jlegewie Did you get cut off there?

jlegewie commented 11 years ago

Yeah, I guess but I don't remember what I was going to say. I have to finished some stuff over the next days and will look at the note.xul overlay when I am done. I can also send a pull request for the overlay I used in my fork but I think that only makes sense when we are sure that there isn't a better solution.

adam-p commented 11 years ago

There is way to use a DOM inspector for Zotero. Install Zotero for FF and open Zotero as a tab. In this mode, the build in DOM inspector (or firebug) should work. Let me know if you are having problems with this solution and I can send more precise instructions.

I hadn't tried to use the in-browser Zotero, just the standalone. But now I have...

I got DOM Inspector working fine. I don't know how to use Firebug to inspect chrome.

Nothing loaded in the options window except preview and the "reset to default" bottom worked for other parts.

Yeah, that's what I saw as well. Retrieving the options is just not working. (The "reset to default" does a local XHR, which works fine, but is a different kind of thing.)

By the way, you can also check about:config in Zotero Standalone through Actions->Preferences->Advanced->Open about:config. The markdown here options don't show up among the preferences.

That's because the options access isn't working. You can go into Firefox's about:config and search for "markdown-here" and copy keys/values from there into Zotero and it will work. (Like add a new boolean item with the name extensions.markdown-here.math-enabled and the value true and now the TeX stuff will work.)

Going to write more in a separate comment...

adam-p commented 11 years ago

I have managed to overlay the note.xul window, but not satisfactorily. I couldn't get the overlay line in chrome.manifest to actually work, and I suspect that it might not be possible to overlay XUL that's instantiated with a window.open call (I'm guessing). So, I used document.loadOverlay to overlay the XUL after the fact. Here's the code:

var win;
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
                   .getService(Components.interfaces.nsIWindowMediator);
// Enumerate all the open windows.
var enumerator = wm.getEnumerator(null);
while(enumerator.hasMoreElements()) {
  win = enumerator.getNext();
  // Assume that the one we want has a "chrome://zotero" location.
  // It'll actually be chrome://zotero/content/note.xul
  if (win.document.location.origin.indexOf('zotero') >= 0) break;
}

// Overlay that window
win.document.loadOverlay('chrome://markdown_here/content/zotero-note-overlay.xul', null);

And it "works". But since this is happening well after the window is loaded, I don't think there's anything useful that can be done. Maybe there's some window-opening event to hook into and do this? Or maybe we can trigger a post-overlay reload (of some magical sort that doesn't lose our overlay... which might not be possible)?

I also managed to extend and override the zoteronoteeditor.

chrome://markdown_here/content/zotero-note-overlay.xul:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="chrome://markdown_here/skin/overlay.css" type="text/css"?>
<overlay id="markdown_here-zotero-note-overlay" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
</overlay>

chrome://markdown_here/skin/overlay.css:

zoteronoteeditor
{
  -moz-binding: url('chrome://markdown_here/content/bindings.xml#markdown-here-zotero-note-editor');
}

chrome://markdown_here/content/bindings.xml#markdown-here-zotero-note-editor

<?xml version="1.0"?>
<bindings   xmlns="http://www.mozilla.org/xbl"
      xmlns:xbl="http://www.mozilla.org/xbl"
      xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">

  <binding id="markdown-here-zotero-note-editor"
           extends="chrome://zotero/content/bindings/noteeditor.xml#note-editor">

    <content>
      <xul:vbox xbl:inherits="flex">
        <xul:label value="OH HI"/>
      </xul:vbox>
    </content>

  </binding>

</bindings>

This results in only "OH HI" showing in the window, but DOM inspector suggests that the XBL inheritance is intact. I think that the problem is that this overriding is happening after the window setup is done (like, JS init of TinyMCE, blah). It's hard to sure, though.

I need to stop messing around with this for now. I have a million other things I should be doing...

adam-p commented 11 years ago

The code I checked in is a bit bad. This line needs to be removed and these lines need to be commented out. Can't return if not in a function.

(That change will be in the development branch soon-ish.)

bisraelsen commented 9 years ago

Is this working? Or has it been abandoned?

adam-p commented 8 years ago

I haven't looked at Zotero support since my last comment.

derekwolfson commented 8 years ago

I'm quite interested in this -- is it dead? or just barely breathing? I can find other word arounds, but Markdown zotero notes would be AWESOME!

malaybasu commented 8 years ago

Yes. This would awesome.

Erotemic commented 8 years ago

agreed

dmhowcroft commented 7 years ago

I also want Markdown as an option. I don't even care about integrating HTML preview or anything--I just want my notes box to be plain-text (with softwrapping / visual linewrap) instead of HTML.

janjaapmeijer commented 6 years ago

Ideally with support for equations (e.g. MathJax)

marbetschar commented 4 years ago

Any chance we can get an officiall release with the current state of work for Zotero (as a ready to install xpi)?

I understand there are some rough edges, but from what I can tell the extension works "good enough": I installed and tested the extension using the one provided by https://github.com/fei0810/markdownhere4zotero - even LaTeX works with it.

But I'd rather prefer installing the extension from the official sources than from any 3rd party.

kathep commented 4 years ago

I'd also like to see this official release. Anyone?