Skip to content

Instantly share code, notes, and snippets.

@neworld
Last active March 9, 2018 15:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neworld/242770b5efb1939b51842587d5f41b03 to your computer and use it in GitHub Desktop.
Save neworld/242770b5efb1939b51842587d5f41b03 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Markdown img to html converter
// @namespace neworld
// @version 0.2.0
// @description Converts markdown img tag to html
// @author Neworld
// @match https://*.github.com/*
// @grant none
// @run-at context-menu
// ==/UserScript==
function convertMDtoHTML(textArea) {
var text = textArea.value;
var regex = /!\[.*?\]\((.*?)\)/g;
var subst = '<img src="\$1" width="250"/>';
var result = text.replace(regex, subst);
textArea.value = result;
}
function arrayHasOwnIndex(array, prop) {
return array.hasOwnProperty(prop) && /^0$|^[1-9]\d*$/.test(prop) && prop <= 4294967294; // 2^32 - 2
}
(function() {
'use strict';
var areas = document.getElementsByTagName("textarea");
for (var key in areas) {
if (arrayHasOwnIndex(areas, key)) {
convertMDtoHTML(areas[key]);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment