alphapapa / org-protocol-capture-html

Capture HTML from the browser selection into Emacs as org-mode content
453 stars 39 forks source link

Firefox Bookmarkelet Script Troubleshooting #46

Closed OmarAshkar closed 4 years ago

OmarAshkar commented 4 years ago

Hello, I have org-capture-extension working and also this bookmarkelet script.

javascript:location.href="org-protocol:///capture?template=p&url="+encodeURIComponent(location.href)+"&title="+encodeURIComponent(document.title||"[untitled page]")

Which indicated that org-protocol is working. The problem with this script is that it doesn't fetch the selected text at all.

However, for the proposed bookmarkelt in the repo

javascript:location.href = 'org-protocol://capture-html?template=w&url=' + encodeURIComponent(location.href) + '&title=' + encodeURIComponent(document.title || "[untitled page]") + '&body=' + encodeURIComponent(function () {var html = ""; if (typeof document.getSelection != "undefined") {var sel = document.getSelection(); if (sel.rangeCount) {var container = document.createElement("div"); for (var i = 0, len = sel.rangeCount; i < len; ++i) {container.appendChild(sel.getRangeAt(i).cloneContents());} html = container.innerHTML;}} else if (typeof document.selection != "undefined") {if (document.selection.type == "Text") {html = document.selection.createRange().htmlText;}} var relToAbs = function (href) {var a = document.createElement("a"); a.href = href; var abs = a.protocol + "//" + a.host + a.pathname + a.search + a.hash; a.remove(); return abs;}; var elementTypes = [['a', 'href'], ['img', 'src']]; var div = document.createElement('div'); div.innerHTML = html; elementTypes.map(function(elementType) {var elements = div.getElementsByTagName(elementType[0]); for (var i = 0; i < elements.length; i++) {elements[i].setAttribute(elementType[1], relToAbs(elements[i].getAttribute(elementType[1])));}}); return div.innerHTML;}());

I am getting either: "Geedy protocol Handeler. Killing Client" or "No Server buffer remains to edit."

I have followed all the instructions and installations, but I think it's all about doom emacs sequence. Not sure as I can't debug it and I don't know which should go after which.

  (use-package! org-protocol-capture-html
    :after org-protocol
    :config
    (add-to-list 'org-capture-templates
                 '("w" "Web site2"  entry
                   (file+headline "~/test.org")
                   "* ")
                 )

Here is the snippet I use, which basiclly says to load org-protocol-capture after org-protocol.

I hope to find a solution for this issue.

Best Regards, Omar

alphapapa commented 4 years ago

Please see https://github.com/alphapapa/org-protocol-capture-html/issues/40.