Skip to content

Instantly share code, notes, and snippets.

@saschpe
Created November 13, 2014 10:02
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 saschpe/19e3033ff663950d6951 to your computer and use it in GitHub Desktop.
Save saschpe/19e3033ff663950d6951 to your computer and use it in GitHub Desktop.
GreaseMonkey User Script to convert (all) texteareas into HTML editors (powerered by CodeMirror)
// ==UserScript==
// @name CodeMirror HTML Textareas
// @namespace saschpe
// @description Instanciate a CodeMirror HTML editor for every textarea...
// @author Sascha Peilicke <saschpe@mailbox.org>
// @include example.com
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// @require http://cdnjs.cloudflare.com/ajax/libs/codemirror/4.7.0/codemirror.min.js
// @require http://cdnjs.cloudflare.com/ajax/libs/codemirror/4.7.0/mode/css/css.min.js
// @require http://cdnjs.cloudflare.com/ajax/libs/codemirror/4.7.0/mode/javascript/javascript.min.js
// @require http://cdnjs.cloudflare.com/ajax/libs/codemirror/4.7.0/mode/xml/xml.min.js
// @require http://cdnjs.cloudflare.com/ajax/libs/codemirror/4.7.0/mode/htmlmixed/htmlmixed.min.js
// @require http://cdnjs.cloudflare.com/ajax/libs/codemirror/4.7.0/mode/htmlembedded/htmlembedded.min.js
// @resource cm_css http://cdnjs.cloudflare.com/ajax/libs/codemirror/4.7.0/codemirror.min.css
// @version 1.1
// @grant GM_addStyle
// @grant GM_getResourceText
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
GM_addStyle(GM_getResourceText("cm_css"));
GM_addStyle(".CodeMirror { border: 1px solid #eee; }");
$(function () {
$("textarea").each(function() {
CodeMirror.fromTextArea($(this)[0], {
mode: "htmlembedded",
indentWithTabs: false,
indentUnit: 4,
lineWrapping: true,
lineNumbers: true,
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment