Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bookmarklet for Markdownifying webpage selections
// Marker, a bookmarklet for Markdownifying webpage selections
// javascript:(function(){var p=document.createElement("p");p.innerHTML="<strong>Loading&hellip;</strong>";p.id="loadingp";p.style.padding="20px";p.style.background="#fff";p.style.left="20px";p.style.top=0;p.style.position="fixed";p.style.zIndex="9999999";p.style.opacity=".85";document.body.appendChild(p);document.body.appendChild(document.createElement("script")).src="https://gist.github.com/ttscoff/8078727/raw/Marker.js?x="+(Math.random());})();
(function () {
function callback() {
(function ($) {
var raw, userSelection;
if (window.getSelection) {
// W3C Ranges
userSelection = window.getSelection ();
// Get the range:
if (userSelection.getRangeAt)
var range = userSelection.getRangeAt (0);
else {
var range = document.createRange ();
range.setStart (userSelection.anchorNode, userSelection.anchorOffset);
range.setEnd (userSelection.focusNode, userSelection.focusOffset);
}
// And the HTML:
var clonedSelection = range.cloneContents ();
var div = document.createElement ('div');
div.appendChild (clonedSelection);
raw = div.innerHTML;
} else if (document.selection) {
// Explorer selection, return the HTML
userSelection = document.selection.createRange ();
raw = userSelection.htmlText;
} else {
raw = "";
}
raw = raw.replace(/(src|href)=\"(.*?)\"/g, function(match, p1, p2, offset, string) {
if (!/^http/.test(p2)) {
if (/^\//.test(p2))
var baselink = window.location.protocol + "//" + window.location.hostname;
else
var baselink = window.location.href.split("/").slice(0,-1).join("/") + "/";
return [p1,"=\"",baselink+p2,"\""].join('');
}
return match;
})
var showFrame = "0";
if (window.markerShowFrame !== undefined) {
switch (window.markerShowFrame) {
case 0:
case false: showFrame = "0"; break;
default: showFrame = "1";
}
}
var $form = $("<form>").attr("method", "post").attr("action", "http://heckyesmarkdown.com/go/")
.append($("<input name=html>").val(encodeURIComponent(raw)))
.append($("<input name=read>").val("0"))
.append($("<input name=output>").val("md"))
.append($("<input name=showframe>").val(showFrame))
.appendTo('body');
$form.submit();
})(jQuery.noConflict(true))
}
var s = document.createElement("script");
s.src = "https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js";
if (s.addEventListener) {
s.addEventListener("load", callback, false)
} else if (s.readyState) {
s.onreadystatechange = callback
}
document.body.appendChild(s);
})();
@akaleeroy

This comment has been minimized.

Copy link

akaleeroy commented Jul 21, 2018

What's the idea with [links as footnotes][1]? Why not [keep with the text](http://hecknothatsannoyingmarkdown.com)?

[1]: http://hecknothatsannoyingmarkdown.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.