Skip to content

Instantly share code, notes, and snippets.

@printminion
Created May 18, 2017 14:18
Show Gist options
  • Select an option

  • Save printminion/395ad38df8863150788eaab24bbcfc9f to your computer and use it in GitHub Desktop.

Select an option

Save printminion/395ad38df8863150788eaab24bbcfc9f to your computer and use it in GitHub Desktop.
codemirror for magento
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
(function(mod) {
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror", "../htmlmixed/htmlmixed"], mod);
else // Plain browser env
mod(CodeMirror);
})(function(CodeMirror) {
"use strict";
CodeMirror.defineMode("htmlmagento", function(config, parserConfig) {
var inner = CodeMirror.getMode({}, "magento");
var outer = CodeMirror.getMode({}, "htmlmixed");
var innerOptions = {
open: '{{',
close: '}}',
mode: inner,
delimStyle: 'delim',
innerStyle: 'inner',
};
return CodeMirror.multiplexingMode(outer, innerOptions);
}, "htmlmixed");
CodeMirror.defineMIME("text/htmlmagento", "htmlmagento");
});
<!doctype html>
<title>CodeMirror: Html Embedded Scripts mode</title>
<meta charset="utf-8"/>
<link rel=stylesheet href="../../doc/docs.css">
<link rel="stylesheet" href="../../lib/codemirror.css">
<link rel="stylesheet" href="../../addon/hint/show-hint.css">
<link rel="stylesheet" href="../../addon/fold/foldgutter.css" />
<script src="../../lib/codemirror.js"></script>
<script src="../../addon/edit/closetag.js"></script>
<script src="../../addon/hint/show-hint.js"></script>
<script src="../../addon/hint/xml-hint.js"></script>
<script src="../../addon/hint/html-hint.js"></script>
<script src="../../addon/hint/javascript-hint.js"></script>
<script src="../../addon/mode/multiplex.js"></script>
<script src="../xml/xml.js"></script>
<script src="../../addon/edit/matchtags.js"></script>
<script src="../../addon/fold/foldcode.js"></script>
<script src="../../addon/fold/foldgutter.js"></script>
<script src="../../addon/fold/brace-fold.js"></script>
<script src="../../addon/fold/xml-fold.js"></script>
<script src="../../addon/fold/indent-fold.js"></script>
<script src="../../addon/fold/markdown-fold.js"></script>
<script src="../../addon/fold/comment-fold.js"></script>
<script src="../javascript/javascript.js"></script>
<script src="../../addon/selection/active-line.js"></script>
<script src="../css/css.js"></script>
<script src="../htmlmixed/htmlmixed.js"></script>
<script src="htmlmagento.js"></script>
<style type="text/css">.CodeMirror {border-top: 1px solid black; border-bottom: 1px solid black;}</style>
<div id=nav>
<a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
<ul>
<li><a href="../../index.html">Home</a>
<li><a href="../../doc/manual.html">Manual</a>
<li><a href="https://github.com/codemirror/codemirror">Code</a>
</ul>
<ul>
<li><a href="../index.html">Language modes</a>
<li><a class=active href="#">Html Embedded Scripts</a>
</ul>
</div>
<article>
<h2>Html Embedded Scripts mode</h2>
<form><textarea id="code" name="code">
This is an example of Magento HTML
<p>{{widget type="mage/core" template="mage/default.phtml"}}</p>
<p><img src="{{media url="wysiwyg/image.jpg"}}" alt="" width="980" height="250" /></p>
<hr />
<p>{{block type="mage/bar" name="foo_1" template="foo/bar.phtml"}}</p>
</textarea></form>
<script>
var editor = CodeMirror.fromTextArea(document.getElementById("code"), {
lineNumbers: true,
mode: "text/htmlmagento",
indentUnit: 4,
lineWrapping: true,
indentWithTabs: true,
styleActiveLine: true,
matchTags: {bothTags: true},
foldGutter: true,
autoCloseTags: true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter"],
extraKeys: {"Ctrl-Space": "autocomplete", "Ctrl-J": "toMatchingTag", "Ctrl-Q": function(cm){ cm.foldCode(cm.getCursor())}},
});
</script>
<p>Mode for html embedded scripts for Magento. Depends on HtmlMixed which in turn depends on
JavaScript, CSS and XML.<br />Other dependancies include those of the scriping language chosen.</p>
<p><strong>MIME types defined:</strong>
<code>text/htmlmagento</code> (Magenot HTML)</p>
</article>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment