Skip to content

Instantly share code, notes, and snippets.

@max
Created February 3, 2015 00:34
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 max/02317c06eb5fda632773 to your computer and use it in GitHub Desktop.
Save max/02317c06eb5fda632773 to your computer and use it in GitHub Desktop.
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
"use strict";
!(function (e) {
if ("object" == typeof exports) module.exports = e();else if ("function" == typeof define && define.amd) define(e);else {
var f;"undefined" != typeof window ? f = window : "undefined" != typeof global ? f = global : "undefined" != typeof self && (f = self), f.Curse = e();
}
})(function () {
var define, module, exports;return (function e(t, n, r) {
var s = function (o, u) {
if (!n[o]) {
if (!t[o]) {
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);throw new Error("Cannot find module '" + o + "'");
}var f = n[o] = { exports: {} };t[o][0].call(f.exports, function (e) {
var n = t[o][1][e];return s(n ? n : e);
}, f, f.exports, e, t, n, r);
}return n[o].exports;
};
var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) s(r[o]);return s;
})({ 1: [function (_dereq_, module, exports) {
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
/**
* Captures and restores the cursor position inside of an HTML element. This
* is particularly useful for capturing, editing, and restoring selections
* in contenteditable elements, where the selection may span both text nodes
* and element nodes.
*
* var elem = document.querySelector('#editor');
* var curse = new Curse(elem);
* curse.capture();
*
* // ...
*
* curse.restore();
*
* @class Curse
* @constructor
* @param {HTMLElement} element an element to track the cursor inside of
*/
var Curse = (function () {
var Curse = function (element) {
var _ref = arguments[1] === undefined ? {} : arguments[1];
var lineBreak = _ref.lineBreak;
var nodeLengths = _ref.nodeLengths;
this.lineBreak = lineBreak;
this.nodeLengths = nodeLengths || {};
this.element = element;
this.reset();
};
_prototypeProperties(Curse, null, {
iterator: {
/**
* An iterator to iterate over the nodes in `this.element`.
*
* This returns a simple node iterator that skips `this.element`, but not its
* children.
*
* @property iterator
* @private
* @type {NodeIterator}
*/
get: function () {
var elem = this.element;
return document.createNodeIterator(this.element, NodeFilter.SHOW_ALL, function onNode(node) {
return node === elem ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
});
},
enumerable: true,
configurable: true
},
capture: {
/**
* Captures the current selection in the element, by storing "start" and
* "end" integer values. This allows for the text and text nodes to change
* inside the element and still have the Curse be able to restore selection
* state.
*
* A `<br>` tag, for example, is counted as a single "character", while
* a text node with the text "Hello, world" is counted as 12 characters.
*
* @method capture
*/
value: function capture() {
var _window$getSelection = window.getSelection();
var anchorNode = _window$getSelection.anchorNode;
var anchorOffset = _window$getSelection.anchorOffset;
var focusNode = _window$getSelection.focusNode;
var focusOffset = _window$getSelection.focusOffset;
var child = undefined,
start = undefined,
end = undefined;
if (anchorNode === null || focusNode === null) {
this.reset();
return;
}
if (anchorNode.nodeName === "#text") {
start = this.lengthUpTo(anchorNode) + anchorOffset;
} else {
child = anchorNode.childNodes[anchorOffset ? anchorOffset - 1 : 0];
start = this.lengthUpTo(child);
}
if (focusNode.nodeName === "#text") {
end = this.lengthUpTo(focusNode) + focusOffset;
} else {
child = focusNode.childNodes[focusOffset ? focusOffset - 1 : 0];
end = this.lengthUpTo(child) + this.nodeLength(child);
}
this.start = start;
this.end = end;
},
writable: true,
enumerable: true,
configurable: true
},
restore: {
/**
* Restore the captured cursor state by iterating over the child nodes in the
* element and counting their length.
*
* @method restore
* @param {Boolean} [onlyActive=true] only restore if the curse's element is
* the active element
*/
value: function restore() {
var onlyActive = arguments[0] === undefined ? true : arguments[0];
if (onlyActive && document.activeElement !== this.element) {
return;
}
if (!onlyActive) {
this.element.focus();
}
var range = document.createRange();
var idx = 0;
var _ref2 = this;
var start = _ref2.start;
var end = _ref2.end;
var iter = this.iterator;
var node = undefined,
setStart = undefined,
setEnd = undefined;
if (this.start > this.end) {
start = this.end;
end = this.start;
}
while (node = iter.nextNode()) {
if (setStart && setEnd) {
break;
}
var nodeLength = this.nodeLength(node);
var isText = node.nodeName === "#text";
var childIdx = undefined;
if (!setStart && start <= idx + nodeLength) {
if (isText) {
range.setStart(node, start - idx);
} else {
childIdx = this.indexOfNode(node);
range.setStart(node.parentNode, childIdx);
}
setStart = true;
}
if (!setEnd && end <= idx + nodeLength) {
if (isText) {
range.setEnd(node, end - idx);
} else {
childIdx = this.indexOfNode(node);
range.setEnd(node.parentNode, childIdx);
}
setEnd = true;
}
idx += nodeLength;
}
var selection = window.getSelection();
selection.removeAllRanges();
// Reverse the selection if it was originally backwards
if (this.start > this.end) {
var startContainer = range.startContainer;
var startOffset = range.startOffset;
range.collapse(false);
selection.addRange(range);
selection.extend(startContainer, startOffset);
} else {
selection.addRange(range);
}
},
writable: true,
enumerable: true,
configurable: true
},
indexOfNode: {
/**
* Get the index of a node in its parent node.
*
* @method indexOfNode
* @private
* @param {Node} child the child node to find the index of
* @returns {Number} the index of the child node
*/
value: function indexOfNode(child) {
var i = 0;
while (child = child.previousSibling) {
i++;
}
return i;
},
writable: true,
enumerable: true,
configurable: true
},
lengthUpTo: {
/**
* Get the number of characters up to a given node.
*
* @method lengthUpTo
* @private
* @param {Node} node a node to find the length up to
* @returns {Number} the length up to the given node
*/
value: function lengthUpTo(lastNode) {
var len = 0;
var iter = this.iterator;
var node = undefined;
while (node = iter.nextNode()) {
if (node === lastNode) {
break;
}
len += this.nodeLength(node);
}
return len;
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
/**
* Reset the state of the cursor.
*
* @method reset
* @private
*/
value: function reset() {
this.start = null;
this.end = null;
},
writable: true,
enumerable: true,
configurable: true
},
nodeLength: {
/**
* Get the "length" of a node. Text nodes are the length of their contents,
* and `<br>` tags, for example, have a length of 1 (a newline character,
* essentially).
*
* @method nodeLength
* @private
* @param {Node} node a Node, typically a Text or HTMLElement node
* @return {Number} the length of the node, as text
*/
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = undefined;
if (this.lineBreak) {
previousSibling = node.previousElementSibling;
}
if (previousSibling && previousSibling.classList.contains(this.lineBreak)) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return Curse;
})();
module.exports = Curse;
}, {}] }, {}, [1])(1);
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],2:[function(require,module,exports){
(function (global){
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.miniprism=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";
/*
* The syntax parsing algorithm in this file is copied heavily from Lea Verou's
* Prism project, which bears this license:
*
* MIT LICENSE
*
* Copyright (c) 2012-2013 Lea Verou
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var grammars = _dereq_("./grammars");
exports.grammars = grammars;
exports.highlight = function highlight(source, grammarName) {
var opts = arguments[2] === undefined ? {} : arguments[2];
var grammar = undefined;
if (typeof grammarName === "string") {
grammar = grammars[grammarName];
}
if (typeof grammarName === "object" && grammarName.constructor === Object) {
grammar = grammarName;
}
if (!grammar) {
throw new Error("Grammar \"" + grammarName + "\" not found.");
}
return stringify(encode(tokenize(source, grammar)), opts.lineClass);
};
function tokenize(source, grammar) {
var strings = [source];
var inlines = grammar.inlines;
if (inlines) {
// jshint -W089
for (var inlineToken in inlines) {
grammar[inlineToken] = inlines[inlineToken];
}
delete grammar.inlines;
}
for (var token in grammar) {
var patterns = grammar[token];
if (!Array.isArray(patterns)) {
patterns = [patterns];
}
for (var i = 0; i < patterns.length; i++) {
var pattern = patterns[i];
var block = pattern.block;
var classes = pattern.classes;
var inside = pattern.inside;
var lookbehind = !!pattern.lookbehind;
var lookbehindLength = 0;
var tag = undefined;
if (pattern.tag) {
tag = pattern.tag;
} else {
tag = block ? "div" : "span";
}
pattern = pattern.pattern || pattern;
for (var _i = 0; _i < strings.length; _i++) {
var string = strings[_i];
if (typeof string !== "string") {
continue;
}
pattern.lastIndex = 0;
var match = pattern.exec(string);
if (!match) {
continue;
}
if (lookbehind) {
lookbehindLength = match[1].length;
}
var from = match.index - 1 + lookbehindLength;
match = match[0].slice(lookbehindLength);
var len = match.length;
var to = from + len;
var before = string.slice(0, from + 1);
var after = string.slice(to + 1);
var args = [_i, 1];
if (before) {
args.push(before);
}
var wrapped = {
block: block,
classes: classes,
tag: tag,
text: inside ? tokenize(match, inside) : match,
token: token
};
args.push(wrapped);
if (after) {
args.push(after);
}
Array.prototype.splice.apply(strings, args);
}
}
}
return strings;
}
function stringify(source) {
var lineClass = arguments[1] === undefined ? "md-line" : arguments[1];
if (source === "\n") {
return "<br>";
}
if (typeof source === "string") {
return source.replace(/\n/g, "");
}
if (Array.isArray(source)) {
return source.reduce(function addItem(result, item) {
return result + stringify(item, lineClass);
}, "");
}
var tag = source.tag;
var classList = source.classes || source.token.split(" ");
var className = classList.map(function (token) {
return "md-" + token;
}).join(" ");
if (source.block) {
className += " " + lineClass;
}
return ["<" + tag + " class=\"" + className + "\">", stringify(source.text, lineClass), "</" + tag + ">"].join("");
}
function encode(src) {
if (Array.isArray(src)) {
return src.map(encode);
} else if (typeof src === "object") {
src.text = encode(src.text);
return src;
} else {
return escapeHTML(src);
}
}
function escapeHTML(str) {
return str.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/\//g, "&#x2F;");
}
},{"./grammars":2}],2:[function(_dereq_,module,exports){
"use strict";
exports.markdown = _dereq_("./markdown");
},{"./markdown":3}],3:[function(_dereq_,module,exports){
"use strict";
/*
* These regexes are in some places copies of, in others modifications of, and
* in some places wholly unrelated to the Markdown regexes found in the
* Stackedit project, which bears this license:
*
* StackEdit - The Markdown editor powered by PageDown.
* Copyright 2013 Benoit Schweblin (http://www.benoitschweblin.com)
* Licensed under an Apache License (http://www.apache.org/licenses/LICENSE-2.0)
*/
exports.gfm = {
block: true,
pattern: /^`{3}.*\n(?:[\s\S]*?)\n`{3} *(?:\n|$)/gm,
inside: {
"gfm-limit": {
block: true,
pattern: /^`{3}.*(?:\n|$)/gm,
inside: {
"gfm-info": {
lookbehind: true,
pattern: /^(`{3}).+(?:\n|$)/
},
"gfm-fence": /^`{3}(?:\n|$)/gm
}
},
"gfm-line": {
block: true,
pattern: /^.*(?:\n|$)/gm
} }
};
exports.blank = [{
block: true,
pattern: /\n(?![\s\S])/mg
}, {
block: true,
pattern: /^\n/mg
}];
exports["setex-h1"] = {
block: true,
pattern: /^.+\n=+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^=].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^=+[ \t]*(?:\n|$)/
}
}
};
exports["setex-h2"] = {
block: true,
pattern: /^(?!^- ).+\n-+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^-].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^-+[ \t]*(?:\n|$)/
}
}
};
exports.code = {
block: true,
pattern: /^(?: {4,}|\t).+(?:\n|$)/gm
};
// h1 through h6
for (var i = 1; i < 7; i++) {
exports["h" + i] = {
classes: ["h" + i, "has-folding"],
block: true,
pattern: new RegExp("^#{" + i + "} .*(?:\n|$)", "gm"),
inside: {
"hash folding": new RegExp("^#{" + i + "} ")
}
};
}
exports.ul = {
classes: ["ul", "has-folding"],
block: true,
pattern: /^[ \t]*(?:[*+\-])[ \t].*(?:\n|$)/gm,
inside: {
"ul-marker folding": /^[ \t]*(?:[*+\-])[ \t]/
}
};
exports.ol = {
block: true,
pattern: /^[ \t]*(?:\d+)\.[ \t].*(?:\n|$)/gm,
inside: {
"ol-marker": /^[ \t]*(?:\d+)\.[ \t]/
}
};
exports.blockquote = {
block: true,
pattern: /^ {0,3}> *.*(?:\n|$)/gm,
inside: {
"blockquote-marker": /^ {0,3}> */
}
};
exports.hr = {
block: true,
pattern: /^(?:[*\-_] *){3,}(?:\n|$)/gm
};
exports["link-def"] = {
block: true,
pattern: /^ {0,3}\[.*?\]:[ \t]+.+(?:\n|$)/gm,
inside: {
"link-def-name": {
pattern: /^ {0,3}\[.*?\]:/,
inside: {
"bracket-start": /^\[/,
"bracket-end": /\](?=:$)/,
colon: /:$/
}
},
"link-def-value": /.*(?:\n|$)/
}
};
exports.p = {
block: true,
pattern: /^.+(?:\n|$)/gm,
inside: {}
};
// jshint -W101
exports.link = {
classes: ["link", "has-folding"],
pattern: /\[(?:(?:\\.)|[^\[\]])*\]\([^\(\)\s]+(?:\(\S*?\))??[^\(\)\s]*?(?:\s(?:['‘][^'’]*['’]|["“][^"”]*["”]))?\)/gm,
inside: {
"bracket-start folding": {
pattern: /(^|[^\\])\[/,
lookbehind: true
},
ref: /(?:(?:\\.)|[^\[\]])+(?=\])/,
"bracket-end folding": /\](?=\s?\()/,
"paren-start folding": /^\(/,
"paren-end folding": /\)$/,
"href folding": /.*/
}
};
// jshint +W101
exports["link-ref"] = {
classes: ["link-ref", "has-folding"],
pattern: /\[(?:.*?)\] ?\[(?:.*?)\]/g,
inside: {
"ref-value folding": {
pattern: /\[[^\[\]]+\]$/,
inside: {
"bracket-start": /\[/,
"ref-href": /[^\[\]]+(?=]$)/,
"bracket-end": /\]/
}
},
"ref-text": {
pattern: /^\[[^\[\]]+\]/,
inside: {
"bracket-start folding": /^\[/,
ref: /^[^\[\]]+/,
"bracket-end folding": /\]$/
}
}
}
};
exports.em = {
classes: ["em", "has-folding"],
pattern: /(^|[^\\])(\*|_)(\S[^\2]*?)??[^\s\\]+?\2/g,
lookbehind: true,
inside: {
"em-marker folding": /(?:^(?:\*|_))|(?:(?:\*|_)$)/
}
};
exports.strong = {
classes: ["strong", "has-folding"],
pattern: /([_\*]){2}(?:(?!\1{2}).)*\1{2}/g,
inside: {
"strong-marker folding": /(?:^(?:\*|_){2})|(?:(?:\*|_){2}$)/
}
};
exports["inline-code"] = {
classes: ["inline-code", "has-folding"],
pattern: /(^|[^\\])`(\S[^`]*?)??[^\s\\]+?`/g,
lookbehind: true,
inside: {
"inline-code-marker folding": /(?:^(?:`))|(?:(?:`)$)/
}
};
var inlines = {
strong: exports.strong,
em: exports.em,
link: exports.link,
"inline-code": exports["inline-code"],
"link-ref": exports["link-ref"]
};
["setex-h1", "setex-h2", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "blockquote", "p"].forEach(function (token) {
exports[token].inside.inlines = inlines;
});
["em", "strong"].forEach(function (token) {
exports[token].inside = exports[token].inside || {};
exports[token].inside.inlines = {
link: exports.link,
"link-ref": exports["link-ref"]
};
});
},{}]},{},[1])
(1)
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./types/constants").PRE;
var blocks = require("./grammar").blocks;
var Null = require("./types").Null;
var OL = require("./types").OL;
var miniprism = _interopRequire(require("miniprism"));
// Standard inlines:
var inlines = miniprism.grammars.markdown.p.inside.inlines;
var slice = Array.prototype.slice;
var Block = (function () {
function Block(editor, _ref) {
var node = _ref.node;
var pre = _ref.pre;
var source = _ref.source;
var type = _ref.type;
this.editor = editor;
this.type = type || new Null();
this.pre = pre || "";
this.content = source;
this.node = node || this.type.createNode();
this.render(true); // (isFirstRender)
}
_prototypeProperties(Block, null, {
source: {
get: function () {
if (this.type.constructor === OL) {
var children = this.node.parentElement ? slice.call(this.node.parentElement.childNodes) : [];
var digit = children.indexOf(this.node) + 1;
return "" + digit + ". " + this._content;
} else {
return this.pre + this._content;
}
},
enumerable: true,
configurable: true
},
content: {
get: function () {
if (this.type.isHeading) {
return "" + this.pre + "" + this._content;
} else {
return this._content;
}
},
set: function (content) {
this._content = content;
var match = undefined,
type = undefined;
if (this.type.isHeading && !content) {
this.type = new Null();
this.pre = "";
}
if (!this.type.shouldReparse) {
return;
}
// jshint -W089
for (var i = 0, len = blocks.length; i < len; i++) {
type = blocks[i];
if (match = content.match(type.pattern)) {
break;
}
}
this.type = type;
this._content = "";
match = match.slice(1);
var labels = type.labels;
for (var i = 0, len = match.length; i < len; i++) {
if (labels[i] === PRE) {
this.pre = match[i];
} else {
this._content += match[i];
}
}
},
enumerable: true,
configurable: true
},
html: {
get: function () {
if (this.type.isHeading) {
return "<span class=\"md-pre\">" + esc(this.pre) + "</span>" + ("" + miniprism.highlight(this._content, inlines));
} else {
return miniprism.highlight(this._content, inlines);
}
},
enumerable: true,
configurable: true
},
shouldContinue: {
get: function () {
return this.type.continues && this.content;
},
enumerable: true,
configurable: true
},
type: {
get: function () {
return this._type;
},
set: function (type) {
this.adjustedPre = false;
this.pre = "";
return this._type = type;
},
enumerable: true,
configurable: true
},
appendTo: {
value: function appendTo(node) {
this.type.appendChild(this.node, node);
},
writable: true,
enumerable: true,
configurable: true
},
clone: {
value: function clone() {
return new this.constructor(this.editor, {
node: this.node.cloneNode(true),
pre: this.pre,
source: this.content,
type: this.type
});
},
writable: true,
enumerable: true,
configurable: true
},
continueFrom: {
value: function continueFrom(block) {
this.type = block.type;
this.pre = block.pre;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
var isFirstRender = arguments[0] === undefined ? false : arguments[0];
if (this.content === this.node.textContent && !isFirstRender) {
return;
}
var oldNode = this.node;
var oldType = this.type;
if (!isFirstRender) {
this.content = this.node.textContent;
}
this.editor.curse.capture();
if (oldType !== this.type) {
this.node = this.type.createNode();
this.type.replaceNode(this.node, oldNode);
}
/*
* Adjust the Curse for `pre` since it is about to be removed from the
* DOM during `#render`. This does not apply to reparsing types, as their
* `pre` is still displayed when focused.
*/
if (!this.adjustedPre && !this.type.shouldReparse) {
this.editor.curse.start -= this.pre.length;
this.editor.curse.end -= this.pre.length;
this.adjustedPre = true;
}
if (this.content) {
this.node.innerHTML = this.html;
} else {
this.node.innerHTML = "<br>";
}
this.editor.curse.restore();
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
value: function reset() {
this.type = new Null();
this.content = this.content;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
selectionSubstring: {
value: function selectionSubstring(sel) {
var anchorNode = sel.anchorNode;
var focusNode = sel.focusNode;
var anchorOffset = sel.anchorOffset;
var focusOffset = sel.focusOffset;
var start = 0;
var end = Infinity;
var curse = this.editor.curse;
if (this.node.contains(anchorNode)) {
start = curse.lengthUpTo(anchorNode) - curse.lengthUpTo(this.node.firstChild) + anchorOffset;
if (this.type.isList) {
start += this.pre.length;
}
}
if (this.node.contains(focusNode)) {
end = curse.lengthUpTo(focusNode) - curse.lengthUpTo(this.node.firstChild) + focusOffset;
if (this.type.isList) {
end += this.pre.length;
}
}
return this.source.substring(start, end);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Block;
})();
module.exports = Block;
function esc(text) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(text));
return div.innerHTML;
}
},{"./grammar":6,"./types":15,"./types/constants":7,"miniprism":2}],4:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Curse = _interopRequire(require("../bower_components/curse/dist/curse"));
var _Curse = (function (Curse) {
function _Curse() {
if (Object.getPrototypeOf(_Curse) !== null) {
Object.getPrototypeOf(_Curse).apply(this, arguments);
}
}
_inherits(_Curse, Curse);
_prototypeProperties(_Curse, null, {
nodeLength: {
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = node.previousElementSibling;
if (previousSibling && previousSibling.classList.contains("LineBreak")) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return _Curse;
})(Curse);
module.exports = _Curse;
},{"../bower_components/curse/dist/curse":1}],5:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Block = _interopRequire(require("./block"));
var Curse = _interopRequire(require("./curse"));
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var BACKSPACE = 8;
var RETURN = 13;
var slice = Array.prototype.slice;
var Editor = (function () {
function Editor() {
var source = arguments[0] === undefined ? "" : arguments[0];
this.blocks = [];
this.node = this.createNode();
this.curse = new Curse(this.node, {
nodeLengths: { BR: 0 }
});
this.source = source;
this.bindEvents();
this.observeMutations();
}
_prototypeProperties(Editor, null, {
anchorNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentAnchor);
},
enumerable: true,
configurable: true
},
focusNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentFocus);
},
enumerable: true,
configurable: true
},
blockNodes: {
get: function () {
return this.blocks.map(function (block) {
return block.node;
});
},
enumerable: true,
configurable: true
},
currentAnchor: {
get: function () {
return this.getNode(window.getSelection().anchorNode);
},
enumerable: true,
configurable: true
},
currentBlock: {
get: function () {
return this.getBlockFromNode(this.currentNode);
},
enumerable: true,
configurable: true
},
currentFocus: {
get: function () {
return this.getNode(window.getSelection().focusNode);
},
enumerable: true,
configurable: true
},
currentNode: {
get: function () {
if (!this.isActive) {
return null;
}
if (this.isReversed) {
return this.currentFocus;
} else {
return this.currentAnchor;
}
},
enumerable: true,
configurable: true
},
foldingNodes: {
get: function () {
return slice.call(this.node.querySelectorAll(".md-folding, .md-pre"));
},
enumerable: true,
configurable: true
},
isActive: {
get: function () {
return document.activeElement === this.node;
},
enumerable: true,
configurable: true
},
isReversed: {
get: function () {
var _ref = this;
var currentAnchor = _ref.currentAnchor;
var currentFocus = _ref.currentFocus;
var nodes = _ref.nodes;
return nodes.indexOf(currentAnchor) > nodes.indexOf(currentFocus);
},
enumerable: true,
configurable: true
},
nodes: {
get: function () {
var nodeList = this.node.querySelectorAll(".Block");
return slice.call(nodeList);
},
enumerable: true,
configurable: true
},
toggleFoldingFn: {
get: function () {
if (this._toggleFoldingFn) {
return this._toggleFoldingFn;
}
return this._toggleFoldingFn = this.toggleFolding.bind(this);
},
enumerable: true,
configurable: true
},
source: {
get: function () {
return this.blocks.map(function (block) {
return block.source;
}).join("\n");
},
set: function (source) {
var _this = this;
this.blocks = source.split(/\n/).map(function (line) {
return new Block(_this, { source: line });
});
this.render();
},
enumerable: true,
configurable: true
},
bindEvents: {
value: function bindEvents() {
document.addEventListener("selectionchange", this.toggleFoldingFn);
this.node.addEventListener("input", this.startRenders.bind(this));
this.node.addEventListener("input", this.toggleFoldingFn);
this.node.addEventListener("keydown", this.onReturn.bind(this));
this.node.addEventListener("keydown", this.preventEmpty.bind(this));
this.node.addEventListener("copy", this.onCopy.bind(this));
this.node.addEventListener("cut", this.onCopy.bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement("div");
node.classList.add("Editor");
node.setAttribute("contenteditable", true);
return node;
},
writable: true,
enumerable: true,
configurable: true
},
eachSelectionNode: {
value: function eachSelectionNode(fn) {
var sel = window.getSelection();
var pointTypes = sel.isCollapsed ? ["anchor"] : ["anchor", "focus"];
for (var i = 0, len = pointTypes.length; i < len; i++) {
var pointType = pointTypes[i];
var node = sel["" + pointType + "Node"];
var offset = sel["" + pointType + "Offset"];
fn(node, offset, sel);
}
},
writable: true,
enumerable: true,
configurable: true
},
focusBlock: {
value: function focusBlock(block, hasContent) {
var range = document.createRange();
var sel = window.getSelection();
var pos = hasContent ? 0 : block.node.childNodes.length;
range.setStart(block.node, pos);
range.setEnd(block.node, pos);
sel.removeAllRanges();
sel.addRange(range);
},
writable: true,
enumerable: true,
configurable: true
},
getBlockFromNode: {
value: function getBlockFromNode(node) {
return this.blocks[this.nodes.indexOf(node)];
},
writable: true,
enumerable: true,
configurable: true
},
getNode: {
value: function getNode(node) {
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
while (!node.classList.contains("Block")) {
node = node.parentElement;
}
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBlock: {
value: function insertBlock(block, prevBlock, nextElementSibling) {
var parentNode = this.node;
var prevNode = prevBlock.node;
var prevParent = prevNode.parentElement;
if (prevBlock.shouldContinue) {
parentNode = prevParent;
block.continueFrom(prevBlock);
} else if (prevBlock.type.continues) {
block.reset();
block.content = block.content;
this.splitBlock(prevParent, prevNode);
prevNode.remove();
if (prevParent.childNodes.length === 0) {
nextElementSibling = prevParent.nextElementSibling;
prevParent.remove();
} else {
nextElementSibling = prevParent;
}
}
block.type.insertBefore(block.node, nextElementSibling, parentNode);
},
writable: true,
enumerable: true,
configurable: true
},
observeMutations: {
value: function observeMutations() {
new MutationObserver(this.onMutation.bind(this)).observe(this.node, { childList: true, subtree: true });
},
writable: true,
enumerable: true,
configurable: true
},
onMutation: {
value: function onMutation(mutationRecords) {
for (var i = 0, len = mutationRecords.length; i < len; i++) {
var mut = mutationRecords[i];
for (var _i = 0, _len = mut.removedNodes.length; _i < _len; _i++) {
this.removeNodes(mut.removedNodes);
}
}
},
writable: true,
enumerable: true,
configurable: true
},
onCopy: {
value: function onCopy(e) {
this.copying = true;
var sel = window.getSelection();
var range = sel.getRangeAt(0);
var copyBin = document.createElement("pre");
var text = "";
var anc = this.anchorNodeBlock;
var foc = this.focusNodeBlock;
var nodes = this.nodes;
text += anc.selectionSubstring(sel) + "\n";
var started = undefined;
for (var i = 0, len = nodes.length; i < len; i++) {
if (foc.node === nodes[i]) {
break;
}
if (anc.node === nodes[i]) {
started = true;
continue;
}
if (started) {
text += this.getBlockFromNode(nodes[i]).source + "\n";
}
}
if (anc !== foc) {
text += foc.selectionSubstring(sel);
}
copyBin.classList.add("CopyBin");
copyBin.textContent = text;
this.node.appendChild(copyBin);
var newRange = document.createRange();
newRange.selectNodeContents(copyBin);
sel.removeAllRanges();
sel.addRange(newRange);
setTimeout((function () {
copyBin.remove();
sel.removeAllRanges();
sel.addRange(range);
this.copying = false;
if (e.type === "cut") {
document.execCommand("insertText", null, "");
}
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
onReturn: {
value: function onReturn(e) {
if (e.keyCode !== RETURN) {
return;
}
e.preventDefault();
var _ref2 = this;
var currentAnchor = _ref2.currentAnchor;
var currentFocus = _ref2.currentFocus;
var currentNode = _ref2.currentNode;
var isReversed = _ref2.isReversed;
var startNode = isReversed ? currentFocus : currentAnchor;
var endNode = isReversed ? currentAnchor : currentFocus;
var nextElementSibling = endNode.nextElementSibling;
var range = window.getSelection().getRangeAt(0);
var collapsed = range.collapsed;
var startContainer = range.startContainer;
var endContainer = range.endContainer;
var startOffset = range.startOffset;
var endOffset = range.endOffset;
// In a copy of the range, select the entire end node of the selection
var rangeCopy = range.cloneRange();
rangeCopy.selectNodeContents(endNode);
// In the range copy, select only the text in the current node *after* the
// user's current selection.
if (range.collapsed) {
rangeCopy.setStart(startContainer, startOffset);
} else {
rangeCopy.setStart(endContainer, endOffset);
}
// Set the text after the user's selection to `source` so that it can be
// inserted into the new block being created.
var source = rangeCopy.toString();
var block = undefined;
if (endContainer === this.node || endOffset === 0) {
block = this.getBlockFromNode(endNode).clone();
} else {
block = new Block(this, { source: source });
}
rangeCopy.deleteContents();
// Delete the content selected by the user
range.deleteContents();
if (currentNode.textContent === "") {
currentNode.innerHTML = "<br>";
}
var idx = this.nodes.indexOf(currentNode) + 1;
this.blocks.splice(idx, 0, block);
this.insertBlock(block, this.blocks[idx - 1], nextElementSibling);
this.focusBlock(block, source);
// When not collapsed remove the end node since we're recreating it with its
// remaining contents.
if (!collapsed && startNode !== endNode) {
endNode.remove();
}
// Manually dispatch an `input` event since we called `preventDefault`.
this.node.dispatchEvent(new Event("input"));
},
writable: true,
enumerable: true,
configurable: true
},
toggleFolding: {
value: function toggleFolding() {
if (this.copying) {
return;
}
this.foldingNodes.forEach(function (node) {
return node.classList.remove("visible");
});
if (!this.isActive) {
return;
}
var range = window.getSelection().getRangeAt(0);
this.foldingNodes.forEach(function (node) {
if (range.intersectsNode(node)) {
node.classList.add("visible");
}
});
slice.call(this.currentNode.querySelectorAll(".md-pre")).forEach(function (node) {
return node.classList.add("visible");
});
this.eachSelectionNode((function maybeAddVisible(node, offset) {
var nextSibling = node.nextElementSibling;
if (nextSibling && nextSibling.classList.contains("md-has-folding") && offset === node.textContent.length) {
node = nextSibling;
}
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
if (!node.classList.contains("md-has-folding")) {
var parentEl = undefined;
var testNode = node;
while (parentEl = testNode.parentElement) {
testNode = parentEl;
if (parentEl.classList.contains("md-has-folding")) {
node = parentEl;
}
if (parentEl.classList.contains("Block")) {
break;
}
}
}
if (!node.classList.contains("md-has-folding")) {
return;
}
slice.call(node.querySelectorAll(".md-folding")).forEach(function (node) {
return node.classList.add("visible");
});
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
preventEmpty: {
value: function preventEmpty(e) {
if (!(window.getSelection().isCollapsed && e.keyCode === BACKSPACE)) {
return;
}
var currentNode = this.currentNode;
if (currentNode.textContent === "" && currentNode === this.nodes[0]) {
e.preventDefault();
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNode: {
value: function removeNode(node) {
if (!node.classList.contains("Block")) {
return;
}
var idx = this.blockNodes.indexOf(node);
if (idx !== -1 && !node.isMoving) {
this.blocks.splice(idx, 1);
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNodes: {
value: function removeNodes(nodes) {
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i];
if (node.nodeType !== ELEMENT_NODE || node.isMoving) {
continue;
}
if (node.classList.contains("Block")) {
this.removeNode(nodes[i]);
} else {
var children = node.querySelectorAll(".Block");
for (var _i2 = 0, _len2 = children.length; _i2 < _len2; _i2++) {
this.removeNode(children[_i2]);
}
}
}
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
this.innerHTML = "";
for (var i = 0, len = this.blocks.length; i < len; i++) {
this.blocks[i].appendTo(this.node);
}
},
writable: true,
enumerable: true,
configurable: true
},
splitBlock: {
value: function splitBlock(block, node) {
var blockOne = block.cloneNode();
// Cache, since we're removing some.
var children = slice.call(block.childNodes);
_loop: for (var i = 0, len = children.length; i < len; i++) {
var _ret = (function (i, len) {
var childNode = children[i];
if (childNode !== node) {
childNode.isMoving = true;
blockOne.appendChild(childNode);
setTimeout(function () {
return childNode.isMoving = false;
});
} else {
return "break";
}
})(i, len);
if (_ret === "break") break _loop;
}
if (blockOne.childNodes.length > 0) {
block.parentElement.insertBefore(blockOne, block);
}
return [blockOne, block];
},
writable: true,
enumerable: true,
configurable: true
},
startRenders: {
value: function startRenders() {
this.blocks.forEach(function (block) {
return block.render();
});
},
writable: true,
enumerable: true,
configurable: true
},
teardown: {
value: function teardown() {
document.removeEventListener("selectionchange", this.toggleFoldingFn);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Editor;
})();
module.exports = Editor;
},{"./block":3,"./curse":4}],6:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var types = _interopRequire(require("./types"));
var grammar = { blocks: [] };
for (var i = 1; i <= 6; i++) {
grammar.blocks.push(new types["H" + i]());
}
grammar.blocks.push(new types.OL());
grammar.blocks.push(new types.UL());
grammar.blocks.push(new types.Paragraph());
module.exports = grammar;
},{"./types":15}],7:[function(require,module,exports){
"use strict";
module.exports = {
PRE: -1
};
},{}],8:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H1 = (function (Heading) {
function H1() {
if (Object.getPrototypeOf(H1) !== null) {
Object.getPrototypeOf(H1).apply(this, arguments);
}
}
_inherits(H1, Heading);
_prototypeProperties(H1, null, {
level: {
get: function () {
return 1;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(# )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H1;
})(Heading);
module.exports = H1;
},{"./heading":14}],9:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H2 = (function (Heading) {
function H2() {
if (Object.getPrototypeOf(H2) !== null) {
Object.getPrototypeOf(H2).apply(this, arguments);
}
}
_inherits(H2, Heading);
_prototypeProperties(H2, null, {
level: {
get: function () {
return 2;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{2} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H2;
})(Heading);
module.exports = H2;
},{"./heading":14}],10:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H3 = (function (Heading) {
function H3() {
if (Object.getPrototypeOf(H3) !== null) {
Object.getPrototypeOf(H3).apply(this, arguments);
}
}
_inherits(H3, Heading);
_prototypeProperties(H3, null, {
level: {
get: function () {
return 3;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{3} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H3;
})(Heading);
module.exports = H3;
},{"./heading":14}],11:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H4 = (function (Heading) {
function H4() {
if (Object.getPrototypeOf(H4) !== null) {
Object.getPrototypeOf(H4).apply(this, arguments);
}
}
_inherits(H4, Heading);
_prototypeProperties(H4, null, {
level: {
get: function () {
return 4;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{4} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H4;
})(Heading);
module.exports = H4;
},{"./heading":14}],12:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H5 = (function (Heading) {
function H5() {
if (Object.getPrototypeOf(H5) !== null) {
Object.getPrototypeOf(H5).apply(this, arguments);
}
}
_inherits(H5, Heading);
_prototypeProperties(H5, null, {
level: {
get: function () {
return 5;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{5} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H5;
})(Heading);
module.exports = H5;
},{"./heading":14}],13:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H6 = (function (Heading) {
function H6() {
if (Object.getPrototypeOf(H6) !== null) {
Object.getPrototypeOf(H6).apply(this, arguments);
}
}
_inherits(H6, Heading);
_prototypeProperties(H6, null, {
level: {
get: function () {
return 6;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{6} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H6;
})(Heading);
module.exports = H6;
},{"./heading":14}],14:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./constants").PRE;
var Type = _interopRequire(require("./type"));
var Heading = (function (Type) {
function Heading() {
if (Object.getPrototypeOf(Heading) !== null) {
Object.getPrototypeOf(Heading).apply(this, arguments);
}
}
_inherits(Heading, Type);
_prototypeProperties(Heading, null, {
cssClass: {
get: function () {
return "h" + this.level;
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "H" + this.level;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return new RegExp("^(#{1,6} )(.*)$");
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Heading;
})(Type);
module.exports = Heading;
},{"./constants":7,"./type":20}],15:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var H1 = _interopRequire(require("./h1"));
var H2 = _interopRequire(require("./h2"));
var H3 = _interopRequire(require("./h3"));
var H4 = _interopRequire(require("./h4"));
var H5 = _interopRequire(require("./h5"));
var H6 = _interopRequire(require("./h6"));
var Null = _interopRequire(require("./null"));
var Paragraph = _interopRequire(require("./paragraph"));
var OL = _interopRequire(require("./ol"));
var UL = _interopRequire(require("./ul"));
module.exports = {
H1: H1,
H2: H2,
H3: H3,
H4: H4,
H5: H5,
H6: H6,
Null: Null,
Paragraph: Paragraph,
OL: OL,
UL: UL
};
},{"./h1":8,"./h2":9,"./h3":10,"./h4":11,"./h5":12,"./h6":13,"./null":17,"./ol":18,"./paragraph":19,"./ul":21}],16:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var PRE = require("./constants").PRE;
var List = (function (Type) {
function List() {
if (Object.getPrototypeOf(List) !== null) {
Object.getPrototypeOf(List).apply(this, arguments);
}
}
_inherits(List, Type);
_prototypeProperties(List, null, {
continues: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "li";
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "LI";
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
var listNode = undefined;
if (parent.lastChild && parent.lastChild.nodeName === this.parentNodeName) {
listNode = parent.lastChild;
} else {
listNode = this.createListNode();
}
listNode.appendChild(node);
parent.appendChild(listNode);
},
writable: true,
enumerable: true,
configurable: true
},
createListNode: {
value: function createListNode() {
var ul = document.createElement(this.parentNodeName.toLowerCase());
ul.classList.add("LineBreak");
return ul;
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
var listNode = undefined;
if (oldNode.previousElementSibling && oldNode.previousElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.previousElementSibling;
listNode.appendChild(node);
} else if (oldNode.nextElementSibling && oldNode.nextElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.nextElementSibling;
listNode.insertBefore(node, listNode.firstChild);
} else {
listNode = this.createListNode();
listNode.appendChild(node);
}
listNode.isMoving = true;
oldNode.parentElement.replaceChild(listNode, oldNode);
setTimeout(function () {
return listNode.isMoving = false;
});
},
writable: true,
enumerable: true,
configurable: true
}
});
return List;
})(Type);
module.exports = List;
},{"./constants":7,"./type":20}],17:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Null = (function (Type) {
function Null() {
if (Object.getPrototypeOf(Null) !== null) {
Object.getPrototypeOf(Null).apply(this, arguments);
}
}
_inherits(Null, Type);
_prototypeProperties(Null, null, {
isNull: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Null;
})(Type);
module.exports = Null;
},{"./type":20}],18:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var OL = (function (List) {
function OL() {
if (Object.getPrototypeOf(OL) !== null) {
Object.getPrototypeOf(OL).apply(this, arguments);
}
}
_inherits(OL, List);
_prototypeProperties(OL, null, {
cssClass: {
get: function () {
return "ol-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "OL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(\d+\. )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return OL;
})(List);
module.exports = OL;
},{"./list":16}],19:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Paragraph = (function (Type) {
function Paragraph() {
if (Object.getPrototypeOf(Paragraph) !== null) {
Object.getPrototypeOf(Paragraph).apply(this, arguments);
}
}
_inherits(Paragraph, Type);
_prototypeProperties(Paragraph, null, {
cssClass: {
get: function () {
return "p";
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "P";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(.*)$/;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Paragraph;
})(Type);
module.exports = Paragraph;
},{"./type":20}],20:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Type = (function () {
function Type() {}
_prototypeProperties(Type, null, {
continues: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "";
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isNull: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "DIV";
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
parent.appendChild(node);
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement(this.nodeName.toLowerCase());
node.className = "Block LineBreak";
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBefore: {
value: function insertBefore(node, next, parent) {
parent.insertBefore(node, next);
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
oldNode.parentElement.replaceChild(node, oldNode);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Type;
})();
module.exports = Type;
},{}],21:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var UL = (function (List) {
function UL() {
if (Object.getPrototypeOf(UL) !== null) {
Object.getPrototypeOf(UL).apply(this, arguments);
}
}
_inherits(UL, List);
_prototypeProperties(UL, null, {
cssClass: {
get: function () {
return "ul-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "UL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(- )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return UL;
})(List);
module.exports = UL;
},{"./list":16}]},{},[5])
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
"use strict";
!(function (e) {
if ("object" == typeof exports) module.exports = e();else if ("function" == typeof define && define.amd) define(e);else {
var f;"undefined" != typeof window ? f = window : "undefined" != typeof global ? f = global : "undefined" != typeof self && (f = self), f.Curse = e();
}
})(function () {
var define, module, exports;return (function e(t, n, r) {
var s = function (o, u) {
if (!n[o]) {
if (!t[o]) {
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);throw new Error("Cannot find module '" + o + "'");
}var f = n[o] = { exports: {} };t[o][0].call(f.exports, function (e) {
var n = t[o][1][e];return s(n ? n : e);
}, f, f.exports, e, t, n, r);
}return n[o].exports;
};
var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) s(r[o]);return s;
})({ 1: [function (_dereq_, module, exports) {
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
/**
* Captures and restores the cursor position inside of an HTML element. This
* is particularly useful for capturing, editing, and restoring selections
* in contenteditable elements, where the selection may span both text nodes
* and element nodes.
*
* var elem = document.querySelector('#editor');
* var curse = new Curse(elem);
* curse.capture();
*
* // ...
*
* curse.restore();
*
* @class Curse
* @constructor
* @param {HTMLElement} element an element to track the cursor inside of
*/
var Curse = (function () {
var Curse = function (element) {
var _ref = arguments[1] === undefined ? {} : arguments[1];
var lineBreak = _ref.lineBreak;
var nodeLengths = _ref.nodeLengths;
this.lineBreak = lineBreak;
this.nodeLengths = nodeLengths || {};
this.element = element;
this.reset();
};
_prototypeProperties(Curse, null, {
iterator: {
/**
* An iterator to iterate over the nodes in `this.element`.
*
* This returns a simple node iterator that skips `this.element`, but not its
* children.
*
* @property iterator
* @private
* @type {NodeIterator}
*/
get: function () {
var elem = this.element;
return document.createNodeIterator(this.element, NodeFilter.SHOW_ALL, function onNode(node) {
return node === elem ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
});
},
enumerable: true,
configurable: true
},
capture: {
/**
* Captures the current selection in the element, by storing "start" and
* "end" integer values. This allows for the text and text nodes to change
* inside the element and still have the Curse be able to restore selection
* state.
*
* A `<br>` tag, for example, is counted as a single "character", while
* a text node with the text "Hello, world" is counted as 12 characters.
*
* @method capture
*/
value: function capture() {
var _window$getSelection = window.getSelection();
var anchorNode = _window$getSelection.anchorNode;
var anchorOffset = _window$getSelection.anchorOffset;
var focusNode = _window$getSelection.focusNode;
var focusOffset = _window$getSelection.focusOffset;
var child = undefined,
start = undefined,
end = undefined;
if (anchorNode === null || focusNode === null) {
this.reset();
return;
}
if (anchorNode.nodeName === "#text") {
start = this.lengthUpTo(anchorNode) + anchorOffset;
} else {
child = anchorNode.childNodes[anchorOffset ? anchorOffset - 1 : 0];
start = this.lengthUpTo(child);
}
if (focusNode.nodeName === "#text") {
end = this.lengthUpTo(focusNode) + focusOffset;
} else {
child = focusNode.childNodes[focusOffset ? focusOffset - 1 : 0];
end = this.lengthUpTo(child) + this.nodeLength(child);
}
this.start = start;
this.end = end;
},
writable: true,
enumerable: true,
configurable: true
},
restore: {
/**
* Restore the captured cursor state by iterating over the child nodes in the
* element and counting their length.
*
* @method restore
* @param {Boolean} [onlyActive=true] only restore if the curse's element is
* the active element
*/
value: function restore() {
var onlyActive = arguments[0] === undefined ? true : arguments[0];
if (onlyActive && document.activeElement !== this.element) {
return;
}
if (!onlyActive) {
this.element.focus();
}
var range = document.createRange();
var idx = 0;
var _ref2 = this;
var start = _ref2.start;
var end = _ref2.end;
var iter = this.iterator;
var node = undefined,
setStart = undefined,
setEnd = undefined;
if (this.start > this.end) {
start = this.end;
end = this.start;
}
while (node = iter.nextNode()) {
if (setStart && setEnd) {
break;
}
var nodeLength = this.nodeLength(node);
var isText = node.nodeName === "#text";
var childIdx = undefined;
if (!setStart && start <= idx + nodeLength) {
if (isText) {
range.setStart(node, start - idx);
} else {
childIdx = this.indexOfNode(node);
range.setStart(node.parentNode, childIdx);
}
setStart = true;
}
if (!setEnd && end <= idx + nodeLength) {
if (isText) {
range.setEnd(node, end - idx);
} else {
childIdx = this.indexOfNode(node);
range.setEnd(node.parentNode, childIdx);
}
setEnd = true;
}
idx += nodeLength;
}
var selection = window.getSelection();
selection.removeAllRanges();
// Reverse the selection if it was originally backwards
if (this.start > this.end) {
var startContainer = range.startContainer;
var startOffset = range.startOffset;
range.collapse(false);
selection.addRange(range);
selection.extend(startContainer, startOffset);
} else {
selection.addRange(range);
}
},
writable: true,
enumerable: true,
configurable: true
},
indexOfNode: {
/**
* Get the index of a node in its parent node.
*
* @method indexOfNode
* @private
* @param {Node} child the child node to find the index of
* @returns {Number} the index of the child node
*/
value: function indexOfNode(child) {
var i = 0;
while (child = child.previousSibling) {
i++;
}
return i;
},
writable: true,
enumerable: true,
configurable: true
},
lengthUpTo: {
/**
* Get the number of characters up to a given node.
*
* @method lengthUpTo
* @private
* @param {Node} node a node to find the length up to
* @returns {Number} the length up to the given node
*/
value: function lengthUpTo(lastNode) {
var len = 0;
var iter = this.iterator;
var node = undefined;
while (node = iter.nextNode()) {
if (node === lastNode) {
break;
}
len += this.nodeLength(node);
}
return len;
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
/**
* Reset the state of the cursor.
*
* @method reset
* @private
*/
value: function reset() {
this.start = null;
this.end = null;
},
writable: true,
enumerable: true,
configurable: true
},
nodeLength: {
/**
* Get the "length" of a node. Text nodes are the length of their contents,
* and `<br>` tags, for example, have a length of 1 (a newline character,
* essentially).
*
* @method nodeLength
* @private
* @param {Node} node a Node, typically a Text or HTMLElement node
* @return {Number} the length of the node, as text
*/
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = undefined;
if (this.lineBreak) {
previousSibling = node.previousElementSibling;
}
if (previousSibling && previousSibling.classList.contains(this.lineBreak)) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return Curse;
})();
module.exports = Curse;
}, {}] }, {}, [1])(1);
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],2:[function(require,module,exports){
(function (global){
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.miniprism=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";
/*
* The syntax parsing algorithm in this file is copied heavily from Lea Verou's
* Prism project, which bears this license:
*
* MIT LICENSE
*
* Copyright (c) 2012-2013 Lea Verou
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var grammars = _dereq_("./grammars");
exports.grammars = grammars;
exports.highlight = function highlight(source, grammarName) {
var opts = arguments[2] === undefined ? {} : arguments[2];
var grammar = undefined;
if (typeof grammarName === "string") {
grammar = grammars[grammarName];
}
if (typeof grammarName === "object" && grammarName.constructor === Object) {
grammar = grammarName;
}
if (!grammar) {
throw new Error("Grammar \"" + grammarName + "\" not found.");
}
return stringify(encode(tokenize(source, grammar)), opts.lineClass);
};
function tokenize(source, grammar) {
var strings = [source];
var inlines = grammar.inlines;
if (inlines) {
// jshint -W089
for (var inlineToken in inlines) {
grammar[inlineToken] = inlines[inlineToken];
}
delete grammar.inlines;
}
for (var token in grammar) {
var patterns = grammar[token];
if (!Array.isArray(patterns)) {
patterns = [patterns];
}
for (var i = 0; i < patterns.length; i++) {
var pattern = patterns[i];
var block = pattern.block;
var classes = pattern.classes;
var inside = pattern.inside;
var lookbehind = !!pattern.lookbehind;
var lookbehindLength = 0;
var tag = undefined;
if (pattern.tag) {
tag = pattern.tag;
} else {
tag = block ? "div" : "span";
}
pattern = pattern.pattern || pattern;
for (var _i = 0; _i < strings.length; _i++) {
var string = strings[_i];
if (typeof string !== "string") {
continue;
}
pattern.lastIndex = 0;
var match = pattern.exec(string);
if (!match) {
continue;
}
if (lookbehind) {
lookbehindLength = match[1].length;
}
var from = match.index - 1 + lookbehindLength;
match = match[0].slice(lookbehindLength);
var len = match.length;
var to = from + len;
var before = string.slice(0, from + 1);
var after = string.slice(to + 1);
var args = [_i, 1];
if (before) {
args.push(before);
}
var wrapped = {
block: block,
classes: classes,
tag: tag,
text: inside ? tokenize(match, inside) : match,
token: token
};
args.push(wrapped);
if (after) {
args.push(after);
}
Array.prototype.splice.apply(strings, args);
}
}
}
return strings;
}
function stringify(source) {
var lineClass = arguments[1] === undefined ? "md-line" : arguments[1];
if (source === "\n") {
return "<br>";
}
if (typeof source === "string") {
return source.replace(/\n/g, "");
}
if (Array.isArray(source)) {
return source.reduce(function addItem(result, item) {
return result + stringify(item, lineClass);
}, "");
}
var tag = source.tag;
var classList = source.classes || source.token.split(" ");
var className = classList.map(function (token) {
return "md-" + token;
}).join(" ");
if (source.block) {
className += " " + lineClass;
}
return ["<" + tag + " class=\"" + className + "\">", stringify(source.text, lineClass), "</" + tag + ">"].join("");
}
function encode(src) {
if (Array.isArray(src)) {
return src.map(encode);
} else if (typeof src === "object") {
src.text = encode(src.text);
return src;
} else {
return escapeHTML(src);
}
}
function escapeHTML(str) {
return str.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/\//g, "&#x2F;");
}
},{"./grammars":2}],2:[function(_dereq_,module,exports){
"use strict";
exports.markdown = _dereq_("./markdown");
},{"./markdown":3}],3:[function(_dereq_,module,exports){
"use strict";
/*
* These regexes are in some places copies of, in others modifications of, and
* in some places wholly unrelated to the Markdown regexes found in the
* Stackedit project, which bears this license:
*
* StackEdit - The Markdown editor powered by PageDown.
* Copyright 2013 Benoit Schweblin (http://www.benoitschweblin.com)
* Licensed under an Apache License (http://www.apache.org/licenses/LICENSE-2.0)
*/
exports.gfm = {
block: true,
pattern: /^`{3}.*\n(?:[\s\S]*?)\n`{3} *(?:\n|$)/gm,
inside: {
"gfm-limit": {
block: true,
pattern: /^`{3}.*(?:\n|$)/gm,
inside: {
"gfm-info": {
lookbehind: true,
pattern: /^(`{3}).+(?:\n|$)/
},
"gfm-fence": /^`{3}(?:\n|$)/gm
}
},
"gfm-line": {
block: true,
pattern: /^.*(?:\n|$)/gm
} }
};
exports.blank = [{
block: true,
pattern: /\n(?![\s\S])/mg
}, {
block: true,
pattern: /^\n/mg
}];
exports["setex-h1"] = {
block: true,
pattern: /^.+\n=+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^=].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^=+[ \t]*(?:\n|$)/
}
}
};
exports["setex-h2"] = {
block: true,
pattern: /^(?!^- ).+\n-+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^-].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^-+[ \t]*(?:\n|$)/
}
}
};
exports.code = {
block: true,
pattern: /^(?: {4,}|\t).+(?:\n|$)/gm
};
// h1 through h6
for (var i = 1; i < 7; i++) {
exports["h" + i] = {
classes: ["h" + i, "has-folding"],
block: true,
pattern: new RegExp("^#{" + i + "} .*(?:\n|$)", "gm"),
inside: {
"hash folding": new RegExp("^#{" + i + "} ")
}
};
}
exports.ul = {
classes: ["ul", "has-folding"],
block: true,
pattern: /^[ \t]*(?:[*+\-])[ \t].*(?:\n|$)/gm,
inside: {
"ul-marker folding": /^[ \t]*(?:[*+\-])[ \t]/
}
};
exports.ol = {
block: true,
pattern: /^[ \t]*(?:\d+)\.[ \t].*(?:\n|$)/gm,
inside: {
"ol-marker": /^[ \t]*(?:\d+)\.[ \t]/
}
};
exports.blockquote = {
block: true,
pattern: /^ {0,3}> *.*(?:\n|$)/gm,
inside: {
"blockquote-marker": /^ {0,3}> */
}
};
exports.hr = {
block: true,
pattern: /^(?:[*\-_] *){3,}(?:\n|$)/gm
};
exports["link-def"] = {
block: true,
pattern: /^ {0,3}\[.*?\]:[ \t]+.+(?:\n|$)/gm,
inside: {
"link-def-name": {
pattern: /^ {0,3}\[.*?\]:/,
inside: {
"bracket-start": /^\[/,
"bracket-end": /\](?=:$)/,
colon: /:$/
}
},
"link-def-value": /.*(?:\n|$)/
}
};
exports.p = {
block: true,
pattern: /^.+(?:\n|$)/gm,
inside: {}
};
// jshint -W101
exports.link = {
classes: ["link", "has-folding"],
pattern: /\[(?:(?:\\.)|[^\[\]])*\]\([^\(\)\s]+(?:\(\S*?\))??[^\(\)\s]*?(?:\s(?:['‘][^'’]*['’]|["“][^"”]*["”]))?\)/gm,
inside: {
"bracket-start folding": {
pattern: /(^|[^\\])\[/,
lookbehind: true
},
ref: /(?:(?:\\.)|[^\[\]])+(?=\])/,
"bracket-end folding": /\](?=\s?\()/,
"paren-start folding": /^\(/,
"paren-end folding": /\)$/,
"href folding": /.*/
}
};
// jshint +W101
exports["link-ref"] = {
classes: ["link-ref", "has-folding"],
pattern: /\[(?:.*?)\] ?\[(?:.*?)\]/g,
inside: {
"ref-value folding": {
pattern: /\[[^\[\]]+\]$/,
inside: {
"bracket-start": /\[/,
"ref-href": /[^\[\]]+(?=]$)/,
"bracket-end": /\]/
}
},
"ref-text": {
pattern: /^\[[^\[\]]+\]/,
inside: {
"bracket-start folding": /^\[/,
ref: /^[^\[\]]+/,
"bracket-end folding": /\]$/
}
}
}
};
exports.em = {
classes: ["em", "has-folding"],
pattern: /(^|[^\\])(\*|_)(\S[^\2]*?)??[^\s\\]+?\2/g,
lookbehind: true,
inside: {
"em-marker folding": /(?:^(?:\*|_))|(?:(?:\*|_)$)/
}
};
exports.strong = {
classes: ["strong", "has-folding"],
pattern: /([_\*]){2}(?:(?!\1{2}).)*\1{2}/g,
inside: {
"strong-marker folding": /(?:^(?:\*|_){2})|(?:(?:\*|_){2}$)/
}
};
exports["inline-code"] = {
classes: ["inline-code", "has-folding"],
pattern: /(^|[^\\])`(\S[^`]*?)??[^\s\\]+?`/g,
lookbehind: true,
inside: {
"inline-code-marker folding": /(?:^(?:`))|(?:(?:`)$)/
}
};
var inlines = {
strong: exports.strong,
em: exports.em,
link: exports.link,
"inline-code": exports["inline-code"],
"link-ref": exports["link-ref"]
};
["setex-h1", "setex-h2", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "blockquote", "p"].forEach(function (token) {
exports[token].inside.inlines = inlines;
});
["em", "strong"].forEach(function (token) {
exports[token].inside = exports[token].inside || {};
exports[token].inside.inlines = {
link: exports.link,
"link-ref": exports["link-ref"]
};
});
},{}]},{},[1])
(1)
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./types/constants").PRE;
var blocks = require("./grammar").blocks;
var Null = require("./types").Null;
var OL = require("./types").OL;
var miniprism = _interopRequire(require("miniprism"));
// Standard inlines:
var inlines = miniprism.grammars.markdown.p.inside.inlines;
var slice = Array.prototype.slice;
var Block = (function () {
function Block(editor, _ref) {
var node = _ref.node;
var pre = _ref.pre;
var source = _ref.source;
var type = _ref.type;
this.editor = editor;
this.type = type || new Null();
this.pre = pre || "";
this.content = source;
this.node = node || this.type.createNode();
this.render(true); // (isFirstRender)
}
_prototypeProperties(Block, null, {
source: {
get: function () {
if (this.type.constructor === OL) {
var children = this.node.parentElement ? slice.call(this.node.parentElement.childNodes) : [];
var digit = children.indexOf(this.node) + 1;
return "" + digit + ". " + this._content;
} else {
return this.pre + this._content;
}
},
enumerable: true,
configurable: true
},
content: {
get: function () {
if (this.type.isHeading) {
return "" + this.pre + "" + this._content;
} else {
return this._content;
}
},
set: function (content) {
this._content = content;
var match = undefined,
type = undefined;
if (this.type.isHeading && !content) {
this.type = new Null();
this.pre = "";
}
if (!this.type.shouldReparse) {
return;
}
// jshint -W089
for (var i = 0, len = blocks.length; i < len; i++) {
type = blocks[i];
if (match = content.match(type.pattern)) {
break;
}
}
this.type = type;
this._content = "";
match = match.slice(1);
var labels = type.labels;
for (var i = 0, len = match.length; i < len; i++) {
if (labels[i] === PRE) {
this.pre = match[i];
} else {
this._content += match[i];
}
}
},
enumerable: true,
configurable: true
},
html: {
get: function () {
if (this.type.isHeading) {
return "<span class=\"md-pre\">" + esc(this.pre) + "</span>" + ("" + miniprism.highlight(this._content, inlines));
} else {
return miniprism.highlight(this._content, inlines);
}
},
enumerable: true,
configurable: true
},
shouldContinue: {
get: function () {
return this.type.continues && this.content;
},
enumerable: true,
configurable: true
},
type: {
get: function () {
return this._type;
},
set: function (type) {
this.adjustedPre = false;
this.pre = "";
return this._type = type;
},
enumerable: true,
configurable: true
},
appendTo: {
value: function appendTo(node) {
this.type.appendChild(this.node, node);
},
writable: true,
enumerable: true,
configurable: true
},
clone: {
value: function clone() {
return new this.constructor(this.editor, {
node: this.node.cloneNode(true),
pre: this.pre,
source: this.content,
type: this.type
});
},
writable: true,
enumerable: true,
configurable: true
},
continueFrom: {
value: function continueFrom(block) {
this.type = block.type;
this.pre = block.pre;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
var isFirstRender = arguments[0] === undefined ? false : arguments[0];
if (this.content === this.node.textContent && !isFirstRender) {
return;
}
var oldNode = this.node;
var oldType = this.type;
if (!isFirstRender) {
this.content = this.node.textContent;
}
this.editor.curse.capture();
if (oldType !== this.type) {
this.node = this.type.createNode();
this.type.replaceNode(this.node, oldNode);
}
/*
* Adjust the Curse for `pre` since it is about to be removed from the
* DOM during `#render`. This does not apply to reparsing types, as their
* `pre` is still displayed when focused.
*/
if (!this.adjustedPre && !this.type.shouldReparse) {
this.editor.curse.start -= this.pre.length;
this.editor.curse.end -= this.pre.length;
this.adjustedPre = true;
}
if (this.content) {
this.node.innerHTML = this.html;
} else {
this.node.innerHTML = "<br>";
}
this.editor.curse.restore();
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
value: function reset() {
this.type = new Null();
this.content = this.content;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
selectionSubstring: {
value: function selectionSubstring(sel) {
var anchorNode = sel.anchorNode;
var focusNode = sel.focusNode;
var anchorOffset = sel.anchorOffset;
var focusOffset = sel.focusOffset;
var start = 0;
var end = Infinity;
var curse = this.editor.curse;
if (this.node.contains(anchorNode)) {
start = curse.lengthUpTo(anchorNode) - curse.lengthUpTo(this.node.firstChild) + anchorOffset;
if (this.type.isList) {
start += this.pre.length;
}
}
if (this.node.contains(focusNode)) {
end = curse.lengthUpTo(focusNode) - curse.lengthUpTo(this.node.firstChild) + focusOffset;
if (this.type.isList) {
end += this.pre.length;
}
}
return this.source.substring(start, end);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Block;
})();
module.exports = Block;
function esc(text) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(text));
return div.innerHTML;
}
},{"./grammar":6,"./types":15,"./types/constants":7,"miniprism":2}],4:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Curse = _interopRequire(require("../bower_components/curse/dist/curse"));
var _Curse = (function (Curse) {
function _Curse() {
if (Object.getPrototypeOf(_Curse) !== null) {
Object.getPrototypeOf(_Curse).apply(this, arguments);
}
}
_inherits(_Curse, Curse);
_prototypeProperties(_Curse, null, {
nodeLength: {
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = node.previousElementSibling;
if (previousSibling && previousSibling.classList.contains("LineBreak")) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return _Curse;
})(Curse);
module.exports = _Curse;
},{"../bower_components/curse/dist/curse":1}],5:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Block = _interopRequire(require("./block"));
var Curse = _interopRequire(require("./curse"));
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var BACKSPACE = 8;
var RETURN = 13;
var slice = Array.prototype.slice;
var Editor = (function () {
function Editor() {
var source = arguments[0] === undefined ? "" : arguments[0];
this.blocks = [];
this.node = this.createNode();
this.curse = new Curse(this.node, {
nodeLengths: { BR: 0 }
});
this.source = source;
this.bindEvents();
this.observeMutations();
}
_prototypeProperties(Editor, null, {
anchorNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentAnchor);
},
enumerable: true,
configurable: true
},
focusNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentFocus);
},
enumerable: true,
configurable: true
},
blockNodes: {
get: function () {
return this.blocks.map(function (block) {
return block.node;
});
},
enumerable: true,
configurable: true
},
currentAnchor: {
get: function () {
return this.getNode(window.getSelection().anchorNode);
},
enumerable: true,
configurable: true
},
currentBlock: {
get: function () {
return this.getBlockFromNode(this.currentNode);
},
enumerable: true,
configurable: true
},
currentFocus: {
get: function () {
return this.getNode(window.getSelection().focusNode);
},
enumerable: true,
configurable: true
},
currentNode: {
get: function () {
if (!this.isActive) {
return null;
}
if (this.isReversed) {
return this.currentFocus;
} else {
return this.currentAnchor;
}
},
enumerable: true,
configurable: true
},
foldingNodes: {
get: function () {
return slice.call(this.node.querySelectorAll(".md-folding, .md-pre"));
},
enumerable: true,
configurable: true
},
isActive: {
get: function () {
return document.activeElement === this.node;
},
enumerable: true,
configurable: true
},
isReversed: {
get: function () {
var _ref = this;
var currentAnchor = _ref.currentAnchor;
var currentFocus = _ref.currentFocus;
var nodes = _ref.nodes;
return nodes.indexOf(currentAnchor) > nodes.indexOf(currentFocus);
},
enumerable: true,
configurable: true
},
nodes: {
get: function () {
var nodeList = this.node.querySelectorAll(".Block");
return slice.call(nodeList);
},
enumerable: true,
configurable: true
},
toggleFoldingFn: {
get: function () {
if (this._toggleFoldingFn) {
return this._toggleFoldingFn;
}
return this._toggleFoldingFn = this.toggleFolding.bind(this);
},
enumerable: true,
configurable: true
},
source: {
get: function () {
return this.blocks.map(function (block) {
return block.source;
}).join("\n");
},
set: function (source) {
var _this = this;
this.blocks = source.split(/\n/).map(function (line) {
return new Block(_this, { source: line });
});
this.render();
},
enumerable: true,
configurable: true
},
bindEvents: {
value: function bindEvents() {
document.addEventListener("selectionchange", this.toggleFoldingFn);
this.node.addEventListener("input", this.startRenders.bind(this));
this.node.addEventListener("input", this.toggleFoldingFn);
this.node.addEventListener("keydown", this.onReturn.bind(this));
this.node.addEventListener("keydown", this.preventEmpty.bind(this));
this.node.addEventListener("copy", this.onCopy.bind(this));
this.node.addEventListener("cut", this.onCopy.bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement("div");
node.classList.add("Editor");
node.setAttribute("contenteditable", true);
return node;
},
writable: true,
enumerable: true,
configurable: true
},
eachSelectionNode: {
value: function eachSelectionNode(fn) {
var sel = window.getSelection();
var pointTypes = sel.isCollapsed ? ["anchor"] : ["anchor", "focus"];
for (var i = 0, len = pointTypes.length; i < len; i++) {
var pointType = pointTypes[i];
var node = sel["" + pointType + "Node"];
var offset = sel["" + pointType + "Offset"];
fn(node, offset, sel);
}
},
writable: true,
enumerable: true,
configurable: true
},
focusBlock: {
value: function focusBlock(block, hasContent) {
var range = document.createRange();
var sel = window.getSelection();
var pos = hasContent ? 0 : block.node.childNodes.length;
range.setStart(block.node, pos);
range.setEnd(block.node, pos);
sel.removeAllRanges();
sel.addRange(range);
},
writable: true,
enumerable: true,
configurable: true
},
getBlockFromNode: {
value: function getBlockFromNode(node) {
return this.blocks[this.nodes.indexOf(node)];
},
writable: true,
enumerable: true,
configurable: true
},
getNode: {
value: function getNode(node) {
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
while (!node.classList.contains("Block")) {
node = node.parentElement;
}
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBlock: {
value: function insertBlock(block, prevBlock, nextElementSibling) {
var parentNode = this.node;
var prevNode = prevBlock.node;
var prevParent = prevNode.parentElement;
if (prevBlock.shouldContinue) {
parentNode = prevParent;
block.continueFrom(prevBlock);
} else if (prevBlock.type.continues) {
block.reset();
block.content = block.content;
this.splitBlock(prevParent, prevNode);
prevNode.remove();
if (prevParent.childNodes.length === 0) {
nextElementSibling = prevParent.nextElementSibling;
prevParent.remove();
} else {
nextElementSibling = prevParent;
}
}
block.type.insertBefore(block.node, nextElementSibling, parentNode);
},
writable: true,
enumerable: true,
configurable: true
},
observeMutations: {
value: function observeMutations() {
new MutationObserver(this.onMutation.bind(this)).observe(this.node, { childList: true, subtree: true });
},
writable: true,
enumerable: true,
configurable: true
},
onMutation: {
value: function onMutation(mutationRecords) {
for (var i = 0, len = mutationRecords.length; i < len; i++) {
var mut = mutationRecords[i];
for (var _i = 0, _len = mut.removedNodes.length; _i < _len; _i++) {
this.removeNodes(mut.removedNodes);
}
}
},
writable: true,
enumerable: true,
configurable: true
},
onCopy: {
value: function onCopy(e) {
this.copying = true;
var sel = window.getSelection();
var range = sel.getRangeAt(0);
var copyBin = document.createElement("pre");
var text = "";
var anc = this.anchorNodeBlock;
var foc = this.focusNodeBlock;
var nodes = this.nodes;
text += anc.selectionSubstring(sel) + "\n";
var started = undefined;
for (var i = 0, len = nodes.length; i < len; i++) {
if (foc.node === nodes[i]) {
break;
}
if (anc.node === nodes[i]) {
started = true;
continue;
}
if (started) {
text += this.getBlockFromNode(nodes[i]).source + "\n";
}
}
if (anc !== foc) {
text += foc.selectionSubstring(sel);
}
copyBin.classList.add("CopyBin");
copyBin.textContent = text;
this.node.appendChild(copyBin);
var newRange = document.createRange();
newRange.selectNodeContents(copyBin);
sel.removeAllRanges();
sel.addRange(newRange);
setTimeout((function () {
copyBin.remove();
sel.removeAllRanges();
sel.addRange(range);
this.copying = false;
if (e.type === "cut") {
document.execCommand("insertText", null, "");
}
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
onReturn: {
value: function onReturn(e) {
if (e.keyCode !== RETURN) {
return;
}
e.preventDefault();
var _ref2 = this;
var currentAnchor = _ref2.currentAnchor;
var currentFocus = _ref2.currentFocus;
var currentNode = _ref2.currentNode;
var isReversed = _ref2.isReversed;
var startNode = isReversed ? currentFocus : currentAnchor;
var endNode = isReversed ? currentAnchor : currentFocus;
var nextElementSibling = endNode.nextElementSibling;
var range = window.getSelection().getRangeAt(0);
var collapsed = range.collapsed;
var startContainer = range.startContainer;
var endContainer = range.endContainer;
var startOffset = range.startOffset;
var endOffset = range.endOffset;
// In a copy of the range, select the entire end node of the selection
var rangeCopy = range.cloneRange();
rangeCopy.selectNodeContents(endNode);
// In the range copy, select only the text in the current node *after* the
// user's current selection.
if (range.collapsed) {
rangeCopy.setStart(startContainer, startOffset);
} else {
rangeCopy.setStart(endContainer, endOffset);
}
// Set the text after the user's selection to `source` so that it can be
// inserted into the new block being created.
var source = rangeCopy.toString();
var block = undefined;
if (endContainer === this.node || endOffset === 0) {
block = this.getBlockFromNode(endNode).clone();
} else {
block = new Block(this, { source: source });
}
rangeCopy.deleteContents();
// Delete the content selected by the user
range.deleteContents();
if (currentNode.textContent === "") {
currentNode.innerHTML = "<br>";
}
var idx = this.nodes.indexOf(currentNode) + 1;
this.blocks.splice(idx, 0, block);
this.insertBlock(block, this.blocks[idx - 1], nextElementSibling);
this.focusBlock(block, source);
// When not collapsed remove the end node since we're recreating it with its
// remaining contents.
if (!collapsed && startNode !== endNode) {
endNode.remove();
}
// Manually dispatch an `input` event since we called `preventDefault`.
this.node.dispatchEvent(new Event("input"));
},
writable: true,
enumerable: true,
configurable: true
},
toggleFolding: {
value: function toggleFolding() {
if (this.copying) {
return;
}
this.foldingNodes.forEach(function (node) {
return node.classList.remove("visible");
});
if (!this.isActive) {
return;
}
var range = window.getSelection().getRangeAt(0);
this.foldingNodes.forEach(function (node) {
if (range.intersectsNode(node)) {
node.classList.add("visible");
}
});
slice.call(this.currentNode.querySelectorAll(".md-pre")).forEach(function (node) {
return node.classList.add("visible");
});
this.eachSelectionNode((function maybeAddVisible(node, offset) {
var nextSibling = node.nextElementSibling;
if (nextSibling && nextSibling.classList.contains("md-has-folding") && offset === node.textContent.length) {
node = nextSibling;
}
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
if (!node.classList.contains("md-has-folding")) {
var parentEl = undefined;
var testNode = node;
while (parentEl = testNode.parentElement) {
testNode = parentEl;
if (parentEl.classList.contains("md-has-folding")) {
node = parentEl;
}
if (parentEl.classList.contains("Block")) {
break;
}
}
}
if (!node.classList.contains("md-has-folding")) {
return;
}
slice.call(node.querySelectorAll(".md-folding")).forEach(function (node) {
return node.classList.add("visible");
});
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
preventEmpty: {
value: function preventEmpty(e) {
if (!(window.getSelection().isCollapsed && e.keyCode === BACKSPACE)) {
return;
}
var currentNode = this.currentNode;
if (currentNode.textContent === "" && currentNode === this.nodes[0]) {
e.preventDefault();
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNode: {
value: function removeNode(node) {
if (!node.classList.contains("Block")) {
return;
}
var idx = this.blockNodes.indexOf(node);
if (idx !== -1 && !node.isMoving) {
this.blocks.splice(idx, 1);
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNodes: {
value: function removeNodes(nodes) {
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i];
if (node.nodeType !== ELEMENT_NODE || node.isMoving) {
continue;
}
if (node.classList.contains("Block")) {
this.removeNode(nodes[i]);
} else {
var children = node.querySelectorAll(".Block");
for (var _i2 = 0, _len2 = children.length; _i2 < _len2; _i2++) {
this.removeNode(children[_i2]);
}
}
}
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
this.innerHTML = "";
for (var i = 0, len = this.blocks.length; i < len; i++) {
this.blocks[i].appendTo(this.node);
}
},
writable: true,
enumerable: true,
configurable: true
},
splitBlock: {
value: function splitBlock(block, node) {
var blockOne = block.cloneNode();
// Cache, since we're removing some.
var children = slice.call(block.childNodes);
_loop: for (var i = 0, len = children.length; i < len; i++) {
var _ret = (function (i, len) {
var childNode = children[i];
if (childNode !== node) {
childNode.isMoving = true;
blockOne.appendChild(childNode);
setTimeout(function () {
return childNode.isMoving = false;
});
} else {
return "break";
}
})(i, len);
if (_ret === "break") break _loop;
}
if (blockOne.childNodes.length > 0) {
block.parentElement.insertBefore(blockOne, block);
}
return [blockOne, block];
},
writable: true,
enumerable: true,
configurable: true
},
startRenders: {
value: function startRenders() {
this.blocks.forEach(function (block) {
return block.render();
});
},
writable: true,
enumerable: true,
configurable: true
},
teardown: {
value: function teardown() {
document.removeEventListener("selectionchange", this.toggleFoldingFn);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Editor;
})();
module.exports = Editor;
},{"./block":3,"./curse":4}],6:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var types = _interopRequire(require("./types"));
var grammar = { blocks: [] };
for (var i = 1; i <= 6; i++) {
grammar.blocks.push(new types["H" + i]());
}
grammar.blocks.push(new types.OL());
grammar.blocks.push(new types.UL());
grammar.blocks.push(new types.Paragraph());
module.exports = grammar;
},{"./types":15}],7:[function(require,module,exports){
"use strict";
module.exports = {
PRE: -1
};
},{}],8:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H1 = (function (Heading) {
function H1() {
if (Object.getPrototypeOf(H1) !== null) {
Object.getPrototypeOf(H1).apply(this, arguments);
}
}
_inherits(H1, Heading);
_prototypeProperties(H1, null, {
level: {
get: function () {
return 1;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(# )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H1;
})(Heading);
module.exports = H1;
},{"./heading":14}],9:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H2 = (function (Heading) {
function H2() {
if (Object.getPrototypeOf(H2) !== null) {
Object.getPrototypeOf(H2).apply(this, arguments);
}
}
_inherits(H2, Heading);
_prototypeProperties(H2, null, {
level: {
get: function () {
return 2;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{2} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H2;
})(Heading);
module.exports = H2;
},{"./heading":14}],10:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H3 = (function (Heading) {
function H3() {
if (Object.getPrototypeOf(H3) !== null) {
Object.getPrototypeOf(H3).apply(this, arguments);
}
}
_inherits(H3, Heading);
_prototypeProperties(H3, null, {
level: {
get: function () {
return 3;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{3} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H3;
})(Heading);
module.exports = H3;
},{"./heading":14}],11:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H4 = (function (Heading) {
function H4() {
if (Object.getPrototypeOf(H4) !== null) {
Object.getPrototypeOf(H4).apply(this, arguments);
}
}
_inherits(H4, Heading);
_prototypeProperties(H4, null, {
level: {
get: function () {
return 4;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{4} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H4;
})(Heading);
module.exports = H4;
},{"./heading":14}],12:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H5 = (function (Heading) {
function H5() {
if (Object.getPrototypeOf(H5) !== null) {
Object.getPrototypeOf(H5).apply(this, arguments);
}
}
_inherits(H5, Heading);
_prototypeProperties(H5, null, {
level: {
get: function () {
return 5;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{5} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H5;
})(Heading);
module.exports = H5;
},{"./heading":14}],13:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H6 = (function (Heading) {
function H6() {
if (Object.getPrototypeOf(H6) !== null) {
Object.getPrototypeOf(H6).apply(this, arguments);
}
}
_inherits(H6, Heading);
_prototypeProperties(H6, null, {
level: {
get: function () {
return 6;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{6} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H6;
})(Heading);
module.exports = H6;
},{"./heading":14}],14:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./constants").PRE;
var Type = _interopRequire(require("./type"));
var Heading = (function (Type) {
function Heading() {
if (Object.getPrototypeOf(Heading) !== null) {
Object.getPrototypeOf(Heading).apply(this, arguments);
}
}
_inherits(Heading, Type);
_prototypeProperties(Heading, null, {
cssClass: {
get: function () {
return "h" + this.level;
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "H" + this.level;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return new RegExp("^(#{1,6} )(.*)$");
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Heading;
})(Type);
module.exports = Heading;
},{"./constants":7,"./type":20}],15:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var H1 = _interopRequire(require("./h1"));
var H2 = _interopRequire(require("./h2"));
var H3 = _interopRequire(require("./h3"));
var H4 = _interopRequire(require("./h4"));
var H5 = _interopRequire(require("./h5"));
var H6 = _interopRequire(require("./h6"));
var Null = _interopRequire(require("./null"));
var Paragraph = _interopRequire(require("./paragraph"));
var OL = _interopRequire(require("./ol"));
var UL = _interopRequire(require("./ul"));
module.exports = {
H1: H1,
H2: H2,
H3: H3,
H4: H4,
H5: H5,
H6: H6,
Null: Null,
Paragraph: Paragraph,
OL: OL,
UL: UL
};
},{"./h1":8,"./h2":9,"./h3":10,"./h4":11,"./h5":12,"./h6":13,"./null":17,"./ol":18,"./paragraph":19,"./ul":21}],16:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var PRE = require("./constants").PRE;
var List = (function (Type) {
function List() {
if (Object.getPrototypeOf(List) !== null) {
Object.getPrototypeOf(List).apply(this, arguments);
}
}
_inherits(List, Type);
_prototypeProperties(List, null, {
continues: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "li";
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "LI";
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
var listNode = undefined;
if (parent.lastChild && parent.lastChild.nodeName === this.parentNodeName) {
listNode = parent.lastChild;
} else {
listNode = this.createListNode();
}
listNode.appendChild(node);
parent.appendChild(listNode);
},
writable: true,
enumerable: true,
configurable: true
},
createListNode: {
value: function createListNode() {
var ul = document.createElement(this.parentNodeName.toLowerCase());
ul.classList.add("LineBreak");
return ul;
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
var listNode = undefined;
if (oldNode.previousElementSibling && oldNode.previousElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.previousElementSibling;
listNode.appendChild(node);
} else if (oldNode.nextElementSibling && oldNode.nextElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.nextElementSibling;
listNode.insertBefore(node, listNode.firstChild);
} else {
listNode = this.createListNode();
listNode.appendChild(node);
}
listNode.isMoving = true;
oldNode.parentElement.replaceChild(listNode, oldNode);
setTimeout(function () {
return listNode.isMoving = false;
});
},
writable: true,
enumerable: true,
configurable: true
}
});
return List;
})(Type);
module.exports = List;
},{"./constants":7,"./type":20}],17:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Null = (function (Type) {
function Null() {
if (Object.getPrototypeOf(Null) !== null) {
Object.getPrototypeOf(Null).apply(this, arguments);
}
}
_inherits(Null, Type);
_prototypeProperties(Null, null, {
isNull: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Null;
})(Type);
module.exports = Null;
},{"./type":20}],18:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var OL = (function (List) {
function OL() {
if (Object.getPrototypeOf(OL) !== null) {
Object.getPrototypeOf(OL).apply(this, arguments);
}
}
_inherits(OL, List);
_prototypeProperties(OL, null, {
cssClass: {
get: function () {
return "ol-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "OL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(\d+\. )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return OL;
})(List);
module.exports = OL;
},{"./list":16}],19:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Paragraph = (function (Type) {
function Paragraph() {
if (Object.getPrototypeOf(Paragraph) !== null) {
Object.getPrototypeOf(Paragraph).apply(this, arguments);
}
}
_inherits(Paragraph, Type);
_prototypeProperties(Paragraph, null, {
cssClass: {
get: function () {
return "p";
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "P";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(.*)$/;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Paragraph;
})(Type);
module.exports = Paragraph;
},{"./type":20}],20:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Type = (function () {
function Type() {}
_prototypeProperties(Type, null, {
continues: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "";
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isNull: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "DIV";
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
parent.appendChild(node);
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement(this.nodeName.toLowerCase());
node.className = "Block LineBreak";
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBefore: {
value: function insertBefore(node, next, parent) {
parent.insertBefore(node, next);
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
oldNode.parentElement.replaceChild(node, oldNode);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Type;
})();
module.exports = Type;
},{}],21:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var UL = (function (List) {
function UL() {
if (Object.getPrototypeOf(UL) !== null) {
Object.getPrototypeOf(UL).apply(this, arguments);
}
}
_inherits(UL, List);
_prototypeProperties(UL, null, {
cssClass: {
get: function () {
return "ul-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "UL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(- )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return UL;
})(List);
module.exports = UL;
},{"./list":16}]},{},[5])
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
"use strict";
!(function (e) {
if ("object" == typeof exports) module.exports = e();else if ("function" == typeof define && define.amd) define(e);else {
var f;"undefined" != typeof window ? f = window : "undefined" != typeof global ? f = global : "undefined" != typeof self && (f = self), f.Curse = e();
}
})(function () {
var define, module, exports;return (function e(t, n, r) {
var s = function (o, u) {
if (!n[o]) {
if (!t[o]) {
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);throw new Error("Cannot find module '" + o + "'");
}var f = n[o] = { exports: {} };t[o][0].call(f.exports, function (e) {
var n = t[o][1][e];return s(n ? n : e);
}, f, f.exports, e, t, n, r);
}return n[o].exports;
};
var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) s(r[o]);return s;
})({ 1: [function (_dereq_, module, exports) {
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
/**
* Captures and restores the cursor position inside of an HTML element. This
* is particularly useful for capturing, editing, and restoring selections
* in contenteditable elements, where the selection may span both text nodes
* and element nodes.
*
* var elem = document.querySelector('#editor');
* var curse = new Curse(elem);
* curse.capture();
*
* // ...
*
* curse.restore();
*
* @class Curse
* @constructor
* @param {HTMLElement} element an element to track the cursor inside of
*/
var Curse = (function () {
var Curse = function (element) {
var _ref = arguments[1] === undefined ? {} : arguments[1];
var lineBreak = _ref.lineBreak;
var nodeLengths = _ref.nodeLengths;
this.lineBreak = lineBreak;
this.nodeLengths = nodeLengths || {};
this.element = element;
this.reset();
};
_prototypeProperties(Curse, null, {
iterator: {
/**
* An iterator to iterate over the nodes in `this.element`.
*
* This returns a simple node iterator that skips `this.element`, but not its
* children.
*
* @property iterator
* @private
* @type {NodeIterator}
*/
get: function () {
var elem = this.element;
return document.createNodeIterator(this.element, NodeFilter.SHOW_ALL, function onNode(node) {
return node === elem ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
});
},
enumerable: true,
configurable: true
},
capture: {
/**
* Captures the current selection in the element, by storing "start" and
* "end" integer values. This allows for the text and text nodes to change
* inside the element and still have the Curse be able to restore selection
* state.
*
* A `<br>` tag, for example, is counted as a single "character", while
* a text node with the text "Hello, world" is counted as 12 characters.
*
* @method capture
*/
value: function capture() {
var _window$getSelection = window.getSelection();
var anchorNode = _window$getSelection.anchorNode;
var anchorOffset = _window$getSelection.anchorOffset;
var focusNode = _window$getSelection.focusNode;
var focusOffset = _window$getSelection.focusOffset;
var child = undefined,
start = undefined,
end = undefined;
if (anchorNode === null || focusNode === null) {
this.reset();
return;
}
if (anchorNode.nodeName === "#text") {
start = this.lengthUpTo(anchorNode) + anchorOffset;
} else {
child = anchorNode.childNodes[anchorOffset ? anchorOffset - 1 : 0];
start = this.lengthUpTo(child);
}
if (focusNode.nodeName === "#text") {
end = this.lengthUpTo(focusNode) + focusOffset;
} else {
child = focusNode.childNodes[focusOffset ? focusOffset - 1 : 0];
end = this.lengthUpTo(child) + this.nodeLength(child);
}
this.start = start;
this.end = end;
},
writable: true,
enumerable: true,
configurable: true
},
restore: {
/**
* Restore the captured cursor state by iterating over the child nodes in the
* element and counting their length.
*
* @method restore
* @param {Boolean} [onlyActive=true] only restore if the curse's element is
* the active element
*/
value: function restore() {
var onlyActive = arguments[0] === undefined ? true : arguments[0];
if (onlyActive && document.activeElement !== this.element) {
return;
}
if (!onlyActive) {
this.element.focus();
}
var range = document.createRange();
var idx = 0;
var _ref2 = this;
var start = _ref2.start;
var end = _ref2.end;
var iter = this.iterator;
var node = undefined,
setStart = undefined,
setEnd = undefined;
if (this.start > this.end) {
start = this.end;
end = this.start;
}
while (node = iter.nextNode()) {
if (setStart && setEnd) {
break;
}
var nodeLength = this.nodeLength(node);
var isText = node.nodeName === "#text";
var childIdx = undefined;
if (!setStart && start <= idx + nodeLength) {
if (isText) {
range.setStart(node, start - idx);
} else {
childIdx = this.indexOfNode(node);
range.setStart(node.parentNode, childIdx);
}
setStart = true;
}
if (!setEnd && end <= idx + nodeLength) {
if (isText) {
range.setEnd(node, end - idx);
} else {
childIdx = this.indexOfNode(node);
range.setEnd(node.parentNode, childIdx);
}
setEnd = true;
}
idx += nodeLength;
}
var selection = window.getSelection();
selection.removeAllRanges();
// Reverse the selection if it was originally backwards
if (this.start > this.end) {
var startContainer = range.startContainer;
var startOffset = range.startOffset;
range.collapse(false);
selection.addRange(range);
selection.extend(startContainer, startOffset);
} else {
selection.addRange(range);
}
},
writable: true,
enumerable: true,
configurable: true
},
indexOfNode: {
/**
* Get the index of a node in its parent node.
*
* @method indexOfNode
* @private
* @param {Node} child the child node to find the index of
* @returns {Number} the index of the child node
*/
value: function indexOfNode(child) {
var i = 0;
while (child = child.previousSibling) {
i++;
}
return i;
},
writable: true,
enumerable: true,
configurable: true
},
lengthUpTo: {
/**
* Get the number of characters up to a given node.
*
* @method lengthUpTo
* @private
* @param {Node} node a node to find the length up to
* @returns {Number} the length up to the given node
*/
value: function lengthUpTo(lastNode) {
var len = 0;
var iter = this.iterator;
var node = undefined;
while (node = iter.nextNode()) {
if (node === lastNode) {
break;
}
len += this.nodeLength(node);
}
return len;
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
/**
* Reset the state of the cursor.
*
* @method reset
* @private
*/
value: function reset() {
this.start = null;
this.end = null;
},
writable: true,
enumerable: true,
configurable: true
},
nodeLength: {
/**
* Get the "length" of a node. Text nodes are the length of their contents,
* and `<br>` tags, for example, have a length of 1 (a newline character,
* essentially).
*
* @method nodeLength
* @private
* @param {Node} node a Node, typically a Text or HTMLElement node
* @return {Number} the length of the node, as text
*/
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = undefined;
if (this.lineBreak) {
previousSibling = node.previousElementSibling;
}
if (previousSibling && previousSibling.classList.contains(this.lineBreak)) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return Curse;
})();
module.exports = Curse;
}, {}] }, {}, [1])(1);
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],2:[function(require,module,exports){
(function (global){
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.miniprism=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";
/*
* The syntax parsing algorithm in this file is copied heavily from Lea Verou's
* Prism project, which bears this license:
*
* MIT LICENSE
*
* Copyright (c) 2012-2013 Lea Verou
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var grammars = _dereq_("./grammars");
exports.grammars = grammars;
exports.highlight = function highlight(source, grammarName) {
var opts = arguments[2] === undefined ? {} : arguments[2];
var grammar = undefined;
if (typeof grammarName === "string") {
grammar = grammars[grammarName];
}
if (typeof grammarName === "object" && grammarName.constructor === Object) {
grammar = grammarName;
}
if (!grammar) {
throw new Error("Grammar \"" + grammarName + "\" not found.");
}
return stringify(encode(tokenize(source, grammar)), opts.lineClass);
};
function tokenize(source, grammar) {
var strings = [source];
var inlines = grammar.inlines;
if (inlines) {
// jshint -W089
for (var inlineToken in inlines) {
grammar[inlineToken] = inlines[inlineToken];
}
delete grammar.inlines;
}
for (var token in grammar) {
var patterns = grammar[token];
if (!Array.isArray(patterns)) {
patterns = [patterns];
}
for (var i = 0; i < patterns.length; i++) {
var pattern = patterns[i];
var block = pattern.block;
var classes = pattern.classes;
var inside = pattern.inside;
var lookbehind = !!pattern.lookbehind;
var lookbehindLength = 0;
var tag = undefined;
if (pattern.tag) {
tag = pattern.tag;
} else {
tag = block ? "div" : "span";
}
pattern = pattern.pattern || pattern;
for (var _i = 0; _i < strings.length; _i++) {
var string = strings[_i];
if (typeof string !== "string") {
continue;
}
pattern.lastIndex = 0;
var match = pattern.exec(string);
if (!match) {
continue;
}
if (lookbehind) {
lookbehindLength = match[1].length;
}
var from = match.index - 1 + lookbehindLength;
match = match[0].slice(lookbehindLength);
var len = match.length;
var to = from + len;
var before = string.slice(0, from + 1);
var after = string.slice(to + 1);
var args = [_i, 1];
if (before) {
args.push(before);
}
var wrapped = {
block: block,
classes: classes,
tag: tag,
text: inside ? tokenize(match, inside) : match,
token: token
};
args.push(wrapped);
if (after) {
args.push(after);
}
Array.prototype.splice.apply(strings, args);
}
}
}
return strings;
}
function stringify(source) {
var lineClass = arguments[1] === undefined ? "md-line" : arguments[1];
if (source === "\n") {
return "<br>";
}
if (typeof source === "string") {
return source.replace(/\n/g, "");
}
if (Array.isArray(source)) {
return source.reduce(function addItem(result, item) {
return result + stringify(item, lineClass);
}, "");
}
var tag = source.tag;
var classList = source.classes || source.token.split(" ");
var className = classList.map(function (token) {
return "md-" + token;
}).join(" ");
if (source.block) {
className += " " + lineClass;
}
return ["<" + tag + " class=\"" + className + "\">", stringify(source.text, lineClass), "</" + tag + ">"].join("");
}
function encode(src) {
if (Array.isArray(src)) {
return src.map(encode);
} else if (typeof src === "object") {
src.text = encode(src.text);
return src;
} else {
return escapeHTML(src);
}
}
function escapeHTML(str) {
return str.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/\//g, "&#x2F;");
}
},{"./grammars":2}],2:[function(_dereq_,module,exports){
"use strict";
exports.markdown = _dereq_("./markdown");
},{"./markdown":3}],3:[function(_dereq_,module,exports){
"use strict";
/*
* These regexes are in some places copies of, in others modifications of, and
* in some places wholly unrelated to the Markdown regexes found in the
* Stackedit project, which bears this license:
*
* StackEdit - The Markdown editor powered by PageDown.
* Copyright 2013 Benoit Schweblin (http://www.benoitschweblin.com)
* Licensed under an Apache License (http://www.apache.org/licenses/LICENSE-2.0)
*/
exports.gfm = {
block: true,
pattern: /^`{3}.*\n(?:[\s\S]*?)\n`{3} *(?:\n|$)/gm,
inside: {
"gfm-limit": {
block: true,
pattern: /^`{3}.*(?:\n|$)/gm,
inside: {
"gfm-info": {
lookbehind: true,
pattern: /^(`{3}).+(?:\n|$)/
},
"gfm-fence": /^`{3}(?:\n|$)/gm
}
},
"gfm-line": {
block: true,
pattern: /^.*(?:\n|$)/gm
} }
};
exports.blank = [{
block: true,
pattern: /\n(?![\s\S])/mg
}, {
block: true,
pattern: /^\n/mg
}];
exports["setex-h1"] = {
block: true,
pattern: /^.+\n=+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^=].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^=+[ \t]*(?:\n|$)/
}
}
};
exports["setex-h2"] = {
block: true,
pattern: /^(?!^- ).+\n-+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^-].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^-+[ \t]*(?:\n|$)/
}
}
};
exports.code = {
block: true,
pattern: /^(?: {4,}|\t).+(?:\n|$)/gm
};
// h1 through h6
for (var i = 1; i < 7; i++) {
exports["h" + i] = {
classes: ["h" + i, "has-folding"],
block: true,
pattern: new RegExp("^#{" + i + "} .*(?:\n|$)", "gm"),
inside: {
"hash folding": new RegExp("^#{" + i + "} ")
}
};
}
exports.ul = {
classes: ["ul", "has-folding"],
block: true,
pattern: /^[ \t]*(?:[*+\-])[ \t].*(?:\n|$)/gm,
inside: {
"ul-marker folding": /^[ \t]*(?:[*+\-])[ \t]/
}
};
exports.ol = {
block: true,
pattern: /^[ \t]*(?:\d+)\.[ \t].*(?:\n|$)/gm,
inside: {
"ol-marker": /^[ \t]*(?:\d+)\.[ \t]/
}
};
exports.blockquote = {
block: true,
pattern: /^ {0,3}> *.*(?:\n|$)/gm,
inside: {
"blockquote-marker": /^ {0,3}> */
}
};
exports.hr = {
block: true,
pattern: /^(?:[*\-_] *){3,}(?:\n|$)/gm
};
exports["link-def"] = {
block: true,
pattern: /^ {0,3}\[.*?\]:[ \t]+.+(?:\n|$)/gm,
inside: {
"link-def-name": {
pattern: /^ {0,3}\[.*?\]:/,
inside: {
"bracket-start": /^\[/,
"bracket-end": /\](?=:$)/,
colon: /:$/
}
},
"link-def-value": /.*(?:\n|$)/
}
};
exports.p = {
block: true,
pattern: /^.+(?:\n|$)/gm,
inside: {}
};
// jshint -W101
exports.link = {
classes: ["link", "has-folding"],
pattern: /\[(?:(?:\\.)|[^\[\]])*\]\([^\(\)\s]+(?:\(\S*?\))??[^\(\)\s]*?(?:\s(?:['‘][^'’]*['’]|["“][^"”]*["”]))?\)/gm,
inside: {
"bracket-start folding": {
pattern: /(^|[^\\])\[/,
lookbehind: true
},
ref: /(?:(?:\\.)|[^\[\]])+(?=\])/,
"bracket-end folding": /\](?=\s?\()/,
"paren-start folding": /^\(/,
"paren-end folding": /\)$/,
"href folding": /.*/
}
};
// jshint +W101
exports["link-ref"] = {
classes: ["link-ref", "has-folding"],
pattern: /\[(?:.*?)\] ?\[(?:.*?)\]/g,
inside: {
"ref-value folding": {
pattern: /\[[^\[\]]+\]$/,
inside: {
"bracket-start": /\[/,
"ref-href": /[^\[\]]+(?=]$)/,
"bracket-end": /\]/
}
},
"ref-text": {
pattern: /^\[[^\[\]]+\]/,
inside: {
"bracket-start folding": /^\[/,
ref: /^[^\[\]]+/,
"bracket-end folding": /\]$/
}
}
}
};
exports.em = {
classes: ["em", "has-folding"],
pattern: /(^|[^\\])(\*|_)(\S[^\2]*?)??[^\s\\]+?\2/g,
lookbehind: true,
inside: {
"em-marker folding": /(?:^(?:\*|_))|(?:(?:\*|_)$)/
}
};
exports.strong = {
classes: ["strong", "has-folding"],
pattern: /([_\*]){2}(?:(?!\1{2}).)*\1{2}/g,
inside: {
"strong-marker folding": /(?:^(?:\*|_){2})|(?:(?:\*|_){2}$)/
}
};
exports["inline-code"] = {
classes: ["inline-code", "has-folding"],
pattern: /(^|[^\\])`(\S[^`]*?)??[^\s\\]+?`/g,
lookbehind: true,
inside: {
"inline-code-marker folding": /(?:^(?:`))|(?:(?:`)$)/
}
};
var inlines = {
strong: exports.strong,
em: exports.em,
link: exports.link,
"inline-code": exports["inline-code"],
"link-ref": exports["link-ref"]
};
["setex-h1", "setex-h2", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "blockquote", "p"].forEach(function (token) {
exports[token].inside.inlines = inlines;
});
["em", "strong"].forEach(function (token) {
exports[token].inside = exports[token].inside || {};
exports[token].inside.inlines = {
link: exports.link,
"link-ref": exports["link-ref"]
};
});
},{}]},{},[1])
(1)
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./types/constants").PRE;
var blocks = require("./grammar").blocks;
var Null = require("./types").Null;
var OL = require("./types").OL;
var miniprism = _interopRequire(require("miniprism"));
// Standard inlines:
var inlines = miniprism.grammars.markdown.p.inside.inlines;
var slice = Array.prototype.slice;
var Block = (function () {
function Block(editor, _ref) {
var node = _ref.node;
var pre = _ref.pre;
var source = _ref.source;
var type = _ref.type;
this.editor = editor;
this.type = type || new Null();
this.pre = pre || "";
this.content = source;
this.node = node || this.type.createNode();
this.render(true); // (isFirstRender)
}
_prototypeProperties(Block, null, {
source: {
get: function () {
if (this.type.constructor === OL) {
var children = this.node.parentElement ? slice.call(this.node.parentElement.childNodes) : [];
var digit = children.indexOf(this.node) + 1;
return "" + digit + ". " + this._content;
} else {
return this.pre + this._content;
}
},
enumerable: true,
configurable: true
},
content: {
get: function () {
if (this.type.isHeading) {
return "" + this.pre + "" + this._content;
} else {
return this._content;
}
},
set: function (content) {
this._content = content;
var match = undefined,
type = undefined;
if (this.type.isHeading && !content) {
this.type = new Null();
this.pre = "";
}
if (!this.type.shouldReparse) {
return;
}
// jshint -W089
for (var i = 0, len = blocks.length; i < len; i++) {
type = blocks[i];
if (match = content.match(type.pattern)) {
break;
}
}
this.type = type;
this._content = "";
match = match.slice(1);
var labels = type.labels;
for (var i = 0, len = match.length; i < len; i++) {
if (labels[i] === PRE) {
this.pre = match[i];
} else {
this._content += match[i];
}
}
},
enumerable: true,
configurable: true
},
html: {
get: function () {
if (this.type.isHeading) {
return "<span class=\"md-pre\">" + esc(this.pre) + "</span>" + ("" + miniprism.highlight(this._content, inlines));
} else {
return miniprism.highlight(this._content, inlines);
}
},
enumerable: true,
configurable: true
},
shouldContinue: {
get: function () {
return this.type.continues && this.content;
},
enumerable: true,
configurable: true
},
type: {
get: function () {
return this._type;
},
set: function (type) {
this.adjustedPre = false;
this.pre = "";
return this._type = type;
},
enumerable: true,
configurable: true
},
appendTo: {
value: function appendTo(node) {
this.type.appendChild(this.node, node);
},
writable: true,
enumerable: true,
configurable: true
},
clone: {
value: function clone() {
return new this.constructor(this.editor, {
node: this.node.cloneNode(true),
pre: this.pre,
source: this.content,
type: this.type
});
},
writable: true,
enumerable: true,
configurable: true
},
continueFrom: {
value: function continueFrom(block) {
this.type = block.type;
this.pre = block.pre;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
var isFirstRender = arguments[0] === undefined ? false : arguments[0];
if (this.content === this.node.textContent && !isFirstRender) {
return;
}
var oldNode = this.node;
var oldType = this.type;
if (!isFirstRender) {
this.content = this.node.textContent;
}
this.editor.curse.capture();
if (oldType !== this.type) {
this.node = this.type.createNode();
this.type.replaceNode(this.node, oldNode);
}
/*
* Adjust the Curse for `pre` since it is about to be removed from the
* DOM during `#render`. This does not apply to reparsing types, as their
* `pre` is still displayed when focused.
*/
if (!this.adjustedPre && !this.type.shouldReparse) {
this.editor.curse.start -= this.pre.length;
this.editor.curse.end -= this.pre.length;
this.adjustedPre = true;
}
if (this.content) {
this.node.innerHTML = this.html;
} else {
this.node.innerHTML = "<br>";
}
this.editor.curse.restore();
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
value: function reset() {
this.type = new Null();
this.content = this.content;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
selectionSubstring: {
value: function selectionSubstring(sel) {
var anchorNode = sel.anchorNode;
var focusNode = sel.focusNode;
var anchorOffset = sel.anchorOffset;
var focusOffset = sel.focusOffset;
var start = 0;
var end = Infinity;
var curse = this.editor.curse;
if (this.node.contains(anchorNode)) {
start = curse.lengthUpTo(anchorNode) - curse.lengthUpTo(this.node.firstChild) + anchorOffset;
if (this.type.isList) {
start += this.pre.length;
}
}
if (this.node.contains(focusNode)) {
end = curse.lengthUpTo(focusNode) - curse.lengthUpTo(this.node.firstChild) + focusOffset;
if (this.type.isList) {
end += this.pre.length;
}
}
return this.source.substring(start, end);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Block;
})();
module.exports = Block;
function esc(text) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(text));
return div.innerHTML;
}
},{"./grammar":6,"./types":15,"./types/constants":7,"miniprism":2}],4:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Curse = _interopRequire(require("../bower_components/curse/dist/curse"));
var _Curse = (function (Curse) {
function _Curse() {
if (Object.getPrototypeOf(_Curse) !== null) {
Object.getPrototypeOf(_Curse).apply(this, arguments);
}
}
_inherits(_Curse, Curse);
_prototypeProperties(_Curse, null, {
nodeLength: {
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = node.previousElementSibling;
if (previousSibling && previousSibling.classList.contains("LineBreak")) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return _Curse;
})(Curse);
module.exports = _Curse;
},{"../bower_components/curse/dist/curse":1}],5:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Block = _interopRequire(require("./block"));
var Curse = _interopRequire(require("./curse"));
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var BACKSPACE = 8;
var RETURN = 13;
var slice = Array.prototype.slice;
var Editor = (function () {
function Editor() {
var source = arguments[0] === undefined ? "" : arguments[0];
this.blocks = [];
this.node = this.createNode();
this.curse = new Curse(this.node, {
nodeLengths: { BR: 0 }
});
this.source = source;
this.bindEvents();
this.observeMutations();
}
_prototypeProperties(Editor, null, {
anchorNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentAnchor);
},
enumerable: true,
configurable: true
},
focusNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentFocus);
},
enumerable: true,
configurable: true
},
blockNodes: {
get: function () {
return this.blocks.map(function (block) {
return block.node;
});
},
enumerable: true,
configurable: true
},
currentAnchor: {
get: function () {
return this.getNode(window.getSelection().anchorNode);
},
enumerable: true,
configurable: true
},
currentBlock: {
get: function () {
return this.getBlockFromNode(this.currentNode);
},
enumerable: true,
configurable: true
},
currentFocus: {
get: function () {
return this.getNode(window.getSelection().focusNode);
},
enumerable: true,
configurable: true
},
currentNode: {
get: function () {
if (!this.isActive) {
return null;
}
if (this.isReversed) {
return this.currentFocus;
} else {
return this.currentAnchor;
}
},
enumerable: true,
configurable: true
},
foldingNodes: {
get: function () {
return slice.call(this.node.querySelectorAll(".md-folding, .md-pre"));
},
enumerable: true,
configurable: true
},
isActive: {
get: function () {
return document.activeElement === this.node;
},
enumerable: true,
configurable: true
},
isReversed: {
get: function () {
var _ref = this;
var currentAnchor = _ref.currentAnchor;
var currentFocus = _ref.currentFocus;
var nodes = _ref.nodes;
return nodes.indexOf(currentAnchor) > nodes.indexOf(currentFocus);
},
enumerable: true,
configurable: true
},
nodes: {
get: function () {
var nodeList = this.node.querySelectorAll(".Block");
return slice.call(nodeList);
},
enumerable: true,
configurable: true
},
toggleFoldingFn: {
get: function () {
if (this._toggleFoldingFn) {
return this._toggleFoldingFn;
}
return this._toggleFoldingFn = this.toggleFolding.bind(this);
},
enumerable: true,
configurable: true
},
source: {
get: function () {
return this.blocks.map(function (block) {
return block.source;
}).join("\n");
},
set: function (source) {
var _this = this;
this.blocks = source.split(/\n/).map(function (line) {
return new Block(_this, { source: line });
});
this.render();
},
enumerable: true,
configurable: true
},
bindEvents: {
value: function bindEvents() {
document.addEventListener("selectionchange", this.toggleFoldingFn);
this.node.addEventListener("input", this.startRenders.bind(this));
this.node.addEventListener("input", this.toggleFoldingFn);
this.node.addEventListener("keydown", this.onReturn.bind(this));
this.node.addEventListener("keydown", this.preventEmpty.bind(this));
this.node.addEventListener("copy", this.onCopy.bind(this));
this.node.addEventListener("cut", this.onCopy.bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement("div");
node.classList.add("Editor");
node.setAttribute("contenteditable", true);
return node;
},
writable: true,
enumerable: true,
configurable: true
},
eachSelectionNode: {
value: function eachSelectionNode(fn) {
var sel = window.getSelection();
var pointTypes = sel.isCollapsed ? ["anchor"] : ["anchor", "focus"];
for (var i = 0, len = pointTypes.length; i < len; i++) {
var pointType = pointTypes[i];
var node = sel["" + pointType + "Node"];
var offset = sel["" + pointType + "Offset"];
fn(node, offset, sel);
}
},
writable: true,
enumerable: true,
configurable: true
},
focusBlock: {
value: function focusBlock(block, hasContent) {
var range = document.createRange();
var sel = window.getSelection();
var pos = hasContent ? 0 : block.node.childNodes.length;
range.setStart(block.node, pos);
range.setEnd(block.node, pos);
sel.removeAllRanges();
sel.addRange(range);
},
writable: true,
enumerable: true,
configurable: true
},
getBlockFromNode: {
value: function getBlockFromNode(node) {
return this.blocks[this.nodes.indexOf(node)];
},
writable: true,
enumerable: true,
configurable: true
},
getNode: {
value: function getNode(node) {
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
while (!node.classList.contains("Block")) {
node = node.parentElement;
}
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBlock: {
value: function insertBlock(block, prevBlock, nextElementSibling) {
var parentNode = this.node;
var prevNode = prevBlock.node;
var prevParent = prevNode.parentElement;
if (prevBlock.shouldContinue) {
parentNode = prevParent;
block.continueFrom(prevBlock);
} else if (prevBlock.type.continues) {
block.reset();
block.content = block.content;
this.splitBlock(prevParent, prevNode);
prevNode.remove();
if (prevParent.childNodes.length === 0) {
nextElementSibling = prevParent.nextElementSibling;
prevParent.remove();
} else {
nextElementSibling = prevParent;
}
}
block.type.insertBefore(block.node, nextElementSibling, parentNode);
},
writable: true,
enumerable: true,
configurable: true
},
observeMutations: {
value: function observeMutations() {
new MutationObserver(this.onMutation.bind(this)).observe(this.node, { childList: true, subtree: true });
},
writable: true,
enumerable: true,
configurable: true
},
onMutation: {
value: function onMutation(mutationRecords) {
for (var i = 0, len = mutationRecords.length; i < len; i++) {
var mut = mutationRecords[i];
for (var _i = 0, _len = mut.removedNodes.length; _i < _len; _i++) {
this.removeNodes(mut.removedNodes);
}
}
},
writable: true,
enumerable: true,
configurable: true
},
onCopy: {
value: function onCopy(e) {
this.copying = true;
var sel = window.getSelection();
var range = sel.getRangeAt(0);
var copyBin = document.createElement("pre");
var text = "";
var anc = this.anchorNodeBlock;
var foc = this.focusNodeBlock;
var nodes = this.nodes;
text += anc.selectionSubstring(sel) + "\n";
var started = undefined;
for (var i = 0, len = nodes.length; i < len; i++) {
if (foc.node === nodes[i]) {
break;
}
if (anc.node === nodes[i]) {
started = true;
continue;
}
if (started) {
text += this.getBlockFromNode(nodes[i]).source + "\n";
}
}
if (anc !== foc) {
text += foc.selectionSubstring(sel);
}
copyBin.classList.add("CopyBin");
copyBin.textContent = text;
this.node.appendChild(copyBin);
var newRange = document.createRange();
newRange.selectNodeContents(copyBin);
sel.removeAllRanges();
sel.addRange(newRange);
setTimeout((function () {
copyBin.remove();
sel.removeAllRanges();
sel.addRange(range);
this.copying = false;
if (e.type === "cut") {
document.execCommand("insertText", null, "");
}
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
onReturn: {
value: function onReturn(e) {
if (e.keyCode !== RETURN) {
return;
}
e.preventDefault();
var _ref2 = this;
var currentAnchor = _ref2.currentAnchor;
var currentFocus = _ref2.currentFocus;
var currentNode = _ref2.currentNode;
var isReversed = _ref2.isReversed;
var startNode = isReversed ? currentFocus : currentAnchor;
var endNode = isReversed ? currentAnchor : currentFocus;
var nextElementSibling = endNode.nextElementSibling;
var range = window.getSelection().getRangeAt(0);
var collapsed = range.collapsed;
var startContainer = range.startContainer;
var endContainer = range.endContainer;
var startOffset = range.startOffset;
var endOffset = range.endOffset;
// In a copy of the range, select the entire end node of the selection
var rangeCopy = range.cloneRange();
rangeCopy.selectNodeContents(endNode);
// In the range copy, select only the text in the current node *after* the
// user's current selection.
if (range.collapsed) {
rangeCopy.setStart(startContainer, startOffset);
} else {
rangeCopy.setStart(endContainer, endOffset);
}
// Set the text after the user's selection to `source` so that it can be
// inserted into the new block being created.
var source = rangeCopy.toString();
var block = undefined;
if (endContainer === this.node || endOffset === 0) {
block = this.getBlockFromNode(endNode).clone();
} else {
block = new Block(this, { source: source });
}
rangeCopy.deleteContents();
// Delete the content selected by the user
range.deleteContents();
if (currentNode.textContent === "") {
currentNode.innerHTML = "<br>";
}
var idx = this.nodes.indexOf(currentNode) + 1;
this.blocks.splice(idx, 0, block);
this.insertBlock(block, this.blocks[idx - 1], nextElementSibling);
this.focusBlock(block, source);
// When not collapsed remove the end node since we're recreating it with its
// remaining contents.
if (!collapsed && startNode !== endNode) {
endNode.remove();
}
// Manually dispatch an `input` event since we called `preventDefault`.
this.node.dispatchEvent(new Event("input"));
},
writable: true,
enumerable: true,
configurable: true
},
toggleFolding: {
value: function toggleFolding() {
if (this.copying) {
return;
}
this.foldingNodes.forEach(function (node) {
return node.classList.remove("visible");
});
if (!this.isActive) {
return;
}
var range = window.getSelection().getRangeAt(0);
this.foldingNodes.forEach(function (node) {
if (range.intersectsNode(node)) {
node.classList.add("visible");
}
});
slice.call(this.currentNode.querySelectorAll(".md-pre")).forEach(function (node) {
return node.classList.add("visible");
});
this.eachSelectionNode((function maybeAddVisible(node, offset) {
var nextSibling = node.nextElementSibling;
if (nextSibling && nextSibling.classList.contains("md-has-folding") && offset === node.textContent.length) {
node = nextSibling;
}
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
if (!node.classList.contains("md-has-folding")) {
var parentEl = undefined;
var testNode = node;
while (parentEl = testNode.parentElement) {
testNode = parentEl;
if (parentEl.classList.contains("md-has-folding")) {
node = parentEl;
}
if (parentEl.classList.contains("Block")) {
break;
}
}
}
if (!node.classList.contains("md-has-folding")) {
return;
}
slice.call(node.querySelectorAll(".md-folding")).forEach(function (node) {
return node.classList.add("visible");
});
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
preventEmpty: {
value: function preventEmpty(e) {
if (!(window.getSelection().isCollapsed && e.keyCode === BACKSPACE)) {
return;
}
var currentNode = this.currentNode;
if (currentNode.textContent === "" && currentNode === this.nodes[0]) {
e.preventDefault();
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNode: {
value: function removeNode(node) {
if (!node.classList.contains("Block")) {
return;
}
var idx = this.blockNodes.indexOf(node);
if (idx !== -1 && !node.isMoving) {
this.blocks.splice(idx, 1);
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNodes: {
value: function removeNodes(nodes) {
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i];
if (node.nodeType !== ELEMENT_NODE || node.isMoving) {
continue;
}
if (node.classList.contains("Block")) {
this.removeNode(nodes[i]);
} else {
var children = node.querySelectorAll(".Block");
for (var _i2 = 0, _len2 = children.length; _i2 < _len2; _i2++) {
this.removeNode(children[_i2]);
}
}
}
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
this.innerHTML = "";
for (var i = 0, len = this.blocks.length; i < len; i++) {
this.blocks[i].appendTo(this.node);
}
},
writable: true,
enumerable: true,
configurable: true
},
splitBlock: {
value: function splitBlock(block, node) {
var blockOne = block.cloneNode();
// Cache, since we're removing some.
var children = slice.call(block.childNodes);
_loop: for (var i = 0, len = children.length; i < len; i++) {
var _ret = (function (i, len) {
var childNode = children[i];
if (childNode !== node) {
childNode.isMoving = true;
blockOne.appendChild(childNode);
setTimeout(function () {
return childNode.isMoving = false;
});
} else {
return "break";
}
})(i, len);
if (_ret === "break") break _loop;
}
if (blockOne.childNodes.length > 0) {
block.parentElement.insertBefore(blockOne, block);
}
return [blockOne, block];
},
writable: true,
enumerable: true,
configurable: true
},
startRenders: {
value: function startRenders() {
this.blocks.forEach(function (block) {
return block.render();
});
},
writable: true,
enumerable: true,
configurable: true
},
teardown: {
value: function teardown() {
document.removeEventListener("selectionchange", this.toggleFoldingFn);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Editor;
})();
module.exports = Editor;
},{"./block":3,"./curse":4}],6:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var types = _interopRequire(require("./types"));
var grammar = { blocks: [] };
for (var i = 1; i <= 6; i++) {
grammar.blocks.push(new types["H" + i]());
}
grammar.blocks.push(new types.OL());
grammar.blocks.push(new types.UL());
grammar.blocks.push(new types.Paragraph());
module.exports = grammar;
},{"./types":15}],7:[function(require,module,exports){
"use strict";
module.exports = {
PRE: -1
};
},{}],8:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H1 = (function (Heading) {
function H1() {
if (Object.getPrototypeOf(H1) !== null) {
Object.getPrototypeOf(H1).apply(this, arguments);
}
}
_inherits(H1, Heading);
_prototypeProperties(H1, null, {
level: {
get: function () {
return 1;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(# )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H1;
})(Heading);
module.exports = H1;
},{"./heading":14}],9:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H2 = (function (Heading) {
function H2() {
if (Object.getPrototypeOf(H2) !== null) {
Object.getPrototypeOf(H2).apply(this, arguments);
}
}
_inherits(H2, Heading);
_prototypeProperties(H2, null, {
level: {
get: function () {
return 2;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{2} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H2;
})(Heading);
module.exports = H2;
},{"./heading":14}],10:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H3 = (function (Heading) {
function H3() {
if (Object.getPrototypeOf(H3) !== null) {
Object.getPrototypeOf(H3).apply(this, arguments);
}
}
_inherits(H3, Heading);
_prototypeProperties(H3, null, {
level: {
get: function () {
return 3;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{3} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H3;
})(Heading);
module.exports = H3;
},{"./heading":14}],11:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H4 = (function (Heading) {
function H4() {
if (Object.getPrototypeOf(H4) !== null) {
Object.getPrototypeOf(H4).apply(this, arguments);
}
}
_inherits(H4, Heading);
_prototypeProperties(H4, null, {
level: {
get: function () {
return 4;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{4} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H4;
})(Heading);
module.exports = H4;
},{"./heading":14}],12:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H5 = (function (Heading) {
function H5() {
if (Object.getPrototypeOf(H5) !== null) {
Object.getPrototypeOf(H5).apply(this, arguments);
}
}
_inherits(H5, Heading);
_prototypeProperties(H5, null, {
level: {
get: function () {
return 5;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{5} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H5;
})(Heading);
module.exports = H5;
},{"./heading":14}],13:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H6 = (function (Heading) {
function H6() {
if (Object.getPrototypeOf(H6) !== null) {
Object.getPrototypeOf(H6).apply(this, arguments);
}
}
_inherits(H6, Heading);
_prototypeProperties(H6, null, {
level: {
get: function () {
return 6;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{6} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H6;
})(Heading);
module.exports = H6;
},{"./heading":14}],14:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./constants").PRE;
var Type = _interopRequire(require("./type"));
var Heading = (function (Type) {
function Heading() {
if (Object.getPrototypeOf(Heading) !== null) {
Object.getPrototypeOf(Heading).apply(this, arguments);
}
}
_inherits(Heading, Type);
_prototypeProperties(Heading, null, {
cssClass: {
get: function () {
return "h" + this.level;
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "H" + this.level;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return new RegExp("^(#{1,6} )(.*)$");
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Heading;
})(Type);
module.exports = Heading;
},{"./constants":7,"./type":20}],15:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var H1 = _interopRequire(require("./h1"));
var H2 = _interopRequire(require("./h2"));
var H3 = _interopRequire(require("./h3"));
var H4 = _interopRequire(require("./h4"));
var H5 = _interopRequire(require("./h5"));
var H6 = _interopRequire(require("./h6"));
var Null = _interopRequire(require("./null"));
var Paragraph = _interopRequire(require("./paragraph"));
var OL = _interopRequire(require("./ol"));
var UL = _interopRequire(require("./ul"));
module.exports = {
H1: H1,
H2: H2,
H3: H3,
H4: H4,
H5: H5,
H6: H6,
Null: Null,
Paragraph: Paragraph,
OL: OL,
UL: UL
};
},{"./h1":8,"./h2":9,"./h3":10,"./h4":11,"./h5":12,"./h6":13,"./null":17,"./ol":18,"./paragraph":19,"./ul":21}],16:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var PRE = require("./constants").PRE;
var List = (function (Type) {
function List() {
if (Object.getPrototypeOf(List) !== null) {
Object.getPrototypeOf(List).apply(this, arguments);
}
}
_inherits(List, Type);
_prototypeProperties(List, null, {
continues: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "li";
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "LI";
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
var listNode = undefined;
if (parent.lastChild && parent.lastChild.nodeName === this.parentNodeName) {
listNode = parent.lastChild;
} else {
listNode = this.createListNode();
}
listNode.appendChild(node);
parent.appendChild(listNode);
},
writable: true,
enumerable: true,
configurable: true
},
createListNode: {
value: function createListNode() {
var ul = document.createElement(this.parentNodeName.toLowerCase());
ul.classList.add("LineBreak");
return ul;
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
var listNode = undefined;
if (oldNode.previousElementSibling && oldNode.previousElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.previousElementSibling;
listNode.appendChild(node);
} else if (oldNode.nextElementSibling && oldNode.nextElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.nextElementSibling;
listNode.insertBefore(node, listNode.firstChild);
} else {
listNode = this.createListNode();
listNode.appendChild(node);
}
listNode.isMoving = true;
oldNode.parentElement.replaceChild(listNode, oldNode);
setTimeout(function () {
return listNode.isMoving = false;
});
},
writable: true,
enumerable: true,
configurable: true
}
});
return List;
})(Type);
module.exports = List;
},{"./constants":7,"./type":20}],17:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Null = (function (Type) {
function Null() {
if (Object.getPrototypeOf(Null) !== null) {
Object.getPrototypeOf(Null).apply(this, arguments);
}
}
_inherits(Null, Type);
_prototypeProperties(Null, null, {
isNull: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Null;
})(Type);
module.exports = Null;
},{"./type":20}],18:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var OL = (function (List) {
function OL() {
if (Object.getPrototypeOf(OL) !== null) {
Object.getPrototypeOf(OL).apply(this, arguments);
}
}
_inherits(OL, List);
_prototypeProperties(OL, null, {
cssClass: {
get: function () {
return "ol-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "OL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(\d+\. )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return OL;
})(List);
module.exports = OL;
},{"./list":16}],19:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Paragraph = (function (Type) {
function Paragraph() {
if (Object.getPrototypeOf(Paragraph) !== null) {
Object.getPrototypeOf(Paragraph).apply(this, arguments);
}
}
_inherits(Paragraph, Type);
_prototypeProperties(Paragraph, null, {
cssClass: {
get: function () {
return "p";
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "P";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(.*)$/;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Paragraph;
})(Type);
module.exports = Paragraph;
},{"./type":20}],20:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Type = (function () {
function Type() {}
_prototypeProperties(Type, null, {
continues: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "";
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isNull: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "DIV";
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
parent.appendChild(node);
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement(this.nodeName.toLowerCase());
node.className = "Block LineBreak";
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBefore: {
value: function insertBefore(node, next, parent) {
parent.insertBefore(node, next);
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
oldNode.parentElement.replaceChild(node, oldNode);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Type;
})();
module.exports = Type;
},{}],21:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var UL = (function (List) {
function UL() {
if (Object.getPrototypeOf(UL) !== null) {
Object.getPrototypeOf(UL).apply(this, arguments);
}
}
_inherits(UL, List);
_prototypeProperties(UL, null, {
cssClass: {
get: function () {
return "ul-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "UL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(- )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return UL;
})(List);
module.exports = UL;
},{"./list":16}]},{},[5])
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
"use strict";
!(function (e) {
if ("object" == typeof exports) module.exports = e();else if ("function" == typeof define && define.amd) define(e);else {
var f;"undefined" != typeof window ? f = window : "undefined" != typeof global ? f = global : "undefined" != typeof self && (f = self), f.Curse = e();
}
})(function () {
var define, module, exports;return (function e(t, n, r) {
var s = function (o, u) {
if (!n[o]) {
if (!t[o]) {
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);throw new Error("Cannot find module '" + o + "'");
}var f = n[o] = { exports: {} };t[o][0].call(f.exports, function (e) {
var n = t[o][1][e];return s(n ? n : e);
}, f, f.exports, e, t, n, r);
}return n[o].exports;
};
var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) s(r[o]);return s;
})({ 1: [function (_dereq_, module, exports) {
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
/**
* Captures and restores the cursor position inside of an HTML element. This
* is particularly useful for capturing, editing, and restoring selections
* in contenteditable elements, where the selection may span both text nodes
* and element nodes.
*
* var elem = document.querySelector('#editor');
* var curse = new Curse(elem);
* curse.capture();
*
* // ...
*
* curse.restore();
*
* @class Curse
* @constructor
* @param {HTMLElement} element an element to track the cursor inside of
*/
var Curse = (function () {
var Curse = function (element) {
var _ref = arguments[1] === undefined ? {} : arguments[1];
var lineBreak = _ref.lineBreak;
var nodeLengths = _ref.nodeLengths;
this.lineBreak = lineBreak;
this.nodeLengths = nodeLengths || {};
this.element = element;
this.reset();
};
_prototypeProperties(Curse, null, {
iterator: {
/**
* An iterator to iterate over the nodes in `this.element`.
*
* This returns a simple node iterator that skips `this.element`, but not its
* children.
*
* @property iterator
* @private
* @type {NodeIterator}
*/
get: function () {
var elem = this.element;
return document.createNodeIterator(this.element, NodeFilter.SHOW_ALL, function onNode(node) {
return node === elem ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
});
},
enumerable: true,
configurable: true
},
capture: {
/**
* Captures the current selection in the element, by storing "start" and
* "end" integer values. This allows for the text and text nodes to change
* inside the element and still have the Curse be able to restore selection
* state.
*
* A `<br>` tag, for example, is counted as a single "character", while
* a text node with the text "Hello, world" is counted as 12 characters.
*
* @method capture
*/
value: function capture() {
var _window$getSelection = window.getSelection();
var anchorNode = _window$getSelection.anchorNode;
var anchorOffset = _window$getSelection.anchorOffset;
var focusNode = _window$getSelection.focusNode;
var focusOffset = _window$getSelection.focusOffset;
var child = undefined,
start = undefined,
end = undefined;
if (anchorNode === null || focusNode === null) {
this.reset();
return;
}
if (anchorNode.nodeName === "#text") {
start = this.lengthUpTo(anchorNode) + anchorOffset;
} else {
child = anchorNode.childNodes[anchorOffset ? anchorOffset - 1 : 0];
start = this.lengthUpTo(child);
}
if (focusNode.nodeName === "#text") {
end = this.lengthUpTo(focusNode) + focusOffset;
} else {
child = focusNode.childNodes[focusOffset ? focusOffset - 1 : 0];
end = this.lengthUpTo(child) + this.nodeLength(child);
}
this.start = start;
this.end = end;
},
writable: true,
enumerable: true,
configurable: true
},
restore: {
/**
* Restore the captured cursor state by iterating over the child nodes in the
* element and counting their length.
*
* @method restore
* @param {Boolean} [onlyActive=true] only restore if the curse's element is
* the active element
*/
value: function restore() {
var onlyActive = arguments[0] === undefined ? true : arguments[0];
if (onlyActive && document.activeElement !== this.element) {
return;
}
if (!onlyActive) {
this.element.focus();
}
var range = document.createRange();
var idx = 0;
var _ref2 = this;
var start = _ref2.start;
var end = _ref2.end;
var iter = this.iterator;
var node = undefined,
setStart = undefined,
setEnd = undefined;
if (this.start > this.end) {
start = this.end;
end = this.start;
}
while (node = iter.nextNode()) {
if (setStart && setEnd) {
break;
}
var nodeLength = this.nodeLength(node);
var isText = node.nodeName === "#text";
var childIdx = undefined;
if (!setStart && start <= idx + nodeLength) {
if (isText) {
range.setStart(node, start - idx);
} else {
childIdx = this.indexOfNode(node);
range.setStart(node.parentNode, childIdx);
}
setStart = true;
}
if (!setEnd && end <= idx + nodeLength) {
if (isText) {
range.setEnd(node, end - idx);
} else {
childIdx = this.indexOfNode(node);
range.setEnd(node.parentNode, childIdx);
}
setEnd = true;
}
idx += nodeLength;
}
var selection = window.getSelection();
selection.removeAllRanges();
// Reverse the selection if it was originally backwards
if (this.start > this.end) {
var startContainer = range.startContainer;
var startOffset = range.startOffset;
range.collapse(false);
selection.addRange(range);
selection.extend(startContainer, startOffset);
} else {
selection.addRange(range);
}
},
writable: true,
enumerable: true,
configurable: true
},
indexOfNode: {
/**
* Get the index of a node in its parent node.
*
* @method indexOfNode
* @private
* @param {Node} child the child node to find the index of
* @returns {Number} the index of the child node
*/
value: function indexOfNode(child) {
var i = 0;
while (child = child.previousSibling) {
i++;
}
return i;
},
writable: true,
enumerable: true,
configurable: true
},
lengthUpTo: {
/**
* Get the number of characters up to a given node.
*
* @method lengthUpTo
* @private
* @param {Node} node a node to find the length up to
* @returns {Number} the length up to the given node
*/
value: function lengthUpTo(lastNode) {
var len = 0;
var iter = this.iterator;
var node = undefined;
while (node = iter.nextNode()) {
if (node === lastNode) {
break;
}
len += this.nodeLength(node);
}
return len;
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
/**
* Reset the state of the cursor.
*
* @method reset
* @private
*/
value: function reset() {
this.start = null;
this.end = null;
},
writable: true,
enumerable: true,
configurable: true
},
nodeLength: {
/**
* Get the "length" of a node. Text nodes are the length of their contents,
* and `<br>` tags, for example, have a length of 1 (a newline character,
* essentially).
*
* @method nodeLength
* @private
* @param {Node} node a Node, typically a Text or HTMLElement node
* @return {Number} the length of the node, as text
*/
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = undefined;
if (this.lineBreak) {
previousSibling = node.previousElementSibling;
}
if (previousSibling && previousSibling.classList.contains(this.lineBreak)) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return Curse;
})();
module.exports = Curse;
}, {}] }, {}, [1])(1);
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],2:[function(require,module,exports){
(function (global){
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.miniprism=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";
/*
* The syntax parsing algorithm in this file is copied heavily from Lea Verou's
* Prism project, which bears this license:
*
* MIT LICENSE
*
* Copyright (c) 2012-2013 Lea Verou
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var grammars = _dereq_("./grammars");
exports.grammars = grammars;
exports.highlight = function highlight(source, grammarName) {
var opts = arguments[2] === undefined ? {} : arguments[2];
var grammar = undefined;
if (typeof grammarName === "string") {
grammar = grammars[grammarName];
}
if (typeof grammarName === "object" && grammarName.constructor === Object) {
grammar = grammarName;
}
if (!grammar) {
throw new Error("Grammar \"" + grammarName + "\" not found.");
}
return stringify(encode(tokenize(source, grammar)), opts.lineClass);
};
function tokenize(source, grammar) {
var strings = [source];
var inlines = grammar.inlines;
if (inlines) {
// jshint -W089
for (var inlineToken in inlines) {
grammar[inlineToken] = inlines[inlineToken];
}
delete grammar.inlines;
}
for (var token in grammar) {
var patterns = grammar[token];
if (!Array.isArray(patterns)) {
patterns = [patterns];
}
for (var i = 0; i < patterns.length; i++) {
var pattern = patterns[i];
var block = pattern.block;
var classes = pattern.classes;
var inside = pattern.inside;
var lookbehind = !!pattern.lookbehind;
var lookbehindLength = 0;
var tag = undefined;
if (pattern.tag) {
tag = pattern.tag;
} else {
tag = block ? "div" : "span";
}
pattern = pattern.pattern || pattern;
for (var _i = 0; _i < strings.length; _i++) {
var string = strings[_i];
if (typeof string !== "string") {
continue;
}
pattern.lastIndex = 0;
var match = pattern.exec(string);
if (!match) {
continue;
}
if (lookbehind) {
lookbehindLength = match[1].length;
}
var from = match.index - 1 + lookbehindLength;
match = match[0].slice(lookbehindLength);
var len = match.length;
var to = from + len;
var before = string.slice(0, from + 1);
var after = string.slice(to + 1);
var args = [_i, 1];
if (before) {
args.push(before);
}
var wrapped = {
block: block,
classes: classes,
tag: tag,
text: inside ? tokenize(match, inside) : match,
token: token
};
args.push(wrapped);
if (after) {
args.push(after);
}
Array.prototype.splice.apply(strings, args);
}
}
}
return strings;
}
function stringify(source) {
var lineClass = arguments[1] === undefined ? "md-line" : arguments[1];
if (source === "\n") {
return "<br>";
}
if (typeof source === "string") {
return source.replace(/\n/g, "");
}
if (Array.isArray(source)) {
return source.reduce(function addItem(result, item) {
return result + stringify(item, lineClass);
}, "");
}
var tag = source.tag;
var classList = source.classes || source.token.split(" ");
var className = classList.map(function (token) {
return "md-" + token;
}).join(" ");
if (source.block) {
className += " " + lineClass;
}
return ["<" + tag + " class=\"" + className + "\">", stringify(source.text, lineClass), "</" + tag + ">"].join("");
}
function encode(src) {
if (Array.isArray(src)) {
return src.map(encode);
} else if (typeof src === "object") {
src.text = encode(src.text);
return src;
} else {
return escapeHTML(src);
}
}
function escapeHTML(str) {
return str.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/\//g, "&#x2F;");
}
},{"./grammars":2}],2:[function(_dereq_,module,exports){
"use strict";
exports.markdown = _dereq_("./markdown");
},{"./markdown":3}],3:[function(_dereq_,module,exports){
"use strict";
/*
* These regexes are in some places copies of, in others modifications of, and
* in some places wholly unrelated to the Markdown regexes found in the
* Stackedit project, which bears this license:
*
* StackEdit - The Markdown editor powered by PageDown.
* Copyright 2013 Benoit Schweblin (http://www.benoitschweblin.com)
* Licensed under an Apache License (http://www.apache.org/licenses/LICENSE-2.0)
*/
exports.gfm = {
block: true,
pattern: /^`{3}.*\n(?:[\s\S]*?)\n`{3} *(?:\n|$)/gm,
inside: {
"gfm-limit": {
block: true,
pattern: /^`{3}.*(?:\n|$)/gm,
inside: {
"gfm-info": {
lookbehind: true,
pattern: /^(`{3}).+(?:\n|$)/
},
"gfm-fence": /^`{3}(?:\n|$)/gm
}
},
"gfm-line": {
block: true,
pattern: /^.*(?:\n|$)/gm
} }
};
exports.blank = [{
block: true,
pattern: /\n(?![\s\S])/mg
}, {
block: true,
pattern: /^\n/mg
}];
exports["setex-h1"] = {
block: true,
pattern: /^.+\n=+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^=].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^=+[ \t]*(?:\n|$)/
}
}
};
exports["setex-h2"] = {
block: true,
pattern: /^(?!^- ).+\n-+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^-].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^-+[ \t]*(?:\n|$)/
}
}
};
exports.code = {
block: true,
pattern: /^(?: {4,}|\t).+(?:\n|$)/gm
};
// h1 through h6
for (var i = 1; i < 7; i++) {
exports["h" + i] = {
classes: ["h" + i, "has-folding"],
block: true,
pattern: new RegExp("^#{" + i + "} .*(?:\n|$)", "gm"),
inside: {
"hash folding": new RegExp("^#{" + i + "} ")
}
};
}
exports.ul = {
classes: ["ul", "has-folding"],
block: true,
pattern: /^[ \t]*(?:[*+\-])[ \t].*(?:\n|$)/gm,
inside: {
"ul-marker folding": /^[ \t]*(?:[*+\-])[ \t]/
}
};
exports.ol = {
block: true,
pattern: /^[ \t]*(?:\d+)\.[ \t].*(?:\n|$)/gm,
inside: {
"ol-marker": /^[ \t]*(?:\d+)\.[ \t]/
}
};
exports.blockquote = {
block: true,
pattern: /^ {0,3}> *.*(?:\n|$)/gm,
inside: {
"blockquote-marker": /^ {0,3}> */
}
};
exports.hr = {
block: true,
pattern: /^(?:[*\-_] *){3,}(?:\n|$)/gm
};
exports["link-def"] = {
block: true,
pattern: /^ {0,3}\[.*?\]:[ \t]+.+(?:\n|$)/gm,
inside: {
"link-def-name": {
pattern: /^ {0,3}\[.*?\]:/,
inside: {
"bracket-start": /^\[/,
"bracket-end": /\](?=:$)/,
colon: /:$/
}
},
"link-def-value": /.*(?:\n|$)/
}
};
exports.p = {
block: true,
pattern: /^.+(?:\n|$)/gm,
inside: {}
};
// jshint -W101
exports.link = {
classes: ["link", "has-folding"],
pattern: /\[(?:(?:\\.)|[^\[\]])*\]\([^\(\)\s]+(?:\(\S*?\))??[^\(\)\s]*?(?:\s(?:['‘][^'’]*['’]|["“][^"”]*["”]))?\)/gm,
inside: {
"bracket-start folding": {
pattern: /(^|[^\\])\[/,
lookbehind: true
},
ref: /(?:(?:\\.)|[^\[\]])+(?=\])/,
"bracket-end folding": /\](?=\s?\()/,
"paren-start folding": /^\(/,
"paren-end folding": /\)$/,
"href folding": /.*/
}
};
// jshint +W101
exports["link-ref"] = {
classes: ["link-ref", "has-folding"],
pattern: /\[(?:.*?)\] ?\[(?:.*?)\]/g,
inside: {
"ref-value folding": {
pattern: /\[[^\[\]]+\]$/,
inside: {
"bracket-start": /\[/,
"ref-href": /[^\[\]]+(?=]$)/,
"bracket-end": /\]/
}
},
"ref-text": {
pattern: /^\[[^\[\]]+\]/,
inside: {
"bracket-start folding": /^\[/,
ref: /^[^\[\]]+/,
"bracket-end folding": /\]$/
}
}
}
};
exports.em = {
classes: ["em", "has-folding"],
pattern: /(^|[^\\])(\*|_)(\S[^\2]*?)??[^\s\\]+?\2/g,
lookbehind: true,
inside: {
"em-marker folding": /(?:^(?:\*|_))|(?:(?:\*|_)$)/
}
};
exports.strong = {
classes: ["strong", "has-folding"],
pattern: /([_\*]){2}(?:(?!\1{2}).)*\1{2}/g,
inside: {
"strong-marker folding": /(?:^(?:\*|_){2})|(?:(?:\*|_){2}$)/
}
};
exports["inline-code"] = {
classes: ["inline-code", "has-folding"],
pattern: /(^|[^\\])`(\S[^`]*?)??[^\s\\]+?`/g,
lookbehind: true,
inside: {
"inline-code-marker folding": /(?:^(?:`))|(?:(?:`)$)/
}
};
var inlines = {
strong: exports.strong,
em: exports.em,
link: exports.link,
"inline-code": exports["inline-code"],
"link-ref": exports["link-ref"]
};
["setex-h1", "setex-h2", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "blockquote", "p"].forEach(function (token) {
exports[token].inside.inlines = inlines;
});
["em", "strong"].forEach(function (token) {
exports[token].inside = exports[token].inside || {};
exports[token].inside.inlines = {
link: exports.link,
"link-ref": exports["link-ref"]
};
});
},{}]},{},[1])
(1)
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./types/constants").PRE;
var blocks = require("./grammar").blocks;
var Null = require("./types").Null;
var OL = require("./types").OL;
var miniprism = _interopRequire(require("miniprism"));
// Standard inlines:
var inlines = miniprism.grammars.markdown.p.inside.inlines;
var slice = Array.prototype.slice;
var Block = (function () {
function Block(editor, _ref) {
var node = _ref.node;
var pre = _ref.pre;
var source = _ref.source;
var type = _ref.type;
this.editor = editor;
this.type = type || new Null();
this.pre = pre || "";
this.content = source;
this.node = node || this.type.createNode();
this.render(true); // (isFirstRender)
}
_prototypeProperties(Block, null, {
source: {
get: function () {
if (this.type.constructor === OL) {
var children = this.node.parentElement ? slice.call(this.node.parentElement.childNodes) : [];
var digit = children.indexOf(this.node) + 1;
return "" + digit + ". " + this._content;
} else {
return this.pre + this._content;
}
},
enumerable: true,
configurable: true
},
content: {
get: function () {
if (this.type.isHeading) {
return "" + this.pre + "" + this._content;
} else {
return this._content;
}
},
set: function (content) {
this._content = content;
var match = undefined,
type = undefined;
if (this.type.isHeading && !content) {
this.type = new Null();
this.pre = "";
}
if (!this.type.shouldReparse) {
return;
}
// jshint -W089
for (var i = 0, len = blocks.length; i < len; i++) {
type = blocks[i];
if (match = content.match(type.pattern)) {
break;
}
}
this.type = type;
this._content = "";
match = match.slice(1);
var labels = type.labels;
for (var i = 0, len = match.length; i < len; i++) {
if (labels[i] === PRE) {
this.pre = match[i];
} else {
this._content += match[i];
}
}
},
enumerable: true,
configurable: true
},
html: {
get: function () {
if (this.type.isHeading) {
return "<span class=\"md-pre\">" + esc(this.pre) + "</span>" + ("" + miniprism.highlight(this._content, inlines));
} else {
return miniprism.highlight(this._content, inlines);
}
},
enumerable: true,
configurable: true
},
shouldContinue: {
get: function () {
return this.type.continues && this.content;
},
enumerable: true,
configurable: true
},
type: {
get: function () {
return this._type;
},
set: function (type) {
this.adjustedPre = false;
this.pre = "";
return this._type = type;
},
enumerable: true,
configurable: true
},
appendTo: {
value: function appendTo(node) {
this.type.appendChild(this.node, node);
},
writable: true,
enumerable: true,
configurable: true
},
clone: {
value: function clone() {
return new this.constructor(this.editor, {
node: this.node.cloneNode(true),
pre: this.pre,
source: this.content,
type: this.type
});
},
writable: true,
enumerable: true,
configurable: true
},
continueFrom: {
value: function continueFrom(block) {
this.type = block.type;
this.pre = block.pre;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
var isFirstRender = arguments[0] === undefined ? false : arguments[0];
if (this.content === this.node.textContent && !isFirstRender) {
return;
}
var oldNode = this.node;
var oldType = this.type;
if (!isFirstRender) {
this.content = this.node.textContent;
}
this.editor.curse.capture();
if (oldType !== this.type) {
this.node = this.type.createNode();
this.type.replaceNode(this.node, oldNode);
}
/*
* Adjust the Curse for `pre` since it is about to be removed from the
* DOM during `#render`. This does not apply to reparsing types, as their
* `pre` is still displayed when focused.
*/
if (!this.adjustedPre && !this.type.shouldReparse) {
this.editor.curse.start -= this.pre.length;
this.editor.curse.end -= this.pre.length;
this.adjustedPre = true;
}
if (this.content) {
this.node.innerHTML = this.html;
} else {
this.node.innerHTML = "<br>";
}
this.editor.curse.restore();
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
value: function reset() {
this.type = new Null();
this.content = this.content;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
selectionSubstring: {
value: function selectionSubstring(sel) {
var anchorNode = sel.anchorNode;
var focusNode = sel.focusNode;
var anchorOffset = sel.anchorOffset;
var focusOffset = sel.focusOffset;
var start = 0;
var end = Infinity;
var curse = this.editor.curse;
if (this.node.contains(anchorNode)) {
start = curse.lengthUpTo(anchorNode) - curse.lengthUpTo(this.node.firstChild) + anchorOffset;
if (this.type.isList) {
start += this.pre.length;
}
}
if (this.node.contains(focusNode)) {
end = curse.lengthUpTo(focusNode) - curse.lengthUpTo(this.node.firstChild) + focusOffset;
if (this.type.isList) {
end += this.pre.length;
}
}
return this.source.substring(start, end);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Block;
})();
module.exports = Block;
function esc(text) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(text));
return div.innerHTML;
}
},{"./grammar":6,"./types":15,"./types/constants":7,"miniprism":2}],4:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Curse = _interopRequire(require("../bower_components/curse/dist/curse"));
var _Curse = (function (Curse) {
function _Curse() {
if (Object.getPrototypeOf(_Curse) !== null) {
Object.getPrototypeOf(_Curse).apply(this, arguments);
}
}
_inherits(_Curse, Curse);
_prototypeProperties(_Curse, null, {
nodeLength: {
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = node.previousElementSibling;
if (previousSibling && previousSibling.classList.contains("LineBreak")) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return _Curse;
})(Curse);
module.exports = _Curse;
},{"../bower_components/curse/dist/curse":1}],5:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Block = _interopRequire(require("./block"));
var Curse = _interopRequire(require("./curse"));
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var BACKSPACE = 8;
var RETURN = 13;
var slice = Array.prototype.slice;
var Editor = (function () {
function Editor() {
var source = arguments[0] === undefined ? "" : arguments[0];
this.blocks = [];
this.node = this.createNode();
this.curse = new Curse(this.node, {
nodeLengths: { BR: 0 }
});
this.source = source;
this.bindEvents();
this.observeMutations();
}
_prototypeProperties(Editor, null, {
anchorNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentAnchor);
},
enumerable: true,
configurable: true
},
focusNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentFocus);
},
enumerable: true,
configurable: true
},
blockNodes: {
get: function () {
return this.blocks.map(function (block) {
return block.node;
});
},
enumerable: true,
configurable: true
},
currentAnchor: {
get: function () {
return this.getNode(window.getSelection().anchorNode);
},
enumerable: true,
configurable: true
},
currentBlock: {
get: function () {
return this.getBlockFromNode(this.currentNode);
},
enumerable: true,
configurable: true
},
currentFocus: {
get: function () {
return this.getNode(window.getSelection().focusNode);
},
enumerable: true,
configurable: true
},
currentNode: {
get: function () {
if (!this.isActive) {
return null;
}
if (this.isReversed) {
return this.currentFocus;
} else {
return this.currentAnchor;
}
},
enumerable: true,
configurable: true
},
foldingNodes: {
get: function () {
return slice.call(this.node.querySelectorAll(".md-folding, .md-pre"));
},
enumerable: true,
configurable: true
},
isActive: {
get: function () {
return document.activeElement === this.node;
},
enumerable: true,
configurable: true
},
isReversed: {
get: function () {
var _ref = this;
var currentAnchor = _ref.currentAnchor;
var currentFocus = _ref.currentFocus;
var nodes = _ref.nodes;
return nodes.indexOf(currentAnchor) > nodes.indexOf(currentFocus);
},
enumerable: true,
configurable: true
},
nodes: {
get: function () {
var nodeList = this.node.querySelectorAll(".Block");
return slice.call(nodeList);
},
enumerable: true,
configurable: true
},
toggleFoldingFn: {
get: function () {
if (this._toggleFoldingFn) {
return this._toggleFoldingFn;
}
return this._toggleFoldingFn = this.toggleFolding.bind(this);
},
enumerable: true,
configurable: true
},
source: {
get: function () {
return this.blocks.map(function (block) {
return block.source;
}).join("\n");
},
set: function (source) {
var _this = this;
this.blocks = source.split(/\n/).map(function (line) {
return new Block(_this, { source: line });
});
this.render();
},
enumerable: true,
configurable: true
},
bindEvents: {
value: function bindEvents() {
document.addEventListener("selectionchange", this.toggleFoldingFn);
this.node.addEventListener("input", this.startRenders.bind(this));
this.node.addEventListener("input", this.toggleFoldingFn);
this.node.addEventListener("keydown", this.onReturn.bind(this));
this.node.addEventListener("keydown", this.preventEmpty.bind(this));
this.node.addEventListener("copy", this.onCopy.bind(this));
this.node.addEventListener("cut", this.onCopy.bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement("div");
node.classList.add("Editor");
node.setAttribute("contenteditable", true);
return node;
},
writable: true,
enumerable: true,
configurable: true
},
eachSelectionNode: {
value: function eachSelectionNode(fn) {
var sel = window.getSelection();
var pointTypes = sel.isCollapsed ? ["anchor"] : ["anchor", "focus"];
for (var i = 0, len = pointTypes.length; i < len; i++) {
var pointType = pointTypes[i];
var node = sel["" + pointType + "Node"];
var offset = sel["" + pointType + "Offset"];
fn(node, offset, sel);
}
},
writable: true,
enumerable: true,
configurable: true
},
focusBlock: {
value: function focusBlock(block, hasContent) {
var range = document.createRange();
var sel = window.getSelection();
var pos = hasContent ? 0 : block.node.childNodes.length;
range.setStart(block.node, pos);
range.setEnd(block.node, pos);
sel.removeAllRanges();
sel.addRange(range);
},
writable: true,
enumerable: true,
configurable: true
},
getBlockFromNode: {
value: function getBlockFromNode(node) {
return this.blocks[this.nodes.indexOf(node)];
},
writable: true,
enumerable: true,
configurable: true
},
getNode: {
value: function getNode(node) {
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
while (!node.classList.contains("Block")) {
node = node.parentElement;
}
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBlock: {
value: function insertBlock(block, prevBlock, nextElementSibling) {
var parentNode = this.node;
var prevNode = prevBlock.node;
var prevParent = prevNode.parentElement;
if (prevBlock.shouldContinue) {
parentNode = prevParent;
block.continueFrom(prevBlock);
} else if (prevBlock.type.continues) {
block.reset();
block.content = block.content;
this.splitBlock(prevParent, prevNode);
prevNode.remove();
if (prevParent.childNodes.length === 0) {
nextElementSibling = prevParent.nextElementSibling;
prevParent.remove();
} else {
nextElementSibling = prevParent;
}
}
block.type.insertBefore(block.node, nextElementSibling, parentNode);
},
writable: true,
enumerable: true,
configurable: true
},
observeMutations: {
value: function observeMutations() {
new MutationObserver(this.onMutation.bind(this)).observe(this.node, { childList: true, subtree: true });
},
writable: true,
enumerable: true,
configurable: true
},
onMutation: {
value: function onMutation(mutationRecords) {
for (var i = 0, len = mutationRecords.length; i < len; i++) {
var mut = mutationRecords[i];
for (var _i = 0, _len = mut.removedNodes.length; _i < _len; _i++) {
this.removeNodes(mut.removedNodes);
}
}
},
writable: true,
enumerable: true,
configurable: true
},
onCopy: {
value: function onCopy(e) {
this.copying = true;
var sel = window.getSelection();
var range = sel.getRangeAt(0);
var copyBin = document.createElement("pre");
var text = "";
var anc = this.anchorNodeBlock;
var foc = this.focusNodeBlock;
var nodes = this.nodes;
text += anc.selectionSubstring(sel) + "\n";
var started = undefined;
for (var i = 0, len = nodes.length; i < len; i++) {
if (foc.node === nodes[i]) {
break;
}
if (anc.node === nodes[i]) {
started = true;
continue;
}
if (started) {
text += this.getBlockFromNode(nodes[i]).source + "\n";
}
}
if (anc !== foc) {
text += foc.selectionSubstring(sel);
}
copyBin.classList.add("CopyBin");
copyBin.textContent = text;
this.node.appendChild(copyBin);
var newRange = document.createRange();
newRange.selectNodeContents(copyBin);
sel.removeAllRanges();
sel.addRange(newRange);
setTimeout((function () {
copyBin.remove();
sel.removeAllRanges();
sel.addRange(range);
this.copying = false;
if (e.type === "cut") {
document.execCommand("insertText", null, "");
}
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
onReturn: {
value: function onReturn(e) {
if (e.keyCode !== RETURN) {
return;
}
e.preventDefault();
var _ref2 = this;
var currentAnchor = _ref2.currentAnchor;
var currentFocus = _ref2.currentFocus;
var currentNode = _ref2.currentNode;
var isReversed = _ref2.isReversed;
var startNode = isReversed ? currentFocus : currentAnchor;
var endNode = isReversed ? currentAnchor : currentFocus;
var nextElementSibling = endNode.nextElementSibling;
var range = window.getSelection().getRangeAt(0);
var collapsed = range.collapsed;
var startContainer = range.startContainer;
var endContainer = range.endContainer;
var startOffset = range.startOffset;
var endOffset = range.endOffset;
// In a copy of the range, select the entire end node of the selection
var rangeCopy = range.cloneRange();
rangeCopy.selectNodeContents(endNode);
// In the range copy, select only the text in the current node *after* the
// user's current selection.
if (range.collapsed) {
rangeCopy.setStart(startContainer, startOffset);
} else {
rangeCopy.setStart(endContainer, endOffset);
}
// Set the text after the user's selection to `source` so that it can be
// inserted into the new block being created.
var source = rangeCopy.toString();
var block = undefined;
if (endContainer === this.node || endOffset === 0) {
block = this.getBlockFromNode(endNode).clone();
} else {
block = new Block(this, { source: source });
}
rangeCopy.deleteContents();
// Delete the content selected by the user
range.deleteContents();
if (currentNode.textContent === "") {
currentNode.innerHTML = "<br>";
}
var idx = this.nodes.indexOf(currentNode) + 1;
this.blocks.splice(idx, 0, block);
this.insertBlock(block, this.blocks[idx - 1], nextElementSibling);
this.focusBlock(block, source);
// When not collapsed remove the end node since we're recreating it with its
// remaining contents.
if (!collapsed && startNode !== endNode) {
endNode.remove();
}
// Manually dispatch an `input` event since we called `preventDefault`.
this.node.dispatchEvent(new Event("input"));
},
writable: true,
enumerable: true,
configurable: true
},
toggleFolding: {
value: function toggleFolding() {
if (this.copying) {
return;
}
this.foldingNodes.forEach(function (node) {
return node.classList.remove("visible");
});
if (!this.isActive) {
return;
}
var range = window.getSelection().getRangeAt(0);
this.foldingNodes.forEach(function (node) {
if (range.intersectsNode(node)) {
node.classList.add("visible");
}
});
slice.call(this.currentNode.querySelectorAll(".md-pre")).forEach(function (node) {
return node.classList.add("visible");
});
this.eachSelectionNode((function maybeAddVisible(node, offset) {
var nextSibling = node.nextElementSibling;
if (nextSibling && nextSibling.classList.contains("md-has-folding") && offset === node.textContent.length) {
node = nextSibling;
}
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
if (!node.classList.contains("md-has-folding")) {
var parentEl = undefined;
var testNode = node;
while (parentEl = testNode.parentElement) {
testNode = parentEl;
if (parentEl.classList.contains("md-has-folding")) {
node = parentEl;
}
if (parentEl.classList.contains("Block")) {
break;
}
}
}
if (!node.classList.contains("md-has-folding")) {
return;
}
slice.call(node.querySelectorAll(".md-folding")).forEach(function (node) {
return node.classList.add("visible");
});
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
preventEmpty: {
value: function preventEmpty(e) {
if (!(window.getSelection().isCollapsed && e.keyCode === BACKSPACE)) {
return;
}
var currentNode = this.currentNode;
if (currentNode.textContent === "" && currentNode === this.nodes[0]) {
e.preventDefault();
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNode: {
value: function removeNode(node) {
if (!node.classList.contains("Block")) {
return;
}
var idx = this.blockNodes.indexOf(node);
if (idx !== -1 && !node.isMoving) {
this.blocks.splice(idx, 1);
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNodes: {
value: function removeNodes(nodes) {
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i];
if (node.nodeType !== ELEMENT_NODE || node.isMoving) {
continue;
}
if (node.classList.contains("Block")) {
this.removeNode(nodes[i]);
} else {
var children = node.querySelectorAll(".Block");
for (var _i2 = 0, _len2 = children.length; _i2 < _len2; _i2++) {
this.removeNode(children[_i2]);
}
}
}
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
this.innerHTML = "";
for (var i = 0, len = this.blocks.length; i < len; i++) {
this.blocks[i].appendTo(this.node);
}
},
writable: true,
enumerable: true,
configurable: true
},
splitBlock: {
value: function splitBlock(block, node) {
var blockOne = block.cloneNode();
// Cache, since we're removing some.
var children = slice.call(block.childNodes);
_loop: for (var i = 0, len = children.length; i < len; i++) {
var _ret = (function (i, len) {
var childNode = children[i];
if (childNode !== node) {
childNode.isMoving = true;
blockOne.appendChild(childNode);
setTimeout(function () {
return childNode.isMoving = false;
});
} else {
return "break";
}
})(i, len);
if (_ret === "break") break _loop;
}
if (blockOne.childNodes.length > 0) {
block.parentElement.insertBefore(blockOne, block);
}
return [blockOne, block];
},
writable: true,
enumerable: true,
configurable: true
},
startRenders: {
value: function startRenders() {
this.blocks.forEach(function (block) {
return block.render();
});
},
writable: true,
enumerable: true,
configurable: true
},
teardown: {
value: function teardown() {
document.removeEventListener("selectionchange", this.toggleFoldingFn);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Editor;
})();
module.exports = Editor;
},{"./block":3,"./curse":4}],6:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var types = _interopRequire(require("./types"));
var grammar = { blocks: [] };
for (var i = 1; i <= 6; i++) {
grammar.blocks.push(new types["H" + i]());
}
grammar.blocks.push(new types.OL());
grammar.blocks.push(new types.UL());
grammar.blocks.push(new types.Paragraph());
module.exports = grammar;
},{"./types":15}],7:[function(require,module,exports){
"use strict";
module.exports = {
PRE: -1
};
},{}],8:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H1 = (function (Heading) {
function H1() {
if (Object.getPrototypeOf(H1) !== null) {
Object.getPrototypeOf(H1).apply(this, arguments);
}
}
_inherits(H1, Heading);
_prototypeProperties(H1, null, {
level: {
get: function () {
return 1;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(# )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H1;
})(Heading);
module.exports = H1;
},{"./heading":14}],9:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H2 = (function (Heading) {
function H2() {
if (Object.getPrototypeOf(H2) !== null) {
Object.getPrototypeOf(H2).apply(this, arguments);
}
}
_inherits(H2, Heading);
_prototypeProperties(H2, null, {
level: {
get: function () {
return 2;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{2} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H2;
})(Heading);
module.exports = H2;
},{"./heading":14}],10:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H3 = (function (Heading) {
function H3() {
if (Object.getPrototypeOf(H3) !== null) {
Object.getPrototypeOf(H3).apply(this, arguments);
}
}
_inherits(H3, Heading);
_prototypeProperties(H3, null, {
level: {
get: function () {
return 3;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{3} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H3;
})(Heading);
module.exports = H3;
},{"./heading":14}],11:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H4 = (function (Heading) {
function H4() {
if (Object.getPrototypeOf(H4) !== null) {
Object.getPrototypeOf(H4).apply(this, arguments);
}
}
_inherits(H4, Heading);
_prototypeProperties(H4, null, {
level: {
get: function () {
return 4;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{4} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H4;
})(Heading);
module.exports = H4;
},{"./heading":14}],12:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H5 = (function (Heading) {
function H5() {
if (Object.getPrototypeOf(H5) !== null) {
Object.getPrototypeOf(H5).apply(this, arguments);
}
}
_inherits(H5, Heading);
_prototypeProperties(H5, null, {
level: {
get: function () {
return 5;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{5} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H5;
})(Heading);
module.exports = H5;
},{"./heading":14}],13:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H6 = (function (Heading) {
function H6() {
if (Object.getPrototypeOf(H6) !== null) {
Object.getPrototypeOf(H6).apply(this, arguments);
}
}
_inherits(H6, Heading);
_prototypeProperties(H6, null, {
level: {
get: function () {
return 6;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{6} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H6;
})(Heading);
module.exports = H6;
},{"./heading":14}],14:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./constants").PRE;
var Type = _interopRequire(require("./type"));
var Heading = (function (Type) {
function Heading() {
if (Object.getPrototypeOf(Heading) !== null) {
Object.getPrototypeOf(Heading).apply(this, arguments);
}
}
_inherits(Heading, Type);
_prototypeProperties(Heading, null, {
cssClass: {
get: function () {
return "h" + this.level;
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "H" + this.level;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return new RegExp("^(#{1,6} )(.*)$");
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Heading;
})(Type);
module.exports = Heading;
},{"./constants":7,"./type":20}],15:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var H1 = _interopRequire(require("./h1"));
var H2 = _interopRequire(require("./h2"));
var H3 = _interopRequire(require("./h3"));
var H4 = _interopRequire(require("./h4"));
var H5 = _interopRequire(require("./h5"));
var H6 = _interopRequire(require("./h6"));
var Null = _interopRequire(require("./null"));
var Paragraph = _interopRequire(require("./paragraph"));
var OL = _interopRequire(require("./ol"));
var UL = _interopRequire(require("./ul"));
module.exports = {
H1: H1,
H2: H2,
H3: H3,
H4: H4,
H5: H5,
H6: H6,
Null: Null,
Paragraph: Paragraph,
OL: OL,
UL: UL
};
},{"./h1":8,"./h2":9,"./h3":10,"./h4":11,"./h5":12,"./h6":13,"./null":17,"./ol":18,"./paragraph":19,"./ul":21}],16:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var PRE = require("./constants").PRE;
var List = (function (Type) {
function List() {
if (Object.getPrototypeOf(List) !== null) {
Object.getPrototypeOf(List).apply(this, arguments);
}
}
_inherits(List, Type);
_prototypeProperties(List, null, {
continues: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "li";
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "LI";
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
var listNode = undefined;
if (parent.lastChild && parent.lastChild.nodeName === this.parentNodeName) {
listNode = parent.lastChild;
} else {
listNode = this.createListNode();
}
listNode.appendChild(node);
parent.appendChild(listNode);
},
writable: true,
enumerable: true,
configurable: true
},
createListNode: {
value: function createListNode() {
var ul = document.createElement(this.parentNodeName.toLowerCase());
ul.classList.add("LineBreak");
return ul;
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
var listNode = undefined;
if (oldNode.previousElementSibling && oldNode.previousElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.previousElementSibling;
listNode.appendChild(node);
} else if (oldNode.nextElementSibling && oldNode.nextElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.nextElementSibling;
listNode.insertBefore(node, listNode.firstChild);
} else {
listNode = this.createListNode();
listNode.appendChild(node);
}
listNode.isMoving = true;
oldNode.parentElement.replaceChild(listNode, oldNode);
setTimeout(function () {
return listNode.isMoving = false;
});
},
writable: true,
enumerable: true,
configurable: true
}
});
return List;
})(Type);
module.exports = List;
},{"./constants":7,"./type":20}],17:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Null = (function (Type) {
function Null() {
if (Object.getPrototypeOf(Null) !== null) {
Object.getPrototypeOf(Null).apply(this, arguments);
}
}
_inherits(Null, Type);
_prototypeProperties(Null, null, {
isNull: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Null;
})(Type);
module.exports = Null;
},{"./type":20}],18:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var OL = (function (List) {
function OL() {
if (Object.getPrototypeOf(OL) !== null) {
Object.getPrototypeOf(OL).apply(this, arguments);
}
}
_inherits(OL, List);
_prototypeProperties(OL, null, {
cssClass: {
get: function () {
return "ol-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "OL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(\d+\. )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return OL;
})(List);
module.exports = OL;
},{"./list":16}],19:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Paragraph = (function (Type) {
function Paragraph() {
if (Object.getPrototypeOf(Paragraph) !== null) {
Object.getPrototypeOf(Paragraph).apply(this, arguments);
}
}
_inherits(Paragraph, Type);
_prototypeProperties(Paragraph, null, {
cssClass: {
get: function () {
return "p";
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "P";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(.*)$/;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Paragraph;
})(Type);
module.exports = Paragraph;
},{"./type":20}],20:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Type = (function () {
function Type() {}
_prototypeProperties(Type, null, {
continues: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "";
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isNull: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "DIV";
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
parent.appendChild(node);
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement(this.nodeName.toLowerCase());
node.className = "Block LineBreak";
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBefore: {
value: function insertBefore(node, next, parent) {
parent.insertBefore(node, next);
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
oldNode.parentElement.replaceChild(node, oldNode);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Type;
})();
module.exports = Type;
},{}],21:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var UL = (function (List) {
function UL() {
if (Object.getPrototypeOf(UL) !== null) {
Object.getPrototypeOf(UL).apply(this, arguments);
}
}
_inherits(UL, List);
_prototypeProperties(UL, null, {
cssClass: {
get: function () {
return "ul-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "UL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(- )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return UL;
})(List);
module.exports = UL;
},{"./list":16}]},{},[5])
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
"use strict";
!(function (e) {
if ("object" == typeof exports) module.exports = e();else if ("function" == typeof define && define.amd) define(e);else {
var f;"undefined" != typeof window ? f = window : "undefined" != typeof global ? f = global : "undefined" != typeof self && (f = self), f.Curse = e();
}
})(function () {
var define, module, exports;return (function e(t, n, r) {
var s = function (o, u) {
if (!n[o]) {
if (!t[o]) {
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);throw new Error("Cannot find module '" + o + "'");
}var f = n[o] = { exports: {} };t[o][0].call(f.exports, function (e) {
var n = t[o][1][e];return s(n ? n : e);
}, f, f.exports, e, t, n, r);
}return n[o].exports;
};
var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) s(r[o]);return s;
})({ 1: [function (_dereq_, module, exports) {
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
/**
* Captures and restores the cursor position inside of an HTML element. This
* is particularly useful for capturing, editing, and restoring selections
* in contenteditable elements, where the selection may span both text nodes
* and element nodes.
*
* var elem = document.querySelector('#editor');
* var curse = new Curse(elem);
* curse.capture();
*
* // ...
*
* curse.restore();
*
* @class Curse
* @constructor
* @param {HTMLElement} element an element to track the cursor inside of
*/
var Curse = (function () {
var Curse = function (element) {
var _ref = arguments[1] === undefined ? {} : arguments[1];
var lineBreak = _ref.lineBreak;
var nodeLengths = _ref.nodeLengths;
this.lineBreak = lineBreak;
this.nodeLengths = nodeLengths || {};
this.element = element;
this.reset();
};
_prototypeProperties(Curse, null, {
iterator: {
/**
* An iterator to iterate over the nodes in `this.element`.
*
* This returns a simple node iterator that skips `this.element`, but not its
* children.
*
* @property iterator
* @private
* @type {NodeIterator}
*/
get: function () {
var elem = this.element;
return document.createNodeIterator(this.element, NodeFilter.SHOW_ALL, function onNode(node) {
return node === elem ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
});
},
enumerable: true,
configurable: true
},
capture: {
/**
* Captures the current selection in the element, by storing "start" and
* "end" integer values. This allows for the text and text nodes to change
* inside the element and still have the Curse be able to restore selection
* state.
*
* A `<br>` tag, for example, is counted as a single "character", while
* a text node with the text "Hello, world" is counted as 12 characters.
*
* @method capture
*/
value: function capture() {
var _window$getSelection = window.getSelection();
var anchorNode = _window$getSelection.anchorNode;
var anchorOffset = _window$getSelection.anchorOffset;
var focusNode = _window$getSelection.focusNode;
var focusOffset = _window$getSelection.focusOffset;
var child = undefined,
start = undefined,
end = undefined;
if (anchorNode === null || focusNode === null) {
this.reset();
return;
}
if (anchorNode.nodeName === "#text") {
start = this.lengthUpTo(anchorNode) + anchorOffset;
} else {
child = anchorNode.childNodes[anchorOffset ? anchorOffset - 1 : 0];
start = this.lengthUpTo(child);
}
if (focusNode.nodeName === "#text") {
end = this.lengthUpTo(focusNode) + focusOffset;
} else {
child = focusNode.childNodes[focusOffset ? focusOffset - 1 : 0];
end = this.lengthUpTo(child) + this.nodeLength(child);
}
this.start = start;
this.end = end;
},
writable: true,
enumerable: true,
configurable: true
},
restore: {
/**
* Restore the captured cursor state by iterating over the child nodes in the
* element and counting their length.
*
* @method restore
* @param {Boolean} [onlyActive=true] only restore if the curse's element is
* the active element
*/
value: function restore() {
var onlyActive = arguments[0] === undefined ? true : arguments[0];
if (onlyActive && document.activeElement !== this.element) {
return;
}
if (!onlyActive) {
this.element.focus();
}
var range = document.createRange();
var idx = 0;
var _ref2 = this;
var start = _ref2.start;
var end = _ref2.end;
var iter = this.iterator;
var node = undefined,
setStart = undefined,
setEnd = undefined;
if (this.start > this.end) {
start = this.end;
end = this.start;
}
while (node = iter.nextNode()) {
if (setStart && setEnd) {
break;
}
var nodeLength = this.nodeLength(node);
var isText = node.nodeName === "#text";
var childIdx = undefined;
if (!setStart && start <= idx + nodeLength) {
if (isText) {
range.setStart(node, start - idx);
} else {
childIdx = this.indexOfNode(node);
range.setStart(node.parentNode, childIdx);
}
setStart = true;
}
if (!setEnd && end <= idx + nodeLength) {
if (isText) {
range.setEnd(node, end - idx);
} else {
childIdx = this.indexOfNode(node);
range.setEnd(node.parentNode, childIdx);
}
setEnd = true;
}
idx += nodeLength;
}
var selection = window.getSelection();
selection.removeAllRanges();
// Reverse the selection if it was originally backwards
if (this.start > this.end) {
var startContainer = range.startContainer;
var startOffset = range.startOffset;
range.collapse(false);
selection.addRange(range);
selection.extend(startContainer, startOffset);
} else {
selection.addRange(range);
}
},
writable: true,
enumerable: true,
configurable: true
},
indexOfNode: {
/**
* Get the index of a node in its parent node.
*
* @method indexOfNode
* @private
* @param {Node} child the child node to find the index of
* @returns {Number} the index of the child node
*/
value: function indexOfNode(child) {
var i = 0;
while (child = child.previousSibling) {
i++;
}
return i;
},
writable: true,
enumerable: true,
configurable: true
},
lengthUpTo: {
/**
* Get the number of characters up to a given node.
*
* @method lengthUpTo
* @private
* @param {Node} node a node to find the length up to
* @returns {Number} the length up to the given node
*/
value: function lengthUpTo(lastNode) {
var len = 0;
var iter = this.iterator;
var node = undefined;
while (node = iter.nextNode()) {
if (node === lastNode) {
break;
}
len += this.nodeLength(node);
}
return len;
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
/**
* Reset the state of the cursor.
*
* @method reset
* @private
*/
value: function reset() {
this.start = null;
this.end = null;
},
writable: true,
enumerable: true,
configurable: true
},
nodeLength: {
/**
* Get the "length" of a node. Text nodes are the length of their contents,
* and `<br>` tags, for example, have a length of 1 (a newline character,
* essentially).
*
* @method nodeLength
* @private
* @param {Node} node a Node, typically a Text or HTMLElement node
* @return {Number} the length of the node, as text
*/
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = undefined;
if (this.lineBreak) {
previousSibling = node.previousElementSibling;
}
if (previousSibling && previousSibling.classList.contains(this.lineBreak)) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return Curse;
})();
module.exports = Curse;
}, {}] }, {}, [1])(1);
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],2:[function(require,module,exports){
(function (global){
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.miniprism=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";
/*
* The syntax parsing algorithm in this file is copied heavily from Lea Verou's
* Prism project, which bears this license:
*
* MIT LICENSE
*
* Copyright (c) 2012-2013 Lea Verou
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var grammars = _dereq_("./grammars");
exports.grammars = grammars;
exports.highlight = function highlight(source, grammarName) {
var opts = arguments[2] === undefined ? {} : arguments[2];
var grammar = undefined;
if (typeof grammarName === "string") {
grammar = grammars[grammarName];
}
if (typeof grammarName === "object" && grammarName.constructor === Object) {
grammar = grammarName;
}
if (!grammar) {
throw new Error("Grammar \"" + grammarName + "\" not found.");
}
return stringify(encode(tokenize(source, grammar)), opts.lineClass);
};
function tokenize(source, grammar) {
var strings = [source];
var inlines = grammar.inlines;
if (inlines) {
// jshint -W089
for (var inlineToken in inlines) {
grammar[inlineToken] = inlines[inlineToken];
}
delete grammar.inlines;
}
for (var token in grammar) {
var patterns = grammar[token];
if (!Array.isArray(patterns)) {
patterns = [patterns];
}
for (var i = 0; i < patterns.length; i++) {
var pattern = patterns[i];
var block = pattern.block;
var classes = pattern.classes;
var inside = pattern.inside;
var lookbehind = !!pattern.lookbehind;
var lookbehindLength = 0;
var tag = undefined;
if (pattern.tag) {
tag = pattern.tag;
} else {
tag = block ? "div" : "span";
}
pattern = pattern.pattern || pattern;
for (var _i = 0; _i < strings.length; _i++) {
var string = strings[_i];
if (typeof string !== "string") {
continue;
}
pattern.lastIndex = 0;
var match = pattern.exec(string);
if (!match) {
continue;
}
if (lookbehind) {
lookbehindLength = match[1].length;
}
var from = match.index - 1 + lookbehindLength;
match = match[0].slice(lookbehindLength);
var len = match.length;
var to = from + len;
var before = string.slice(0, from + 1);
var after = string.slice(to + 1);
var args = [_i, 1];
if (before) {
args.push(before);
}
var wrapped = {
block: block,
classes: classes,
tag: tag,
text: inside ? tokenize(match, inside) : match,
token: token
};
args.push(wrapped);
if (after) {
args.push(after);
}
Array.prototype.splice.apply(strings, args);
}
}
}
return strings;
}
function stringify(source) {
var lineClass = arguments[1] === undefined ? "md-line" : arguments[1];
if (source === "\n") {
return "<br>";
}
if (typeof source === "string") {
return source.replace(/\n/g, "");
}
if (Array.isArray(source)) {
return source.reduce(function addItem(result, item) {
return result + stringify(item, lineClass);
}, "");
}
var tag = source.tag;
var classList = source.classes || source.token.split(" ");
var className = classList.map(function (token) {
return "md-" + token;
}).join(" ");
if (source.block) {
className += " " + lineClass;
}
return ["<" + tag + " class=\"" + className + "\">", stringify(source.text, lineClass), "</" + tag + ">"].join("");
}
function encode(src) {
if (Array.isArray(src)) {
return src.map(encode);
} else if (typeof src === "object") {
src.text = encode(src.text);
return src;
} else {
return escapeHTML(src);
}
}
function escapeHTML(str) {
return str.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/\//g, "&#x2F;");
}
},{"./grammars":2}],2:[function(_dereq_,module,exports){
"use strict";
exports.markdown = _dereq_("./markdown");
},{"./markdown":3}],3:[function(_dereq_,module,exports){
"use strict";
/*
* These regexes are in some places copies of, in others modifications of, and
* in some places wholly unrelated to the Markdown regexes found in the
* Stackedit project, which bears this license:
*
* StackEdit - The Markdown editor powered by PageDown.
* Copyright 2013 Benoit Schweblin (http://www.benoitschweblin.com)
* Licensed under an Apache License (http://www.apache.org/licenses/LICENSE-2.0)
*/
exports.gfm = {
block: true,
pattern: /^`{3}.*\n(?:[\s\S]*?)\n`{3} *(?:\n|$)/gm,
inside: {
"gfm-limit": {
block: true,
pattern: /^`{3}.*(?:\n|$)/gm,
inside: {
"gfm-info": {
lookbehind: true,
pattern: /^(`{3}).+(?:\n|$)/
},
"gfm-fence": /^`{3}(?:\n|$)/gm
}
},
"gfm-line": {
block: true,
pattern: /^.*(?:\n|$)/gm
} }
};
exports.blank = [{
block: true,
pattern: /\n(?![\s\S])/mg
}, {
block: true,
pattern: /^\n/mg
}];
exports["setex-h1"] = {
block: true,
pattern: /^.+\n=+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^=].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^=+[ \t]*(?:\n|$)/
}
}
};
exports["setex-h2"] = {
block: true,
pattern: /^(?!^- ).+\n-+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^-].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^-+[ \t]*(?:\n|$)/
}
}
};
exports.code = {
block: true,
pattern: /^(?: {4,}|\t).+(?:\n|$)/gm
};
// h1 through h6
for (var i = 1; i < 7; i++) {
exports["h" + i] = {
classes: ["h" + i, "has-folding"],
block: true,
pattern: new RegExp("^#{" + i + "} .*(?:\n|$)", "gm"),
inside: {
"hash folding": new RegExp("^#{" + i + "} ")
}
};
}
exports.ul = {
classes: ["ul", "has-folding"],
block: true,
pattern: /^[ \t]*(?:[*+\-])[ \t].*(?:\n|$)/gm,
inside: {
"ul-marker folding": /^[ \t]*(?:[*+\-])[ \t]/
}
};
exports.ol = {
block: true,
pattern: /^[ \t]*(?:\d+)\.[ \t].*(?:\n|$)/gm,
inside: {
"ol-marker": /^[ \t]*(?:\d+)\.[ \t]/
}
};
exports.blockquote = {
block: true,
pattern: /^ {0,3}> *.*(?:\n|$)/gm,
inside: {
"blockquote-marker": /^ {0,3}> */
}
};
exports.hr = {
block: true,
pattern: /^(?:[*\-_] *){3,}(?:\n|$)/gm
};
exports["link-def"] = {
block: true,
pattern: /^ {0,3}\[.*?\]:[ \t]+.+(?:\n|$)/gm,
inside: {
"link-def-name": {
pattern: /^ {0,3}\[.*?\]:/,
inside: {
"bracket-start": /^\[/,
"bracket-end": /\](?=:$)/,
colon: /:$/
}
},
"link-def-value": /.*(?:\n|$)/
}
};
exports.p = {
block: true,
pattern: /^.+(?:\n|$)/gm,
inside: {}
};
// jshint -W101
exports.link = {
classes: ["link", "has-folding"],
pattern: /\[(?:(?:\\.)|[^\[\]])*\]\([^\(\)\s]+(?:\(\S*?\))??[^\(\)\s]*?(?:\s(?:['‘][^'’]*['’]|["“][^"”]*["”]))?\)/gm,
inside: {
"bracket-start folding": {
pattern: /(^|[^\\])\[/,
lookbehind: true
},
ref: /(?:(?:\\.)|[^\[\]])+(?=\])/,
"bracket-end folding": /\](?=\s?\()/,
"paren-start folding": /^\(/,
"paren-end folding": /\)$/,
"href folding": /.*/
}
};
// jshint +W101
exports["link-ref"] = {
classes: ["link-ref", "has-folding"],
pattern: /\[(?:.*?)\] ?\[(?:.*?)\]/g,
inside: {
"ref-value folding": {
pattern: /\[[^\[\]]+\]$/,
inside: {
"bracket-start": /\[/,
"ref-href": /[^\[\]]+(?=]$)/,
"bracket-end": /\]/
}
},
"ref-text": {
pattern: /^\[[^\[\]]+\]/,
inside: {
"bracket-start folding": /^\[/,
ref: /^[^\[\]]+/,
"bracket-end folding": /\]$/
}
}
}
};
exports.em = {
classes: ["em", "has-folding"],
pattern: /(^|[^\\])(\*|_)(\S[^\2]*?)??[^\s\\]+?\2/g,
lookbehind: true,
inside: {
"em-marker folding": /(?:^(?:\*|_))|(?:(?:\*|_)$)/
}
};
exports.strong = {
classes: ["strong", "has-folding"],
pattern: /([_\*]){2}(?:(?!\1{2}).)*\1{2}/g,
inside: {
"strong-marker folding": /(?:^(?:\*|_){2})|(?:(?:\*|_){2}$)/
}
};
exports["inline-code"] = {
classes: ["inline-code", "has-folding"],
pattern: /(^|[^\\])`(\S[^`]*?)??[^\s\\]+?`/g,
lookbehind: true,
inside: {
"inline-code-marker folding": /(?:^(?:`))|(?:(?:`)$)/
}
};
var inlines = {
strong: exports.strong,
em: exports.em,
link: exports.link,
"inline-code": exports["inline-code"],
"link-ref": exports["link-ref"]
};
["setex-h1", "setex-h2", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "blockquote", "p"].forEach(function (token) {
exports[token].inside.inlines = inlines;
});
["em", "strong"].forEach(function (token) {
exports[token].inside = exports[token].inside || {};
exports[token].inside.inlines = {
link: exports.link,
"link-ref": exports["link-ref"]
};
});
},{}]},{},[1])
(1)
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./types/constants").PRE;
var blocks = require("./grammar").blocks;
var Null = require("./types").Null;
var OL = require("./types").OL;
var miniprism = _interopRequire(require("miniprism"));
// Standard inlines:
var inlines = miniprism.grammars.markdown.p.inside.inlines;
var slice = Array.prototype.slice;
var Block = (function () {
function Block(editor, _ref) {
var node = _ref.node;
var pre = _ref.pre;
var source = _ref.source;
var type = _ref.type;
this.editor = editor;
this.type = type || new Null();
this.pre = pre || "";
this.content = source;
this.node = node || this.type.createNode();
this.render(true); // (isFirstRender)
}
_prototypeProperties(Block, null, {
source: {
get: function () {
if (this.type.constructor === OL) {
var children = this.node.parentElement ? slice.call(this.node.parentElement.childNodes) : [];
var digit = children.indexOf(this.node) + 1;
return "" + digit + ". " + this._content;
} else {
return this.pre + this._content;
}
},
enumerable: true,
configurable: true
},
content: {
get: function () {
if (this.type.isHeading) {
return "" + this.pre + "" + this._content;
} else {
return this._content;
}
},
set: function (content) {
this._content = content;
var match = undefined,
type = undefined;
if (this.type.isHeading && !content) {
this.type = new Null();
this.pre = "";
}
if (!this.type.shouldReparse) {
return;
}
// jshint -W089
for (var i = 0, len = blocks.length; i < len; i++) {
type = blocks[i];
if (match = content.match(type.pattern)) {
break;
}
}
this.type = type;
this._content = "";
match = match.slice(1);
var labels = type.labels;
for (var i = 0, len = match.length; i < len; i++) {
if (labels[i] === PRE) {
this.pre = match[i];
} else {
this._content += match[i];
}
}
},
enumerable: true,
configurable: true
},
html: {
get: function () {
if (this.type.isHeading) {
return "<span class=\"md-pre\">" + esc(this.pre) + "</span>" + ("" + miniprism.highlight(this._content, inlines));
} else {
return miniprism.highlight(this._content, inlines);
}
},
enumerable: true,
configurable: true
},
shouldContinue: {
get: function () {
return this.type.continues && this.content;
},
enumerable: true,
configurable: true
},
type: {
get: function () {
return this._type;
},
set: function (type) {
this.adjustedPre = false;
this.pre = "";
return this._type = type;
},
enumerable: true,
configurable: true
},
appendTo: {
value: function appendTo(node) {
this.type.appendChild(this.node, node);
},
writable: true,
enumerable: true,
configurable: true
},
clone: {
value: function clone() {
return new this.constructor(this.editor, {
node: this.node.cloneNode(true),
pre: this.pre,
source: this.content,
type: this.type
});
},
writable: true,
enumerable: true,
configurable: true
},
continueFrom: {
value: function continueFrom(block) {
this.type = block.type;
this.pre = block.pre;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
var isFirstRender = arguments[0] === undefined ? false : arguments[0];
if (this.content === this.node.textContent && !isFirstRender) {
return;
}
var oldNode = this.node;
var oldType = this.type;
if (!isFirstRender) {
this.content = this.node.textContent;
}
this.editor.curse.capture();
if (oldType !== this.type) {
this.node = this.type.createNode();
this.type.replaceNode(this.node, oldNode);
}
/*
* Adjust the Curse for `pre` since it is about to be removed from the
* DOM during `#render`. This does not apply to reparsing types, as their
* `pre` is still displayed when focused.
*/
if (!this.adjustedPre && !this.type.shouldReparse) {
this.editor.curse.start -= this.pre.length;
this.editor.curse.end -= this.pre.length;
this.adjustedPre = true;
}
if (this.content) {
this.node.innerHTML = this.html;
} else {
this.node.innerHTML = "<br>";
}
this.editor.curse.restore();
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
value: function reset() {
this.type = new Null();
this.content = this.content;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
selectionSubstring: {
value: function selectionSubstring(sel) {
var anchorNode = sel.anchorNode;
var focusNode = sel.focusNode;
var anchorOffset = sel.anchorOffset;
var focusOffset = sel.focusOffset;
var start = 0;
var end = Infinity;
var curse = this.editor.curse;
if (this.node.contains(anchorNode)) {
start = curse.lengthUpTo(anchorNode) - curse.lengthUpTo(this.node.firstChild) + anchorOffset;
if (this.type.isList) {
start += this.pre.length;
}
}
if (this.node.contains(focusNode)) {
end = curse.lengthUpTo(focusNode) - curse.lengthUpTo(this.node.firstChild) + focusOffset;
if (this.type.isList) {
end += this.pre.length;
}
}
return this.source.substring(start, end);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Block;
})();
module.exports = Block;
function esc(text) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(text));
return div.innerHTML;
}
},{"./grammar":6,"./types":15,"./types/constants":7,"miniprism":2}],4:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Curse = _interopRequire(require("../bower_components/curse/dist/curse"));
var _Curse = (function (Curse) {
function _Curse() {
if (Object.getPrototypeOf(_Curse) !== null) {
Object.getPrototypeOf(_Curse).apply(this, arguments);
}
}
_inherits(_Curse, Curse);
_prototypeProperties(_Curse, null, {
nodeLength: {
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = node.previousElementSibling;
if (previousSibling && previousSibling.classList.contains("LineBreak")) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return _Curse;
})(Curse);
module.exports = _Curse;
},{"../bower_components/curse/dist/curse":1}],5:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Block = _interopRequire(require("./block"));
var Curse = _interopRequire(require("./curse"));
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var BACKSPACE = 8;
var RETURN = 13;
var slice = Array.prototype.slice;
var Editor = (function () {
function Editor() {
var source = arguments[0] === undefined ? "" : arguments[0];
this.blocks = [];
this.node = this.createNode();
this.curse = new Curse(this.node, {
nodeLengths: { BR: 0 }
});
this.source = source;
this.bindEvents();
this.observeMutations();
}
_prototypeProperties(Editor, null, {
anchorNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentAnchor);
},
enumerable: true,
configurable: true
},
focusNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentFocus);
},
enumerable: true,
configurable: true
},
blockNodes: {
get: function () {
return this.blocks.map(function (block) {
return block.node;
});
},
enumerable: true,
configurable: true
},
currentAnchor: {
get: function () {
return this.getNode(window.getSelection().anchorNode);
},
enumerable: true,
configurable: true
},
currentBlock: {
get: function () {
return this.getBlockFromNode(this.currentNode);
},
enumerable: true,
configurable: true
},
currentFocus: {
get: function () {
return this.getNode(window.getSelection().focusNode);
},
enumerable: true,
configurable: true
},
currentNode: {
get: function () {
if (!this.isActive) {
return null;
}
if (this.isReversed) {
return this.currentFocus;
} else {
return this.currentAnchor;
}
},
enumerable: true,
configurable: true
},
foldingNodes: {
get: function () {
return slice.call(this.node.querySelectorAll(".md-folding, .md-pre"));
},
enumerable: true,
configurable: true
},
isActive: {
get: function () {
return document.activeElement === this.node;
},
enumerable: true,
configurable: true
},
isReversed: {
get: function () {
var _ref = this;
var currentAnchor = _ref.currentAnchor;
var currentFocus = _ref.currentFocus;
var nodes = _ref.nodes;
return nodes.indexOf(currentAnchor) > nodes.indexOf(currentFocus);
},
enumerable: true,
configurable: true
},
nodes: {
get: function () {
var nodeList = this.node.querySelectorAll(".Block");
return slice.call(nodeList);
},
enumerable: true,
configurable: true
},
toggleFoldingFn: {
get: function () {
if (this._toggleFoldingFn) {
return this._toggleFoldingFn;
}
return this._toggleFoldingFn = this.toggleFolding.bind(this);
},
enumerable: true,
configurable: true
},
source: {
get: function () {
return this.blocks.map(function (block) {
return block.source;
}).join("\n");
},
set: function (source) {
var _this = this;
this.blocks = source.split(/\n/).map(function (line) {
return new Block(_this, { source: line });
});
this.render();
},
enumerable: true,
configurable: true
},
bindEvents: {
value: function bindEvents() {
document.addEventListener("selectionchange", this.toggleFoldingFn);
this.node.addEventListener("input", this.startRenders.bind(this));
this.node.addEventListener("input", this.toggleFoldingFn);
this.node.addEventListener("keydown", this.onReturn.bind(this));
this.node.addEventListener("keydown", this.preventEmpty.bind(this));
this.node.addEventListener("copy", this.onCopy.bind(this));
this.node.addEventListener("cut", this.onCopy.bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement("div");
node.classList.add("Editor");
node.setAttribute("contenteditable", true);
return node;
},
writable: true,
enumerable: true,
configurable: true
},
eachSelectionNode: {
value: function eachSelectionNode(fn) {
var sel = window.getSelection();
var pointTypes = sel.isCollapsed ? ["anchor"] : ["anchor", "focus"];
for (var i = 0, len = pointTypes.length; i < len; i++) {
var pointType = pointTypes[i];
var node = sel["" + pointType + "Node"];
var offset = sel["" + pointType + "Offset"];
fn(node, offset, sel);
}
},
writable: true,
enumerable: true,
configurable: true
},
focusBlock: {
value: function focusBlock(block, hasContent) {
var range = document.createRange();
var sel = window.getSelection();
var pos = hasContent ? 0 : block.node.childNodes.length;
range.setStart(block.node, pos);
range.setEnd(block.node, pos);
sel.removeAllRanges();
sel.addRange(range);
},
writable: true,
enumerable: true,
configurable: true
},
getBlockFromNode: {
value: function getBlockFromNode(node) {
return this.blocks[this.nodes.indexOf(node)];
},
writable: true,
enumerable: true,
configurable: true
},
getNode: {
value: function getNode(node) {
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
while (!node.classList.contains("Block")) {
node = node.parentElement;
}
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBlock: {
value: function insertBlock(block, prevBlock, nextElementSibling) {
var parentNode = this.node;
var prevNode = prevBlock.node;
var prevParent = prevNode.parentElement;
if (prevBlock.shouldContinue) {
parentNode = prevParent;
block.continueFrom(prevBlock);
} else if (prevBlock.type.continues) {
block.reset();
block.content = block.content;
this.splitBlock(prevParent, prevNode);
prevNode.remove();
if (prevParent.childNodes.length === 0) {
nextElementSibling = prevParent.nextElementSibling;
prevParent.remove();
} else {
nextElementSibling = prevParent;
}
}
block.type.insertBefore(block.node, nextElementSibling, parentNode);
},
writable: true,
enumerable: true,
configurable: true
},
observeMutations: {
value: function observeMutations() {
new MutationObserver(this.onMutation.bind(this)).observe(this.node, { childList: true, subtree: true });
},
writable: true,
enumerable: true,
configurable: true
},
onMutation: {
value: function onMutation(mutationRecords) {
for (var i = 0, len = mutationRecords.length; i < len; i++) {
var mut = mutationRecords[i];
for (var _i = 0, _len = mut.removedNodes.length; _i < _len; _i++) {
this.removeNodes(mut.removedNodes);
}
}
},
writable: true,
enumerable: true,
configurable: true
},
onCopy: {
value: function onCopy(e) {
this.copying = true;
var sel = window.getSelection();
var range = sel.getRangeAt(0);
var copyBin = document.createElement("pre");
var text = "";
var anc = this.anchorNodeBlock;
var foc = this.focusNodeBlock;
var nodes = this.nodes;
text += anc.selectionSubstring(sel) + "\n";
var started = undefined;
for (var i = 0, len = nodes.length; i < len; i++) {
if (foc.node === nodes[i]) {
break;
}
if (anc.node === nodes[i]) {
started = true;
continue;
}
if (started) {
text += this.getBlockFromNode(nodes[i]).source + "\n";
}
}
if (anc !== foc) {
text += foc.selectionSubstring(sel);
}
copyBin.classList.add("CopyBin");
copyBin.textContent = text;
this.node.appendChild(copyBin);
var newRange = document.createRange();
newRange.selectNodeContents(copyBin);
sel.removeAllRanges();
sel.addRange(newRange);
setTimeout((function () {
copyBin.remove();
sel.removeAllRanges();
sel.addRange(range);
this.copying = false;
if (e.type === "cut") {
document.execCommand("insertText", null, "");
}
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
onReturn: {
value: function onReturn(e) {
if (e.keyCode !== RETURN) {
return;
}
e.preventDefault();
var _ref2 = this;
var currentAnchor = _ref2.currentAnchor;
var currentFocus = _ref2.currentFocus;
var currentNode = _ref2.currentNode;
var isReversed = _ref2.isReversed;
var startNode = isReversed ? currentFocus : currentAnchor;
var endNode = isReversed ? currentAnchor : currentFocus;
var nextElementSibling = endNode.nextElementSibling;
var range = window.getSelection().getRangeAt(0);
var collapsed = range.collapsed;
var startContainer = range.startContainer;
var endContainer = range.endContainer;
var startOffset = range.startOffset;
var endOffset = range.endOffset;
// In a copy of the range, select the entire end node of the selection
var rangeCopy = range.cloneRange();
rangeCopy.selectNodeContents(endNode);
// In the range copy, select only the text in the current node *after* the
// user's current selection.
if (range.collapsed) {
rangeCopy.setStart(startContainer, startOffset);
} else {
rangeCopy.setStart(endContainer, endOffset);
}
// Set the text after the user's selection to `source` so that it can be
// inserted into the new block being created.
var source = rangeCopy.toString();
var block = undefined;
if (endContainer === this.node || endOffset === 0) {
block = this.getBlockFromNode(endNode).clone();
} else {
block = new Block(this, { source: source });
}
rangeCopy.deleteContents();
// Delete the content selected by the user
range.deleteContents();
if (currentNode.textContent === "") {
currentNode.innerHTML = "<br>";
}
var idx = this.nodes.indexOf(currentNode) + 1;
this.blocks.splice(idx, 0, block);
this.insertBlock(block, this.blocks[idx - 1], nextElementSibling);
this.focusBlock(block, source);
// When not collapsed remove the end node since we're recreating it with its
// remaining contents.
if (!collapsed && startNode !== endNode) {
endNode.remove();
}
// Manually dispatch an `input` event since we called `preventDefault`.
this.node.dispatchEvent(new Event("input"));
},
writable: true,
enumerable: true,
configurable: true
},
toggleFolding: {
value: function toggleFolding() {
if (this.copying) {
return;
}
this.foldingNodes.forEach(function (node) {
return node.classList.remove("visible");
});
if (!this.isActive) {
return;
}
var range = window.getSelection().getRangeAt(0);
this.foldingNodes.forEach(function (node) {
if (range.intersectsNode(node)) {
node.classList.add("visible");
}
});
slice.call(this.currentNode.querySelectorAll(".md-pre")).forEach(function (node) {
return node.classList.add("visible");
});
this.eachSelectionNode((function maybeAddVisible(node, offset) {
var nextSibling = node.nextElementSibling;
if (nextSibling && nextSibling.classList.contains("md-has-folding") && offset === node.textContent.length) {
node = nextSibling;
}
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
if (!node.classList.contains("md-has-folding")) {
var parentEl = undefined;
var testNode = node;
while (parentEl = testNode.parentElement) {
testNode = parentEl;
if (parentEl.classList.contains("md-has-folding")) {
node = parentEl;
}
if (parentEl.classList.contains("Block")) {
break;
}
}
}
if (!node.classList.contains("md-has-folding")) {
return;
}
slice.call(node.querySelectorAll(".md-folding")).forEach(function (node) {
return node.classList.add("visible");
});
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
preventEmpty: {
value: function preventEmpty(e) {
if (!(window.getSelection().isCollapsed && e.keyCode === BACKSPACE)) {
return;
}
var currentNode = this.currentNode;
if (currentNode.textContent === "" && currentNode === this.nodes[0]) {
e.preventDefault();
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNode: {
value: function removeNode(node) {
if (!node.classList.contains("Block")) {
return;
}
var idx = this.blockNodes.indexOf(node);
if (idx !== -1 && !node.isMoving) {
this.blocks.splice(idx, 1);
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNodes: {
value: function removeNodes(nodes) {
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i];
if (node.nodeType !== ELEMENT_NODE || node.isMoving) {
continue;
}
if (node.classList.contains("Block")) {
this.removeNode(nodes[i]);
} else {
var children = node.querySelectorAll(".Block");
for (var _i2 = 0, _len2 = children.length; _i2 < _len2; _i2++) {
this.removeNode(children[_i2]);
}
}
}
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
this.innerHTML = "";
for (var i = 0, len = this.blocks.length; i < len; i++) {
this.blocks[i].appendTo(this.node);
}
},
writable: true,
enumerable: true,
configurable: true
},
splitBlock: {
value: function splitBlock(block, node) {
var blockOne = block.cloneNode();
// Cache, since we're removing some.
var children = slice.call(block.childNodes);
_loop: for (var i = 0, len = children.length; i < len; i++) {
var _ret = (function (i, len) {
var childNode = children[i];
if (childNode !== node) {
childNode.isMoving = true;
blockOne.appendChild(childNode);
setTimeout(function () {
return childNode.isMoving = false;
});
} else {
return "break";
}
})(i, len);
if (_ret === "break") break _loop;
}
if (blockOne.childNodes.length > 0) {
block.parentElement.insertBefore(blockOne, block);
}
return [blockOne, block];
},
writable: true,
enumerable: true,
configurable: true
},
startRenders: {
value: function startRenders() {
this.blocks.forEach(function (block) {
return block.render();
});
},
writable: true,
enumerable: true,
configurable: true
},
teardown: {
value: function teardown() {
document.removeEventListener("selectionchange", this.toggleFoldingFn);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Editor;
})();
module.exports = Editor;
},{"./block":3,"./curse":4}],6:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var types = _interopRequire(require("./types"));
var grammar = { blocks: [] };
for (var i = 1; i <= 6; i++) {
grammar.blocks.push(new types["H" + i]());
}
grammar.blocks.push(new types.OL());
grammar.blocks.push(new types.UL());
grammar.blocks.push(new types.Paragraph());
module.exports = grammar;
},{"./types":15}],7:[function(require,module,exports){
"use strict";
module.exports = {
PRE: -1
};
},{}],8:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H1 = (function (Heading) {
function H1() {
if (Object.getPrototypeOf(H1) !== null) {
Object.getPrototypeOf(H1).apply(this, arguments);
}
}
_inherits(H1, Heading);
_prototypeProperties(H1, null, {
level: {
get: function () {
return 1;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(# )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H1;
})(Heading);
module.exports = H1;
},{"./heading":14}],9:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H2 = (function (Heading) {
function H2() {
if (Object.getPrototypeOf(H2) !== null) {
Object.getPrototypeOf(H2).apply(this, arguments);
}
}
_inherits(H2, Heading);
_prototypeProperties(H2, null, {
level: {
get: function () {
return 2;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{2} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H2;
})(Heading);
module.exports = H2;
},{"./heading":14}],10:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H3 = (function (Heading) {
function H3() {
if (Object.getPrototypeOf(H3) !== null) {
Object.getPrototypeOf(H3).apply(this, arguments);
}
}
_inherits(H3, Heading);
_prototypeProperties(H3, null, {
level: {
get: function () {
return 3;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{3} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H3;
})(Heading);
module.exports = H3;
},{"./heading":14}],11:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H4 = (function (Heading) {
function H4() {
if (Object.getPrototypeOf(H4) !== null) {
Object.getPrototypeOf(H4).apply(this, arguments);
}
}
_inherits(H4, Heading);
_prototypeProperties(H4, null, {
level: {
get: function () {
return 4;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{4} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H4;
})(Heading);
module.exports = H4;
},{"./heading":14}],12:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H5 = (function (Heading) {
function H5() {
if (Object.getPrototypeOf(H5) !== null) {
Object.getPrototypeOf(H5).apply(this, arguments);
}
}
_inherits(H5, Heading);
_prototypeProperties(H5, null, {
level: {
get: function () {
return 5;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{5} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H5;
})(Heading);
module.exports = H5;
},{"./heading":14}],13:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H6 = (function (Heading) {
function H6() {
if (Object.getPrototypeOf(H6) !== null) {
Object.getPrototypeOf(H6).apply(this, arguments);
}
}
_inherits(H6, Heading);
_prototypeProperties(H6, null, {
level: {
get: function () {
return 6;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{6} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H6;
})(Heading);
module.exports = H6;
},{"./heading":14}],14:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./constants").PRE;
var Type = _interopRequire(require("./type"));
var Heading = (function (Type) {
function Heading() {
if (Object.getPrototypeOf(Heading) !== null) {
Object.getPrototypeOf(Heading).apply(this, arguments);
}
}
_inherits(Heading, Type);
_prototypeProperties(Heading, null, {
cssClass: {
get: function () {
return "h" + this.level;
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "H" + this.level;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return new RegExp("^(#{1,6} )(.*)$");
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Heading;
})(Type);
module.exports = Heading;
},{"./constants":7,"./type":20}],15:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var H1 = _interopRequire(require("./h1"));
var H2 = _interopRequire(require("./h2"));
var H3 = _interopRequire(require("./h3"));
var H4 = _interopRequire(require("./h4"));
var H5 = _interopRequire(require("./h5"));
var H6 = _interopRequire(require("./h6"));
var Null = _interopRequire(require("./null"));
var Paragraph = _interopRequire(require("./paragraph"));
var OL = _interopRequire(require("./ol"));
var UL = _interopRequire(require("./ul"));
module.exports = {
H1: H1,
H2: H2,
H3: H3,
H4: H4,
H5: H5,
H6: H6,
Null: Null,
Paragraph: Paragraph,
OL: OL,
UL: UL
};
},{"./h1":8,"./h2":9,"./h3":10,"./h4":11,"./h5":12,"./h6":13,"./null":17,"./ol":18,"./paragraph":19,"./ul":21}],16:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var PRE = require("./constants").PRE;
var List = (function (Type) {
function List() {
if (Object.getPrototypeOf(List) !== null) {
Object.getPrototypeOf(List).apply(this, arguments);
}
}
_inherits(List, Type);
_prototypeProperties(List, null, {
continues: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "li";
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "LI";
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
var listNode = undefined;
if (parent.lastChild && parent.lastChild.nodeName === this.parentNodeName) {
listNode = parent.lastChild;
} else {
listNode = this.createListNode();
}
listNode.appendChild(node);
parent.appendChild(listNode);
},
writable: true,
enumerable: true,
configurable: true
},
createListNode: {
value: function createListNode() {
var ul = document.createElement(this.parentNodeName.toLowerCase());
ul.classList.add("LineBreak");
return ul;
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
var listNode = undefined;
if (oldNode.previousElementSibling && oldNode.previousElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.previousElementSibling;
listNode.appendChild(node);
} else if (oldNode.nextElementSibling && oldNode.nextElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.nextElementSibling;
listNode.insertBefore(node, listNode.firstChild);
} else {
listNode = this.createListNode();
listNode.appendChild(node);
}
listNode.isMoving = true;
oldNode.parentElement.replaceChild(listNode, oldNode);
setTimeout(function () {
return listNode.isMoving = false;
});
},
writable: true,
enumerable: true,
configurable: true
}
});
return List;
})(Type);
module.exports = List;
},{"./constants":7,"./type":20}],17:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Null = (function (Type) {
function Null() {
if (Object.getPrototypeOf(Null) !== null) {
Object.getPrototypeOf(Null).apply(this, arguments);
}
}
_inherits(Null, Type);
_prototypeProperties(Null, null, {
isNull: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Null;
})(Type);
module.exports = Null;
},{"./type":20}],18:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var OL = (function (List) {
function OL() {
if (Object.getPrototypeOf(OL) !== null) {
Object.getPrototypeOf(OL).apply(this, arguments);
}
}
_inherits(OL, List);
_prototypeProperties(OL, null, {
cssClass: {
get: function () {
return "ol-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "OL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(\d+\. )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return OL;
})(List);
module.exports = OL;
},{"./list":16}],19:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Paragraph = (function (Type) {
function Paragraph() {
if (Object.getPrototypeOf(Paragraph) !== null) {
Object.getPrototypeOf(Paragraph).apply(this, arguments);
}
}
_inherits(Paragraph, Type);
_prototypeProperties(Paragraph, null, {
cssClass: {
get: function () {
return "p";
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "P";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(.*)$/;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Paragraph;
})(Type);
module.exports = Paragraph;
},{"./type":20}],20:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Type = (function () {
function Type() {}
_prototypeProperties(Type, null, {
continues: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "";
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isNull: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "DIV";
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
parent.appendChild(node);
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement(this.nodeName.toLowerCase());
node.className = "Block LineBreak";
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBefore: {
value: function insertBefore(node, next, parent) {
parent.insertBefore(node, next);
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
oldNode.parentElement.replaceChild(node, oldNode);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Type;
})();
module.exports = Type;
},{}],21:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var UL = (function (List) {
function UL() {
if (Object.getPrototypeOf(UL) !== null) {
Object.getPrototypeOf(UL).apply(this, arguments);
}
}
_inherits(UL, List);
_prototypeProperties(UL, null, {
cssClass: {
get: function () {
return "ul-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "UL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(- )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return UL;
})(List);
module.exports = UL;
},{"./list":16}]},{},[5])
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
"use strict";
!(function (e) {
if ("object" == typeof exports) module.exports = e();else if ("function" == typeof define && define.amd) define(e);else {
var f;"undefined" != typeof window ? f = window : "undefined" != typeof global ? f = global : "undefined" != typeof self && (f = self), f.Curse = e();
}
})(function () {
var define, module, exports;return (function e(t, n, r) {
var s = function (o, u) {
if (!n[o]) {
if (!t[o]) {
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);throw new Error("Cannot find module '" + o + "'");
}var f = n[o] = { exports: {} };t[o][0].call(f.exports, function (e) {
var n = t[o][1][e];return s(n ? n : e);
}, f, f.exports, e, t, n, r);
}return n[o].exports;
};
var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) s(r[o]);return s;
})({ 1: [function (_dereq_, module, exports) {
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
/**
* Captures and restores the cursor position inside of an HTML element. This
* is particularly useful for capturing, editing, and restoring selections
* in contenteditable elements, where the selection may span both text nodes
* and element nodes.
*
* var elem = document.querySelector('#editor');
* var curse = new Curse(elem);
* curse.capture();
*
* // ...
*
* curse.restore();
*
* @class Curse
* @constructor
* @param {HTMLElement} element an element to track the cursor inside of
*/
var Curse = (function () {
var Curse = function (element) {
var _ref = arguments[1] === undefined ? {} : arguments[1];
var lineBreak = _ref.lineBreak;
var nodeLengths = _ref.nodeLengths;
this.lineBreak = lineBreak;
this.nodeLengths = nodeLengths || {};
this.element = element;
this.reset();
};
_prototypeProperties(Curse, null, {
iterator: {
/**
* An iterator to iterate over the nodes in `this.element`.
*
* This returns a simple node iterator that skips `this.element`, but not its
* children.
*
* @property iterator
* @private
* @type {NodeIterator}
*/
get: function () {
var elem = this.element;
return document.createNodeIterator(this.element, NodeFilter.SHOW_ALL, function onNode(node) {
return node === elem ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
});
},
enumerable: true,
configurable: true
},
capture: {
/**
* Captures the current selection in the element, by storing "start" and
* "end" integer values. This allows for the text and text nodes to change
* inside the element and still have the Curse be able to restore selection
* state.
*
* A `<br>` tag, for example, is counted as a single "character", while
* a text node with the text "Hello, world" is counted as 12 characters.
*
* @method capture
*/
value: function capture() {
var _window$getSelection = window.getSelection();
var anchorNode = _window$getSelection.anchorNode;
var anchorOffset = _window$getSelection.anchorOffset;
var focusNode = _window$getSelection.focusNode;
var focusOffset = _window$getSelection.focusOffset;
var child = undefined,
start = undefined,
end = undefined;
if (anchorNode === null || focusNode === null) {
this.reset();
return;
}
if (anchorNode.nodeName === "#text") {
start = this.lengthUpTo(anchorNode) + anchorOffset;
} else {
child = anchorNode.childNodes[anchorOffset ? anchorOffset - 1 : 0];
start = this.lengthUpTo(child);
}
if (focusNode.nodeName === "#text") {
end = this.lengthUpTo(focusNode) + focusOffset;
} else {
child = focusNode.childNodes[focusOffset ? focusOffset - 1 : 0];
end = this.lengthUpTo(child) + this.nodeLength(child);
}
this.start = start;
this.end = end;
},
writable: true,
enumerable: true,
configurable: true
},
restore: {
/**
* Restore the captured cursor state by iterating over the child nodes in the
* element and counting their length.
*
* @method restore
* @param {Boolean} [onlyActive=true] only restore if the curse's element is
* the active element
*/
value: function restore() {
var onlyActive = arguments[0] === undefined ? true : arguments[0];
if (onlyActive && document.activeElement !== this.element) {
return;
}
if (!onlyActive) {
this.element.focus();
}
var range = document.createRange();
var idx = 0;
var _ref2 = this;
var start = _ref2.start;
var end = _ref2.end;
var iter = this.iterator;
var node = undefined,
setStart = undefined,
setEnd = undefined;
if (this.start > this.end) {
start = this.end;
end = this.start;
}
while (node = iter.nextNode()) {
if (setStart && setEnd) {
break;
}
var nodeLength = this.nodeLength(node);
var isText = node.nodeName === "#text";
var childIdx = undefined;
if (!setStart && start <= idx + nodeLength) {
if (isText) {
range.setStart(node, start - idx);
} else {
childIdx = this.indexOfNode(node);
range.setStart(node.parentNode, childIdx);
}
setStart = true;
}
if (!setEnd && end <= idx + nodeLength) {
if (isText) {
range.setEnd(node, end - idx);
} else {
childIdx = this.indexOfNode(node);
range.setEnd(node.parentNode, childIdx);
}
setEnd = true;
}
idx += nodeLength;
}
var selection = window.getSelection();
selection.removeAllRanges();
// Reverse the selection if it was originally backwards
if (this.start > this.end) {
var startContainer = range.startContainer;
var startOffset = range.startOffset;
range.collapse(false);
selection.addRange(range);
selection.extend(startContainer, startOffset);
} else {
selection.addRange(range);
}
},
writable: true,
enumerable: true,
configurable: true
},
indexOfNode: {
/**
* Get the index of a node in its parent node.
*
* @method indexOfNode
* @private
* @param {Node} child the child node to find the index of
* @returns {Number} the index of the child node
*/
value: function indexOfNode(child) {
var i = 0;
while (child = child.previousSibling) {
i++;
}
return i;
},
writable: true,
enumerable: true,
configurable: true
},
lengthUpTo: {
/**
* Get the number of characters up to a given node.
*
* @method lengthUpTo
* @private
* @param {Node} node a node to find the length up to
* @returns {Number} the length up to the given node
*/
value: function lengthUpTo(lastNode) {
var len = 0;
var iter = this.iterator;
var node = undefined;
while (node = iter.nextNode()) {
if (node === lastNode) {
break;
}
len += this.nodeLength(node);
}
return len;
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
/**
* Reset the state of the cursor.
*
* @method reset
* @private
*/
value: function reset() {
this.start = null;
this.end = null;
},
writable: true,
enumerable: true,
configurable: true
},
nodeLength: {
/**
* Get the "length" of a node. Text nodes are the length of their contents,
* and `<br>` tags, for example, have a length of 1 (a newline character,
* essentially).
*
* @method nodeLength
* @private
* @param {Node} node a Node, typically a Text or HTMLElement node
* @return {Number} the length of the node, as text
*/
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = undefined;
if (this.lineBreak) {
previousSibling = node.previousElementSibling;
}
if (previousSibling && previousSibling.classList.contains(this.lineBreak)) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return Curse;
})();
module.exports = Curse;
}, {}] }, {}, [1])(1);
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],2:[function(require,module,exports){
(function (global){
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.miniprism=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";
/*
* The syntax parsing algorithm in this file is copied heavily from Lea Verou's
* Prism project, which bears this license:
*
* MIT LICENSE
*
* Copyright (c) 2012-2013 Lea Verou
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var grammars = _dereq_("./grammars");
exports.grammars = grammars;
exports.highlight = function highlight(source, grammarName) {
var opts = arguments[2] === undefined ? {} : arguments[2];
var grammar = undefined;
if (typeof grammarName === "string") {
grammar = grammars[grammarName];
}
if (typeof grammarName === "object" && grammarName.constructor === Object) {
grammar = grammarName;
}
if (!grammar) {
throw new Error("Grammar \"" + grammarName + "\" not found.");
}
return stringify(encode(tokenize(source, grammar)), opts.lineClass);
};
function tokenize(source, grammar) {
var strings = [source];
var inlines = grammar.inlines;
if (inlines) {
// jshint -W089
for (var inlineToken in inlines) {
grammar[inlineToken] = inlines[inlineToken];
}
delete grammar.inlines;
}
for (var token in grammar) {
var patterns = grammar[token];
if (!Array.isArray(patterns)) {
patterns = [patterns];
}
for (var i = 0; i < patterns.length; i++) {
var pattern = patterns[i];
var block = pattern.block;
var classes = pattern.classes;
var inside = pattern.inside;
var lookbehind = !!pattern.lookbehind;
var lookbehindLength = 0;
var tag = undefined;
if (pattern.tag) {
tag = pattern.tag;
} else {
tag = block ? "div" : "span";
}
pattern = pattern.pattern || pattern;
for (var _i = 0; _i < strings.length; _i++) {
var string = strings[_i];
if (typeof string !== "string") {
continue;
}
pattern.lastIndex = 0;
var match = pattern.exec(string);
if (!match) {
continue;
}
if (lookbehind) {
lookbehindLength = match[1].length;
}
var from = match.index - 1 + lookbehindLength;
match = match[0].slice(lookbehindLength);
var len = match.length;
var to = from + len;
var before = string.slice(0, from + 1);
var after = string.slice(to + 1);
var args = [_i, 1];
if (before) {
args.push(before);
}
var wrapped = {
block: block,
classes: classes,
tag: tag,
text: inside ? tokenize(match, inside) : match,
token: token
};
args.push(wrapped);
if (after) {
args.push(after);
}
Array.prototype.splice.apply(strings, args);
}
}
}
return strings;
}
function stringify(source) {
var lineClass = arguments[1] === undefined ? "md-line" : arguments[1];
if (source === "\n") {
return "<br>";
}
if (typeof source === "string") {
return source.replace(/\n/g, "");
}
if (Array.isArray(source)) {
return source.reduce(function addItem(result, item) {
return result + stringify(item, lineClass);
}, "");
}
var tag = source.tag;
var classList = source.classes || source.token.split(" ");
var className = classList.map(function (token) {
return "md-" + token;
}).join(" ");
if (source.block) {
className += " " + lineClass;
}
return ["<" + tag + " class=\"" + className + "\">", stringify(source.text, lineClass), "</" + tag + ">"].join("");
}
function encode(src) {
if (Array.isArray(src)) {
return src.map(encode);
} else if (typeof src === "object") {
src.text = encode(src.text);
return src;
} else {
return escapeHTML(src);
}
}
function escapeHTML(str) {
return str.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/\//g, "&#x2F;");
}
},{"./grammars":2}],2:[function(_dereq_,module,exports){
"use strict";
exports.markdown = _dereq_("./markdown");
},{"./markdown":3}],3:[function(_dereq_,module,exports){
"use strict";
/*
* These regexes are in some places copies of, in others modifications of, and
* in some places wholly unrelated to the Markdown regexes found in the
* Stackedit project, which bears this license:
*
* StackEdit - The Markdown editor powered by PageDown.
* Copyright 2013 Benoit Schweblin (http://www.benoitschweblin.com)
* Licensed under an Apache License (http://www.apache.org/licenses/LICENSE-2.0)
*/
exports.gfm = {
block: true,
pattern: /^`{3}.*\n(?:[\s\S]*?)\n`{3} *(?:\n|$)/gm,
inside: {
"gfm-limit": {
block: true,
pattern: /^`{3}.*(?:\n|$)/gm,
inside: {
"gfm-info": {
lookbehind: true,
pattern: /^(`{3}).+(?:\n|$)/
},
"gfm-fence": /^`{3}(?:\n|$)/gm
}
},
"gfm-line": {
block: true,
pattern: /^.*(?:\n|$)/gm
} }
};
exports.blank = [{
block: true,
pattern: /\n(?![\s\S])/mg
}, {
block: true,
pattern: /^\n/mg
}];
exports["setex-h1"] = {
block: true,
pattern: /^.+\n=+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^=].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^=+[ \t]*(?:\n|$)/
}
}
};
exports["setex-h2"] = {
block: true,
pattern: /^(?!^- ).+\n-+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^-].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^-+[ \t]*(?:\n|$)/
}
}
};
exports.code = {
block: true,
pattern: /^(?: {4,}|\t).+(?:\n|$)/gm
};
// h1 through h6
for (var i = 1; i < 7; i++) {
exports["h" + i] = {
classes: ["h" + i, "has-folding"],
block: true,
pattern: new RegExp("^#{" + i + "} .*(?:\n|$)", "gm"),
inside: {
"hash folding": new RegExp("^#{" + i + "} ")
}
};
}
exports.ul = {
classes: ["ul", "has-folding"],
block: true,
pattern: /^[ \t]*(?:[*+\-])[ \t].*(?:\n|$)/gm,
inside: {
"ul-marker folding": /^[ \t]*(?:[*+\-])[ \t]/
}
};
exports.ol = {
block: true,
pattern: /^[ \t]*(?:\d+)\.[ \t].*(?:\n|$)/gm,
inside: {
"ol-marker": /^[ \t]*(?:\d+)\.[ \t]/
}
};
exports.blockquote = {
block: true,
pattern: /^ {0,3}> *.*(?:\n|$)/gm,
inside: {
"blockquote-marker": /^ {0,3}> */
}
};
exports.hr = {
block: true,
pattern: /^(?:[*\-_] *){3,}(?:\n|$)/gm
};
exports["link-def"] = {
block: true,
pattern: /^ {0,3}\[.*?\]:[ \t]+.+(?:\n|$)/gm,
inside: {
"link-def-name": {
pattern: /^ {0,3}\[.*?\]:/,
inside: {
"bracket-start": /^\[/,
"bracket-end": /\](?=:$)/,
colon: /:$/
}
},
"link-def-value": /.*(?:\n|$)/
}
};
exports.p = {
block: true,
pattern: /^.+(?:\n|$)/gm,
inside: {}
};
// jshint -W101
exports.link = {
classes: ["link", "has-folding"],
pattern: /\[(?:(?:\\.)|[^\[\]])*\]\([^\(\)\s]+(?:\(\S*?\))??[^\(\)\s]*?(?:\s(?:['‘][^'’]*['’]|["“][^"”]*["”]))?\)/gm,
inside: {
"bracket-start folding": {
pattern: /(^|[^\\])\[/,
lookbehind: true
},
ref: /(?:(?:\\.)|[^\[\]])+(?=\])/,
"bracket-end folding": /\](?=\s?\()/,
"paren-start folding": /^\(/,
"paren-end folding": /\)$/,
"href folding": /.*/
}
};
// jshint +W101
exports["link-ref"] = {
classes: ["link-ref", "has-folding"],
pattern: /\[(?:.*?)\] ?\[(?:.*?)\]/g,
inside: {
"ref-value folding": {
pattern: /\[[^\[\]]+\]$/,
inside: {
"bracket-start": /\[/,
"ref-href": /[^\[\]]+(?=]$)/,
"bracket-end": /\]/
}
},
"ref-text": {
pattern: /^\[[^\[\]]+\]/,
inside: {
"bracket-start folding": /^\[/,
ref: /^[^\[\]]+/,
"bracket-end folding": /\]$/
}
}
}
};
exports.em = {
classes: ["em", "has-folding"],
pattern: /(^|[^\\])(\*|_)(\S[^\2]*?)??[^\s\\]+?\2/g,
lookbehind: true,
inside: {
"em-marker folding": /(?:^(?:\*|_))|(?:(?:\*|_)$)/
}
};
exports.strong = {
classes: ["strong", "has-folding"],
pattern: /([_\*]){2}(?:(?!\1{2}).)*\1{2}/g,
inside: {
"strong-marker folding": /(?:^(?:\*|_){2})|(?:(?:\*|_){2}$)/
}
};
exports["inline-code"] = {
classes: ["inline-code", "has-folding"],
pattern: /(^|[^\\])`(\S[^`]*?)??[^\s\\]+?`/g,
lookbehind: true,
inside: {
"inline-code-marker folding": /(?:^(?:`))|(?:(?:`)$)/
}
};
var inlines = {
strong: exports.strong,
em: exports.em,
link: exports.link,
"inline-code": exports["inline-code"],
"link-ref": exports["link-ref"]
};
["setex-h1", "setex-h2", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "blockquote", "p"].forEach(function (token) {
exports[token].inside.inlines = inlines;
});
["em", "strong"].forEach(function (token) {
exports[token].inside = exports[token].inside || {};
exports[token].inside.inlines = {
link: exports.link,
"link-ref": exports["link-ref"]
};
});
},{}]},{},[1])
(1)
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./types/constants").PRE;
var blocks = require("./grammar").blocks;
var Null = require("./types").Null;
var OL = require("./types").OL;
var miniprism = _interopRequire(require("miniprism"));
// Standard inlines:
var inlines = miniprism.grammars.markdown.p.inside.inlines;
var slice = Array.prototype.slice;
var Block = (function () {
function Block(editor, _ref) {
var node = _ref.node;
var pre = _ref.pre;
var source = _ref.source;
var type = _ref.type;
this.editor = editor;
this.type = type || new Null();
this.pre = pre || "";
this.content = source;
this.node = node || this.type.createNode();
this.render(true); // (isFirstRender)
}
_prototypeProperties(Block, null, {
source: {
get: function () {
if (this.type.constructor === OL) {
var children = this.node.parentElement ? slice.call(this.node.parentElement.childNodes) : [];
var digit = children.indexOf(this.node) + 1;
return "" + digit + ". " + this._content;
} else {
return this.pre + this._content;
}
},
enumerable: true,
configurable: true
},
content: {
get: function () {
if (this.type.isHeading) {
return "" + this.pre + "" + this._content;
} else {
return this._content;
}
},
set: function (content) {
this._content = content;
var match = undefined,
type = undefined;
if (this.type.isHeading && !content) {
this.type = new Null();
this.pre = "";
}
if (!this.type.shouldReparse) {
return;
}
// jshint -W089
for (var i = 0, len = blocks.length; i < len; i++) {
type = blocks[i];
if (match = content.match(type.pattern)) {
break;
}
}
this.type = type;
this._content = "";
match = match.slice(1);
var labels = type.labels;
for (var i = 0, len = match.length; i < len; i++) {
if (labels[i] === PRE) {
this.pre = match[i];
} else {
this._content += match[i];
}
}
},
enumerable: true,
configurable: true
},
html: {
get: function () {
if (this.type.isHeading) {
return "<span class=\"md-pre\">" + esc(this.pre) + "</span>" + ("" + miniprism.highlight(this._content, inlines));
} else {
return miniprism.highlight(this._content, inlines);
}
},
enumerable: true,
configurable: true
},
shouldContinue: {
get: function () {
return this.type.continues && this.content;
},
enumerable: true,
configurable: true
},
type: {
get: function () {
return this._type;
},
set: function (type) {
this.adjustedPre = false;
this.pre = "";
return this._type = type;
},
enumerable: true,
configurable: true
},
appendTo: {
value: function appendTo(node) {
this.type.appendChild(this.node, node);
},
writable: true,
enumerable: true,
configurable: true
},
clone: {
value: function clone() {
return new this.constructor(this.editor, {
node: this.node.cloneNode(true),
pre: this.pre,
source: this.content,
type: this.type
});
},
writable: true,
enumerable: true,
configurable: true
},
continueFrom: {
value: function continueFrom(block) {
this.type = block.type;
this.pre = block.pre;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
var isFirstRender = arguments[0] === undefined ? false : arguments[0];
if (this.content === this.node.textContent && !isFirstRender) {
return;
}
var oldNode = this.node;
var oldType = this.type;
if (!isFirstRender) {
this.content = this.node.textContent;
}
this.editor.curse.capture();
if (oldType !== this.type) {
this.node = this.type.createNode();
this.type.replaceNode(this.node, oldNode);
}
/*
* Adjust the Curse for `pre` since it is about to be removed from the
* DOM during `#render`. This does not apply to reparsing types, as their
* `pre` is still displayed when focused.
*/
if (!this.adjustedPre && !this.type.shouldReparse) {
this.editor.curse.start -= this.pre.length;
this.editor.curse.end -= this.pre.length;
this.adjustedPre = true;
}
if (this.content) {
this.node.innerHTML = this.html;
} else {
this.node.innerHTML = "<br>";
}
this.editor.curse.restore();
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
value: function reset() {
this.type = new Null();
this.content = this.content;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
selectionSubstring: {
value: function selectionSubstring(sel) {
var anchorNode = sel.anchorNode;
var focusNode = sel.focusNode;
var anchorOffset = sel.anchorOffset;
var focusOffset = sel.focusOffset;
var start = 0;
var end = Infinity;
var curse = this.editor.curse;
if (this.node.contains(anchorNode)) {
start = curse.lengthUpTo(anchorNode) - curse.lengthUpTo(this.node.firstChild) + anchorOffset;
if (this.type.isList) {
start += this.pre.length;
}
}
if (this.node.contains(focusNode)) {
end = curse.lengthUpTo(focusNode) - curse.lengthUpTo(this.node.firstChild) + focusOffset;
if (this.type.isList) {
end += this.pre.length;
}
}
return this.source.substring(start, end);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Block;
})();
module.exports = Block;
function esc(text) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(text));
return div.innerHTML;
}
},{"./grammar":6,"./types":15,"./types/constants":7,"miniprism":2}],4:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Curse = _interopRequire(require("../bower_components/curse/dist/curse"));
var _Curse = (function (Curse) {
function _Curse() {
if (Object.getPrototypeOf(_Curse) !== null) {
Object.getPrototypeOf(_Curse).apply(this, arguments);
}
}
_inherits(_Curse, Curse);
_prototypeProperties(_Curse, null, {
nodeLength: {
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = node.previousElementSibling;
if (previousSibling && previousSibling.classList.contains("LineBreak")) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return _Curse;
})(Curse);
module.exports = _Curse;
},{"../bower_components/curse/dist/curse":1}],5:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Block = _interopRequire(require("./block"));
var Curse = _interopRequire(require("./curse"));
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var BACKSPACE = 8;
var RETURN = 13;
var slice = Array.prototype.slice;
var Editor = (function () {
function Editor() {
var source = arguments[0] === undefined ? "" : arguments[0];
this.blocks = [];
this.node = this.createNode();
this.curse = new Curse(this.node, {
nodeLengths: { BR: 0 }
});
this.source = source;
this.bindEvents();
this.observeMutations();
}
_prototypeProperties(Editor, null, {
anchorNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentAnchor);
},
enumerable: true,
configurable: true
},
focusNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentFocus);
},
enumerable: true,
configurable: true
},
blockNodes: {
get: function () {
return this.blocks.map(function (block) {
return block.node;
});
},
enumerable: true,
configurable: true
},
currentAnchor: {
get: function () {
return this.getNode(window.getSelection().anchorNode);
},
enumerable: true,
configurable: true
},
currentBlock: {
get: function () {
return this.getBlockFromNode(this.currentNode);
},
enumerable: true,
configurable: true
},
currentFocus: {
get: function () {
return this.getNode(window.getSelection().focusNode);
},
enumerable: true,
configurable: true
},
currentNode: {
get: function () {
if (!this.isActive) {
return null;
}
if (this.isReversed) {
return this.currentFocus;
} else {
return this.currentAnchor;
}
},
enumerable: true,
configurable: true
},
foldingNodes: {
get: function () {
return slice.call(this.node.querySelectorAll(".md-folding, .md-pre"));
},
enumerable: true,
configurable: true
},
isActive: {
get: function () {
return document.activeElement === this.node;
},
enumerable: true,
configurable: true
},
isReversed: {
get: function () {
var _ref = this;
var currentAnchor = _ref.currentAnchor;
var currentFocus = _ref.currentFocus;
var nodes = _ref.nodes;
return nodes.indexOf(currentAnchor) > nodes.indexOf(currentFocus);
},
enumerable: true,
configurable: true
},
nodes: {
get: function () {
var nodeList = this.node.querySelectorAll(".Block");
return slice.call(nodeList);
},
enumerable: true,
configurable: true
},
toggleFoldingFn: {
get: function () {
if (this._toggleFoldingFn) {
return this._toggleFoldingFn;
}
return this._toggleFoldingFn = this.toggleFolding.bind(this);
},
enumerable: true,
configurable: true
},
source: {
get: function () {
return this.blocks.map(function (block) {
return block.source;
}).join("\n");
},
set: function (source) {
var _this = this;
this.blocks = source.split(/\n/).map(function (line) {
return new Block(_this, { source: line });
});
this.render();
},
enumerable: true,
configurable: true
},
bindEvents: {
value: function bindEvents() {
document.addEventListener("selectionchange", this.toggleFoldingFn);
this.node.addEventListener("input", this.startRenders.bind(this));
this.node.addEventListener("input", this.toggleFoldingFn);
this.node.addEventListener("keydown", this.onReturn.bind(this));
this.node.addEventListener("keydown", this.preventEmpty.bind(this));
this.node.addEventListener("copy", this.onCopy.bind(this));
this.node.addEventListener("cut", this.onCopy.bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement("div");
node.classList.add("Editor");
node.setAttribute("contenteditable", true);
return node;
},
writable: true,
enumerable: true,
configurable: true
},
eachSelectionNode: {
value: function eachSelectionNode(fn) {
var sel = window.getSelection();
var pointTypes = sel.isCollapsed ? ["anchor"] : ["anchor", "focus"];
for (var i = 0, len = pointTypes.length; i < len; i++) {
var pointType = pointTypes[i];
var node = sel["" + pointType + "Node"];
var offset = sel["" + pointType + "Offset"];
fn(node, offset, sel);
}
},
writable: true,
enumerable: true,
configurable: true
},
focusBlock: {
value: function focusBlock(block, hasContent) {
var range = document.createRange();
var sel = window.getSelection();
var pos = hasContent ? 0 : block.node.childNodes.length;
range.setStart(block.node, pos);
range.setEnd(block.node, pos);
sel.removeAllRanges();
sel.addRange(range);
},
writable: true,
enumerable: true,
configurable: true
},
getBlockFromNode: {
value: function getBlockFromNode(node) {
return this.blocks[this.nodes.indexOf(node)];
},
writable: true,
enumerable: true,
configurable: true
},
getNode: {
value: function getNode(node) {
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
while (!node.classList.contains("Block")) {
node = node.parentElement;
}
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBlock: {
value: function insertBlock(block, prevBlock, nextElementSibling) {
var parentNode = this.node;
var prevNode = prevBlock.node;
var prevParent = prevNode.parentElement;
if (prevBlock.shouldContinue) {
parentNode = prevParent;
block.continueFrom(prevBlock);
} else if (prevBlock.type.continues) {
block.reset();
block.content = block.content;
this.splitBlock(prevParent, prevNode);
prevNode.remove();
if (prevParent.childNodes.length === 0) {
nextElementSibling = prevParent.nextElementSibling;
prevParent.remove();
} else {
nextElementSibling = prevParent;
}
}
block.type.insertBefore(block.node, nextElementSibling, parentNode);
},
writable: true,
enumerable: true,
configurable: true
},
observeMutations: {
value: function observeMutations() {
new MutationObserver(this.onMutation.bind(this)).observe(this.node, { childList: true, subtree: true });
},
writable: true,
enumerable: true,
configurable: true
},
onMutation: {
value: function onMutation(mutationRecords) {
for (var i = 0, len = mutationRecords.length; i < len; i++) {
var mut = mutationRecords[i];
for (var _i = 0, _len = mut.removedNodes.length; _i < _len; _i++) {
this.removeNodes(mut.removedNodes);
}
}
},
writable: true,
enumerable: true,
configurable: true
},
onCopy: {
value: function onCopy(e) {
this.copying = true;
var sel = window.getSelection();
var range = sel.getRangeAt(0);
var copyBin = document.createElement("pre");
var text = "";
var anc = this.anchorNodeBlock;
var foc = this.focusNodeBlock;
var nodes = this.nodes;
text += anc.selectionSubstring(sel) + "\n";
var started = undefined;
for (var i = 0, len = nodes.length; i < len; i++) {
if (foc.node === nodes[i]) {
break;
}
if (anc.node === nodes[i]) {
started = true;
continue;
}
if (started) {
text += this.getBlockFromNode(nodes[i]).source + "\n";
}
}
if (anc !== foc) {
text += foc.selectionSubstring(sel);
}
copyBin.classList.add("CopyBin");
copyBin.textContent = text;
this.node.appendChild(copyBin);
var newRange = document.createRange();
newRange.selectNodeContents(copyBin);
sel.removeAllRanges();
sel.addRange(newRange);
setTimeout((function () {
copyBin.remove();
sel.removeAllRanges();
sel.addRange(range);
this.copying = false;
if (e.type === "cut") {
document.execCommand("insertText", null, "");
}
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
onReturn: {
value: function onReturn(e) {
if (e.keyCode !== RETURN) {
return;
}
e.preventDefault();
var _ref2 = this;
var currentAnchor = _ref2.currentAnchor;
var currentFocus = _ref2.currentFocus;
var currentNode = _ref2.currentNode;
var isReversed = _ref2.isReversed;
var startNode = isReversed ? currentFocus : currentAnchor;
var endNode = isReversed ? currentAnchor : currentFocus;
var nextElementSibling = endNode.nextElementSibling;
var range = window.getSelection().getRangeAt(0);
var collapsed = range.collapsed;
var startContainer = range.startContainer;
var endContainer = range.endContainer;
var startOffset = range.startOffset;
var endOffset = range.endOffset;
// In a copy of the range, select the entire end node of the selection
var rangeCopy = range.cloneRange();
rangeCopy.selectNodeContents(endNode);
// In the range copy, select only the text in the current node *after* the
// user's current selection.
if (range.collapsed) {
rangeCopy.setStart(startContainer, startOffset);
} else {
rangeCopy.setStart(endContainer, endOffset);
}
// Set the text after the user's selection to `source` so that it can be
// inserted into the new block being created.
var source = rangeCopy.toString();
var block = undefined;
if (endContainer === this.node || endOffset === 0) {
block = this.getBlockFromNode(endNode).clone();
} else {
block = new Block(this, { source: source });
}
rangeCopy.deleteContents();
// Delete the content selected by the user
range.deleteContents();
if (currentNode.textContent === "") {
currentNode.innerHTML = "<br>";
}
var idx = this.nodes.indexOf(currentNode) + 1;
this.blocks.splice(idx, 0, block);
this.insertBlock(block, this.blocks[idx - 1], nextElementSibling);
this.focusBlock(block, source);
// When not collapsed remove the end node since we're recreating it with its
// remaining contents.
if (!collapsed && startNode !== endNode) {
endNode.remove();
}
// Manually dispatch an `input` event since we called `preventDefault`.
this.node.dispatchEvent(new Event("input"));
},
writable: true,
enumerable: true,
configurable: true
},
toggleFolding: {
value: function toggleFolding() {
if (this.copying) {
return;
}
this.foldingNodes.forEach(function (node) {
return node.classList.remove("visible");
});
if (!this.isActive) {
return;
}
var range = window.getSelection().getRangeAt(0);
this.foldingNodes.forEach(function (node) {
if (range.intersectsNode(node)) {
node.classList.add("visible");
}
});
slice.call(this.currentNode.querySelectorAll(".md-pre")).forEach(function (node) {
return node.classList.add("visible");
});
this.eachSelectionNode((function maybeAddVisible(node, offset) {
var nextSibling = node.nextElementSibling;
if (nextSibling && nextSibling.classList.contains("md-has-folding") && offset === node.textContent.length) {
node = nextSibling;
}
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
if (!node.classList.contains("md-has-folding")) {
var parentEl = undefined;
var testNode = node;
while (parentEl = testNode.parentElement) {
testNode = parentEl;
if (parentEl.classList.contains("md-has-folding")) {
node = parentEl;
}
if (parentEl.classList.contains("Block")) {
break;
}
}
}
if (!node.classList.contains("md-has-folding")) {
return;
}
slice.call(node.querySelectorAll(".md-folding")).forEach(function (node) {
return node.classList.add("visible");
});
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
preventEmpty: {
value: function preventEmpty(e) {
if (!(window.getSelection().isCollapsed && e.keyCode === BACKSPACE)) {
return;
}
var currentNode = this.currentNode;
if (currentNode.textContent === "" && currentNode === this.nodes[0]) {
e.preventDefault();
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNode: {
value: function removeNode(node) {
if (!node.classList.contains("Block")) {
return;
}
var idx = this.blockNodes.indexOf(node);
if (idx !== -1 && !node.isMoving) {
this.blocks.splice(idx, 1);
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNodes: {
value: function removeNodes(nodes) {
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i];
if (node.nodeType !== ELEMENT_NODE || node.isMoving) {
continue;
}
if (node.classList.contains("Block")) {
this.removeNode(nodes[i]);
} else {
var children = node.querySelectorAll(".Block");
for (var _i2 = 0, _len2 = children.length; _i2 < _len2; _i2++) {
this.removeNode(children[_i2]);
}
}
}
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
this.innerHTML = "";
for (var i = 0, len = this.blocks.length; i < len; i++) {
this.blocks[i].appendTo(this.node);
}
},
writable: true,
enumerable: true,
configurable: true
},
splitBlock: {
value: function splitBlock(block, node) {
var blockOne = block.cloneNode();
// Cache, since we're removing some.
var children = slice.call(block.childNodes);
_loop: for (var i = 0, len = children.length; i < len; i++) {
var _ret = (function (i, len) {
var childNode = children[i];
if (childNode !== node) {
childNode.isMoving = true;
blockOne.appendChild(childNode);
setTimeout(function () {
return childNode.isMoving = false;
});
} else {
return "break";
}
})(i, len);
if (_ret === "break") break _loop;
}
if (blockOne.childNodes.length > 0) {
block.parentElement.insertBefore(blockOne, block);
}
return [blockOne, block];
},
writable: true,
enumerable: true,
configurable: true
},
startRenders: {
value: function startRenders() {
this.blocks.forEach(function (block) {
return block.render();
});
},
writable: true,
enumerable: true,
configurable: true
},
teardown: {
value: function teardown() {
document.removeEventListener("selectionchange", this.toggleFoldingFn);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Editor;
})();
module.exports = Editor;
},{"./block":3,"./curse":4}],6:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var types = _interopRequire(require("./types"));
var grammar = { blocks: [] };
for (var i = 1; i <= 6; i++) {
grammar.blocks.push(new types["H" + i]());
}
grammar.blocks.push(new types.OL());
grammar.blocks.push(new types.UL());
grammar.blocks.push(new types.Paragraph());
module.exports = grammar;
},{"./types":15}],7:[function(require,module,exports){
"use strict";
module.exports = {
PRE: -1
};
},{}],8:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H1 = (function (Heading) {
function H1() {
if (Object.getPrototypeOf(H1) !== null) {
Object.getPrototypeOf(H1).apply(this, arguments);
}
}
_inherits(H1, Heading);
_prototypeProperties(H1, null, {
level: {
get: function () {
return 1;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(# )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H1;
})(Heading);
module.exports = H1;
},{"./heading":14}],9:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H2 = (function (Heading) {
function H2() {
if (Object.getPrototypeOf(H2) !== null) {
Object.getPrototypeOf(H2).apply(this, arguments);
}
}
_inherits(H2, Heading);
_prototypeProperties(H2, null, {
level: {
get: function () {
return 2;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{2} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H2;
})(Heading);
module.exports = H2;
},{"./heading":14}],10:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H3 = (function (Heading) {
function H3() {
if (Object.getPrototypeOf(H3) !== null) {
Object.getPrototypeOf(H3).apply(this, arguments);
}
}
_inherits(H3, Heading);
_prototypeProperties(H3, null, {
level: {
get: function () {
return 3;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{3} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H3;
})(Heading);
module.exports = H3;
},{"./heading":14}],11:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H4 = (function (Heading) {
function H4() {
if (Object.getPrototypeOf(H4) !== null) {
Object.getPrototypeOf(H4).apply(this, arguments);
}
}
_inherits(H4, Heading);
_prototypeProperties(H4, null, {
level: {
get: function () {
return 4;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{4} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H4;
})(Heading);
module.exports = H4;
},{"./heading":14}],12:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H5 = (function (Heading) {
function H5() {
if (Object.getPrototypeOf(H5) !== null) {
Object.getPrototypeOf(H5).apply(this, arguments);
}
}
_inherits(H5, Heading);
_prototypeProperties(H5, null, {
level: {
get: function () {
return 5;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{5} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H5;
})(Heading);
module.exports = H5;
},{"./heading":14}],13:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H6 = (function (Heading) {
function H6() {
if (Object.getPrototypeOf(H6) !== null) {
Object.getPrototypeOf(H6).apply(this, arguments);
}
}
_inherits(H6, Heading);
_prototypeProperties(H6, null, {
level: {
get: function () {
return 6;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{6} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H6;
})(Heading);
module.exports = H6;
},{"./heading":14}],14:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./constants").PRE;
var Type = _interopRequire(require("./type"));
var Heading = (function (Type) {
function Heading() {
if (Object.getPrototypeOf(Heading) !== null) {
Object.getPrototypeOf(Heading).apply(this, arguments);
}
}
_inherits(Heading, Type);
_prototypeProperties(Heading, null, {
cssClass: {
get: function () {
return "h" + this.level;
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "H" + this.level;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return new RegExp("^(#{1,6} )(.*)$");
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Heading;
})(Type);
module.exports = Heading;
},{"./constants":7,"./type":20}],15:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var H1 = _interopRequire(require("./h1"));
var H2 = _interopRequire(require("./h2"));
var H3 = _interopRequire(require("./h3"));
var H4 = _interopRequire(require("./h4"));
var H5 = _interopRequire(require("./h5"));
var H6 = _interopRequire(require("./h6"));
var Null = _interopRequire(require("./null"));
var Paragraph = _interopRequire(require("./paragraph"));
var OL = _interopRequire(require("./ol"));
var UL = _interopRequire(require("./ul"));
module.exports = {
H1: H1,
H2: H2,
H3: H3,
H4: H4,
H5: H5,
H6: H6,
Null: Null,
Paragraph: Paragraph,
OL: OL,
UL: UL
};
},{"./h1":8,"./h2":9,"./h3":10,"./h4":11,"./h5":12,"./h6":13,"./null":17,"./ol":18,"./paragraph":19,"./ul":21}],16:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var PRE = require("./constants").PRE;
var List = (function (Type) {
function List() {
if (Object.getPrototypeOf(List) !== null) {
Object.getPrototypeOf(List).apply(this, arguments);
}
}
_inherits(List, Type);
_prototypeProperties(List, null, {
continues: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "li";
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "LI";
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
var listNode = undefined;
if (parent.lastChild && parent.lastChild.nodeName === this.parentNodeName) {
listNode = parent.lastChild;
} else {
listNode = this.createListNode();
}
listNode.appendChild(node);
parent.appendChild(listNode);
},
writable: true,
enumerable: true,
configurable: true
},
createListNode: {
value: function createListNode() {
var ul = document.createElement(this.parentNodeName.toLowerCase());
ul.classList.add("LineBreak");
return ul;
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
var listNode = undefined;
if (oldNode.previousElementSibling && oldNode.previousElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.previousElementSibling;
listNode.appendChild(node);
} else if (oldNode.nextElementSibling && oldNode.nextElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.nextElementSibling;
listNode.insertBefore(node, listNode.firstChild);
} else {
listNode = this.createListNode();
listNode.appendChild(node);
}
listNode.isMoving = true;
oldNode.parentElement.replaceChild(listNode, oldNode);
setTimeout(function () {
return listNode.isMoving = false;
});
},
writable: true,
enumerable: true,
configurable: true
}
});
return List;
})(Type);
module.exports = List;
},{"./constants":7,"./type":20}],17:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Null = (function (Type) {
function Null() {
if (Object.getPrototypeOf(Null) !== null) {
Object.getPrototypeOf(Null).apply(this, arguments);
}
}
_inherits(Null, Type);
_prototypeProperties(Null, null, {
isNull: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Null;
})(Type);
module.exports = Null;
},{"./type":20}],18:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var OL = (function (List) {
function OL() {
if (Object.getPrototypeOf(OL) !== null) {
Object.getPrototypeOf(OL).apply(this, arguments);
}
}
_inherits(OL, List);
_prototypeProperties(OL, null, {
cssClass: {
get: function () {
return "ol-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "OL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(\d+\. )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return OL;
})(List);
module.exports = OL;
},{"./list":16}],19:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Paragraph = (function (Type) {
function Paragraph() {
if (Object.getPrototypeOf(Paragraph) !== null) {
Object.getPrototypeOf(Paragraph).apply(this, arguments);
}
}
_inherits(Paragraph, Type);
_prototypeProperties(Paragraph, null, {
cssClass: {
get: function () {
return "p";
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "P";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(.*)$/;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Paragraph;
})(Type);
module.exports = Paragraph;
},{"./type":20}],20:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Type = (function () {
function Type() {}
_prototypeProperties(Type, null, {
continues: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "";
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isNull: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "DIV";
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
parent.appendChild(node);
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement(this.nodeName.toLowerCase());
node.className = "Block LineBreak";
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBefore: {
value: function insertBefore(node, next, parent) {
parent.insertBefore(node, next);
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
oldNode.parentElement.replaceChild(node, oldNode);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Type;
})();
module.exports = Type;
},{}],21:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var UL = (function (List) {
function UL() {
if (Object.getPrototypeOf(UL) !== null) {
Object.getPrototypeOf(UL).apply(this, arguments);
}
}
_inherits(UL, List);
_prototypeProperties(UL, null, {
cssClass: {
get: function () {
return "ul-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "UL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(- )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return UL;
})(List);
module.exports = UL;
},{"./list":16}]},{},[5])
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
"use strict";
!(function (e) {
if ("object" == typeof exports) module.exports = e();else if ("function" == typeof define && define.amd) define(e);else {
var f;"undefined" != typeof window ? f = window : "undefined" != typeof global ? f = global : "undefined" != typeof self && (f = self), f.Curse = e();
}
})(function () {
var define, module, exports;return (function e(t, n, r) {
var s = function (o, u) {
if (!n[o]) {
if (!t[o]) {
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);throw new Error("Cannot find module '" + o + "'");
}var f = n[o] = { exports: {} };t[o][0].call(f.exports, function (e) {
var n = t[o][1][e];return s(n ? n : e);
}, f, f.exports, e, t, n, r);
}return n[o].exports;
};
var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) s(r[o]);return s;
})({ 1: [function (_dereq_, module, exports) {
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
/**
* Captures and restores the cursor position inside of an HTML element. This
* is particularly useful for capturing, editing, and restoring selections
* in contenteditable elements, where the selection may span both text nodes
* and element nodes.
*
* var elem = document.querySelector('#editor');
* var curse = new Curse(elem);
* curse.capture();
*
* // ...
*
* curse.restore();
*
* @class Curse
* @constructor
* @param {HTMLElement} element an element to track the cursor inside of
*/
var Curse = (function () {
var Curse = function (element) {
var _ref = arguments[1] === undefined ? {} : arguments[1];
var lineBreak = _ref.lineBreak;
var nodeLengths = _ref.nodeLengths;
this.lineBreak = lineBreak;
this.nodeLengths = nodeLengths || {};
this.element = element;
this.reset();
};
_prototypeProperties(Curse, null, {
iterator: {
/**
* An iterator to iterate over the nodes in `this.element`.
*
* This returns a simple node iterator that skips `this.element`, but not its
* children.
*
* @property iterator
* @private
* @type {NodeIterator}
*/
get: function () {
var elem = this.element;
return document.createNodeIterator(this.element, NodeFilter.SHOW_ALL, function onNode(node) {
return node === elem ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
});
},
enumerable: true,
configurable: true
},
capture: {
/**
* Captures the current selection in the element, by storing "start" and
* "end" integer values. This allows for the text and text nodes to change
* inside the element and still have the Curse be able to restore selection
* state.
*
* A `<br>` tag, for example, is counted as a single "character", while
* a text node with the text "Hello, world" is counted as 12 characters.
*
* @method capture
*/
value: function capture() {
var _window$getSelection = window.getSelection();
var anchorNode = _window$getSelection.anchorNode;
var anchorOffset = _window$getSelection.anchorOffset;
var focusNode = _window$getSelection.focusNode;
var focusOffset = _window$getSelection.focusOffset;
var child = undefined,
start = undefined,
end = undefined;
if (anchorNode === null || focusNode === null) {
this.reset();
return;
}
if (anchorNode.nodeName === "#text") {
start = this.lengthUpTo(anchorNode) + anchorOffset;
} else {
child = anchorNode.childNodes[anchorOffset ? anchorOffset - 1 : 0];
start = this.lengthUpTo(child);
}
if (focusNode.nodeName === "#text") {
end = this.lengthUpTo(focusNode) + focusOffset;
} else {
child = focusNode.childNodes[focusOffset ? focusOffset - 1 : 0];
end = this.lengthUpTo(child) + this.nodeLength(child);
}
this.start = start;
this.end = end;
},
writable: true,
enumerable: true,
configurable: true
},
restore: {
/**
* Restore the captured cursor state by iterating over the child nodes in the
* element and counting their length.
*
* @method restore
* @param {Boolean} [onlyActive=true] only restore if the curse's element is
* the active element
*/
value: function restore() {
var onlyActive = arguments[0] === undefined ? true : arguments[0];
if (onlyActive && document.activeElement !== this.element) {
return;
}
if (!onlyActive) {
this.element.focus();
}
var range = document.createRange();
var idx = 0;
var _ref2 = this;
var start = _ref2.start;
var end = _ref2.end;
var iter = this.iterator;
var node = undefined,
setStart = undefined,
setEnd = undefined;
if (this.start > this.end) {
start = this.end;
end = this.start;
}
while (node = iter.nextNode()) {
if (setStart && setEnd) {
break;
}
var nodeLength = this.nodeLength(node);
var isText = node.nodeName === "#text";
var childIdx = undefined;
if (!setStart && start <= idx + nodeLength) {
if (isText) {
range.setStart(node, start - idx);
} else {
childIdx = this.indexOfNode(node);
range.setStart(node.parentNode, childIdx);
}
setStart = true;
}
if (!setEnd && end <= idx + nodeLength) {
if (isText) {
range.setEnd(node, end - idx);
} else {
childIdx = this.indexOfNode(node);
range.setEnd(node.parentNode, childIdx);
}
setEnd = true;
}
idx += nodeLength;
}
var selection = window.getSelection();
selection.removeAllRanges();
// Reverse the selection if it was originally backwards
if (this.start > this.end) {
var startContainer = range.startContainer;
var startOffset = range.startOffset;
range.collapse(false);
selection.addRange(range);
selection.extend(startContainer, startOffset);
} else {
selection.addRange(range);
}
},
writable: true,
enumerable: true,
configurable: true
},
indexOfNode: {
/**
* Get the index of a node in its parent node.
*
* @method indexOfNode
* @private
* @param {Node} child the child node to find the index of
* @returns {Number} the index of the child node
*/
value: function indexOfNode(child) {
var i = 0;
while (child = child.previousSibling) {
i++;
}
return i;
},
writable: true,
enumerable: true,
configurable: true
},
lengthUpTo: {
/**
* Get the number of characters up to a given node.
*
* @method lengthUpTo
* @private
* @param {Node} node a node to find the length up to
* @returns {Number} the length up to the given node
*/
value: function lengthUpTo(lastNode) {
var len = 0;
var iter = this.iterator;
var node = undefined;
while (node = iter.nextNode()) {
if (node === lastNode) {
break;
}
len += this.nodeLength(node);
}
return len;
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
/**
* Reset the state of the cursor.
*
* @method reset
* @private
*/
value: function reset() {
this.start = null;
this.end = null;
},
writable: true,
enumerable: true,
configurable: true
},
nodeLength: {
/**
* Get the "length" of a node. Text nodes are the length of their contents,
* and `<br>` tags, for example, have a length of 1 (a newline character,
* essentially).
*
* @method nodeLength
* @private
* @param {Node} node a Node, typically a Text or HTMLElement node
* @return {Number} the length of the node, as text
*/
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = undefined;
if (this.lineBreak) {
previousSibling = node.previousElementSibling;
}
if (previousSibling && previousSibling.classList.contains(this.lineBreak)) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return Curse;
})();
module.exports = Curse;
}, {}] }, {}, [1])(1);
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],2:[function(require,module,exports){
(function (global){
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.miniprism=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";
/*
* The syntax parsing algorithm in this file is copied heavily from Lea Verou's
* Prism project, which bears this license:
*
* MIT LICENSE
*
* Copyright (c) 2012-2013 Lea Verou
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var grammars = _dereq_("./grammars");
exports.grammars = grammars;
exports.highlight = function highlight(source, grammarName) {
var opts = arguments[2] === undefined ? {} : arguments[2];
var grammar = undefined;
if (typeof grammarName === "string") {
grammar = grammars[grammarName];
}
if (typeof grammarName === "object" && grammarName.constructor === Object) {
grammar = grammarName;
}
if (!grammar) {
throw new Error("Grammar \"" + grammarName + "\" not found.");
}
return stringify(encode(tokenize(source, grammar)), opts.lineClass);
};
function tokenize(source, grammar) {
var strings = [source];
var inlines = grammar.inlines;
if (inlines) {
// jshint -W089
for (var inlineToken in inlines) {
grammar[inlineToken] = inlines[inlineToken];
}
delete grammar.inlines;
}
for (var token in grammar) {
var patterns = grammar[token];
if (!Array.isArray(patterns)) {
patterns = [patterns];
}
for (var i = 0; i < patterns.length; i++) {
var pattern = patterns[i];
var block = pattern.block;
var classes = pattern.classes;
var inside = pattern.inside;
var lookbehind = !!pattern.lookbehind;
var lookbehindLength = 0;
var tag = undefined;
if (pattern.tag) {
tag = pattern.tag;
} else {
tag = block ? "div" : "span";
}
pattern = pattern.pattern || pattern;
for (var _i = 0; _i < strings.length; _i++) {
var string = strings[_i];
if (typeof string !== "string") {
continue;
}
pattern.lastIndex = 0;
var match = pattern.exec(string);
if (!match) {
continue;
}
if (lookbehind) {
lookbehindLength = match[1].length;
}
var from = match.index - 1 + lookbehindLength;
match = match[0].slice(lookbehindLength);
var len = match.length;
var to = from + len;
var before = string.slice(0, from + 1);
var after = string.slice(to + 1);
var args = [_i, 1];
if (before) {
args.push(before);
}
var wrapped = {
block: block,
classes: classes,
tag: tag,
text: inside ? tokenize(match, inside) : match,
token: token
};
args.push(wrapped);
if (after) {
args.push(after);
}
Array.prototype.splice.apply(strings, args);
}
}
}
return strings;
}
function stringify(source) {
var lineClass = arguments[1] === undefined ? "md-line" : arguments[1];
if (source === "\n") {
return "<br>";
}
if (typeof source === "string") {
return source.replace(/\n/g, "");
}
if (Array.isArray(source)) {
return source.reduce(function addItem(result, item) {
return result + stringify(item, lineClass);
}, "");
}
var tag = source.tag;
var classList = source.classes || source.token.split(" ");
var className = classList.map(function (token) {
return "md-" + token;
}).join(" ");
if (source.block) {
className += " " + lineClass;
}
return ["<" + tag + " class=\"" + className + "\">", stringify(source.text, lineClass), "</" + tag + ">"].join("");
}
function encode(src) {
if (Array.isArray(src)) {
return src.map(encode);
} else if (typeof src === "object") {
src.text = encode(src.text);
return src;
} else {
return escapeHTML(src);
}
}
function escapeHTML(str) {
return str.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/\//g, "&#x2F;");
}
},{"./grammars":2}],2:[function(_dereq_,module,exports){
"use strict";
exports.markdown = _dereq_("./markdown");
},{"./markdown":3}],3:[function(_dereq_,module,exports){
"use strict";
/*
* These regexes are in some places copies of, in others modifications of, and
* in some places wholly unrelated to the Markdown regexes found in the
* Stackedit project, which bears this license:
*
* StackEdit - The Markdown editor powered by PageDown.
* Copyright 2013 Benoit Schweblin (http://www.benoitschweblin.com)
* Licensed under an Apache License (http://www.apache.org/licenses/LICENSE-2.0)
*/
exports.gfm = {
block: true,
pattern: /^`{3}.*\n(?:[\s\S]*?)\n`{3} *(?:\n|$)/gm,
inside: {
"gfm-limit": {
block: true,
pattern: /^`{3}.*(?:\n|$)/gm,
inside: {
"gfm-info": {
lookbehind: true,
pattern: /^(`{3}).+(?:\n|$)/
},
"gfm-fence": /^`{3}(?:\n|$)/gm
}
},
"gfm-line": {
block: true,
pattern: /^.*(?:\n|$)/gm
} }
};
exports.blank = [{
block: true,
pattern: /\n(?![\s\S])/mg
}, {
block: true,
pattern: /^\n/mg
}];
exports["setex-h1"] = {
block: true,
pattern: /^.+\n=+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^=].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^=+[ \t]*(?:\n|$)/
}
}
};
exports["setex-h2"] = {
block: true,
pattern: /^(?!^- ).+\n-+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^-].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^-+[ \t]*(?:\n|$)/
}
}
};
exports.code = {
block: true,
pattern: /^(?: {4,}|\t).+(?:\n|$)/gm
};
// h1 through h6
for (var i = 1; i < 7; i++) {
exports["h" + i] = {
classes: ["h" + i, "has-folding"],
block: true,
pattern: new RegExp("^#{" + i + "} .*(?:\n|$)", "gm"),
inside: {
"hash folding": new RegExp("^#{" + i + "} ")
}
};
}
exports.ul = {
classes: ["ul", "has-folding"],
block: true,
pattern: /^[ \t]*(?:[*+\-])[ \t].*(?:\n|$)/gm,
inside: {
"ul-marker folding": /^[ \t]*(?:[*+\-])[ \t]/
}
};
exports.ol = {
block: true,
pattern: /^[ \t]*(?:\d+)\.[ \t].*(?:\n|$)/gm,
inside: {
"ol-marker": /^[ \t]*(?:\d+)\.[ \t]/
}
};
exports.blockquote = {
block: true,
pattern: /^ {0,3}> *.*(?:\n|$)/gm,
inside: {
"blockquote-marker": /^ {0,3}> */
}
};
exports.hr = {
block: true,
pattern: /^(?:[*\-_] *){3,}(?:\n|$)/gm
};
exports["link-def"] = {
block: true,
pattern: /^ {0,3}\[.*?\]:[ \t]+.+(?:\n|$)/gm,
inside: {
"link-def-name": {
pattern: /^ {0,3}\[.*?\]:/,
inside: {
"bracket-start": /^\[/,
"bracket-end": /\](?=:$)/,
colon: /:$/
}
},
"link-def-value": /.*(?:\n|$)/
}
};
exports.p = {
block: true,
pattern: /^.+(?:\n|$)/gm,
inside: {}
};
// jshint -W101
exports.link = {
classes: ["link", "has-folding"],
pattern: /\[(?:(?:\\.)|[^\[\]])*\]\([^\(\)\s]+(?:\(\S*?\))??[^\(\)\s]*?(?:\s(?:['‘][^'’]*['’]|["“][^"”]*["”]))?\)/gm,
inside: {
"bracket-start folding": {
pattern: /(^|[^\\])\[/,
lookbehind: true
},
ref: /(?:(?:\\.)|[^\[\]])+(?=\])/,
"bracket-end folding": /\](?=\s?\()/,
"paren-start folding": /^\(/,
"paren-end folding": /\)$/,
"href folding": /.*/
}
};
// jshint +W101
exports["link-ref"] = {
classes: ["link-ref", "has-folding"],
pattern: /\[(?:.*?)\] ?\[(?:.*?)\]/g,
inside: {
"ref-value folding": {
pattern: /\[[^\[\]]+\]$/,
inside: {
"bracket-start": /\[/,
"ref-href": /[^\[\]]+(?=]$)/,
"bracket-end": /\]/
}
},
"ref-text": {
pattern: /^\[[^\[\]]+\]/,
inside: {
"bracket-start folding": /^\[/,
ref: /^[^\[\]]+/,
"bracket-end folding": /\]$/
}
}
}
};
exports.em = {
classes: ["em", "has-folding"],
pattern: /(^|[^\\])(\*|_)(\S[^\2]*?)??[^\s\\]+?\2/g,
lookbehind: true,
inside: {
"em-marker folding": /(?:^(?:\*|_))|(?:(?:\*|_)$)/
}
};
exports.strong = {
classes: ["strong", "has-folding"],
pattern: /([_\*]){2}(?:(?!\1{2}).)*\1{2}/g,
inside: {
"strong-marker folding": /(?:^(?:\*|_){2})|(?:(?:\*|_){2}$)/
}
};
exports["inline-code"] = {
classes: ["inline-code", "has-folding"],
pattern: /(^|[^\\])`(\S[^`]*?)??[^\s\\]+?`/g,
lookbehind: true,
inside: {
"inline-code-marker folding": /(?:^(?:`))|(?:(?:`)$)/
}
};
var inlines = {
strong: exports.strong,
em: exports.em,
link: exports.link,
"inline-code": exports["inline-code"],
"link-ref": exports["link-ref"]
};
["setex-h1", "setex-h2", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "blockquote", "p"].forEach(function (token) {
exports[token].inside.inlines = inlines;
});
["em", "strong"].forEach(function (token) {
exports[token].inside = exports[token].inside || {};
exports[token].inside.inlines = {
link: exports.link,
"link-ref": exports["link-ref"]
};
});
},{}]},{},[1])
(1)
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./types/constants").PRE;
var blocks = require("./grammar").blocks;
var Null = require("./types").Null;
var OL = require("./types").OL;
var miniprism = _interopRequire(require("miniprism"));
// Standard inlines:
var inlines = miniprism.grammars.markdown.p.inside.inlines;
var slice = Array.prototype.slice;
var Block = (function () {
function Block(editor, _ref) {
var node = _ref.node;
var pre = _ref.pre;
var source = _ref.source;
var type = _ref.type;
this.editor = editor;
this.type = type || new Null();
this.pre = pre || "";
this.content = source;
this.node = node || this.type.createNode();
this.render(true); // (isFirstRender)
}
_prototypeProperties(Block, null, {
source: {
get: function () {
if (this.type.constructor === OL) {
var children = this.node.parentElement ? slice.call(this.node.parentElement.childNodes) : [];
var digit = children.indexOf(this.node) + 1;
return "" + digit + ". " + this._content;
} else {
return this.pre + this._content;
}
},
enumerable: true,
configurable: true
},
content: {
get: function () {
if (this.type.isHeading) {
return "" + this.pre + "" + this._content;
} else {
return this._content;
}
},
set: function (content) {
this._content = content;
var match = undefined,
type = undefined;
if (this.type.isHeading && !content) {
this.type = new Null();
this.pre = "";
}
if (!this.type.shouldReparse) {
return;
}
// jshint -W089
for (var i = 0, len = blocks.length; i < len; i++) {
type = blocks[i];
if (match = content.match(type.pattern)) {
break;
}
}
this.type = type;
this._content = "";
match = match.slice(1);
var labels = type.labels;
for (var i = 0, len = match.length; i < len; i++) {
if (labels[i] === PRE) {
this.pre = match[i];
} else {
this._content += match[i];
}
}
},
enumerable: true,
configurable: true
},
html: {
get: function () {
if (this.type.isHeading) {
return "<span class=\"md-pre\">" + esc(this.pre) + "</span>" + ("" + miniprism.highlight(this._content, inlines));
} else {
return miniprism.highlight(this._content, inlines);
}
},
enumerable: true,
configurable: true
},
shouldContinue: {
get: function () {
return this.type.continues && this.content;
},
enumerable: true,
configurable: true
},
type: {
get: function () {
return this._type;
},
set: function (type) {
this.adjustedPre = false;
this.pre = "";
return this._type = type;
},
enumerable: true,
configurable: true
},
appendTo: {
value: function appendTo(node) {
this.type.appendChild(this.node, node);
},
writable: true,
enumerable: true,
configurable: true
},
clone: {
value: function clone() {
return new this.constructor(this.editor, {
node: this.node.cloneNode(true),
pre: this.pre,
source: this.content,
type: this.type
});
},
writable: true,
enumerable: true,
configurable: true
},
continueFrom: {
value: function continueFrom(block) {
this.type = block.type;
this.pre = block.pre;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
var isFirstRender = arguments[0] === undefined ? false : arguments[0];
if (this.content === this.node.textContent && !isFirstRender) {
return;
}
var oldNode = this.node;
var oldType = this.type;
if (!isFirstRender) {
this.content = this.node.textContent;
}
this.editor.curse.capture();
if (oldType !== this.type) {
this.node = this.type.createNode();
this.type.replaceNode(this.node, oldNode);
}
/*
* Adjust the Curse for `pre` since it is about to be removed from the
* DOM during `#render`. This does not apply to reparsing types, as their
* `pre` is still displayed when focused.
*/
if (!this.adjustedPre && !this.type.shouldReparse) {
this.editor.curse.start -= this.pre.length;
this.editor.curse.end -= this.pre.length;
this.adjustedPre = true;
}
if (this.content) {
this.node.innerHTML = this.html;
} else {
this.node.innerHTML = "<br>";
}
this.editor.curse.restore();
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
value: function reset() {
this.type = new Null();
this.content = this.content;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
selectionSubstring: {
value: function selectionSubstring(sel) {
var anchorNode = sel.anchorNode;
var focusNode = sel.focusNode;
var anchorOffset = sel.anchorOffset;
var focusOffset = sel.focusOffset;
var start = 0;
var end = Infinity;
var curse = this.editor.curse;
if (this.node.contains(anchorNode)) {
start = curse.lengthUpTo(anchorNode) - curse.lengthUpTo(this.node.firstChild) + anchorOffset;
if (this.type.isList) {
start += this.pre.length;
}
}
if (this.node.contains(focusNode)) {
end = curse.lengthUpTo(focusNode) - curse.lengthUpTo(this.node.firstChild) + focusOffset;
if (this.type.isList) {
end += this.pre.length;
}
}
return this.source.substring(start, end);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Block;
})();
module.exports = Block;
function esc(text) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(text));
return div.innerHTML;
}
},{"./grammar":6,"./types":15,"./types/constants":7,"miniprism":2}],4:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Curse = _interopRequire(require("../bower_components/curse/dist/curse"));
var _Curse = (function (Curse) {
function _Curse() {
if (Object.getPrototypeOf(_Curse) !== null) {
Object.getPrototypeOf(_Curse).apply(this, arguments);
}
}
_inherits(_Curse, Curse);
_prototypeProperties(_Curse, null, {
nodeLength: {
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = node.previousElementSibling;
if (previousSibling && previousSibling.classList.contains("LineBreak")) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return _Curse;
})(Curse);
module.exports = _Curse;
},{"../bower_components/curse/dist/curse":1}],5:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Block = _interopRequire(require("./block"));
var Curse = _interopRequire(require("./curse"));
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var BACKSPACE = 8;
var RETURN = 13;
var slice = Array.prototype.slice;
var Editor = (function () {
function Editor() {
var source = arguments[0] === undefined ? "" : arguments[0];
this.blocks = [];
this.node = this.createNode();
this.curse = new Curse(this.node, {
nodeLengths: { BR: 0 }
});
this.source = source;
this.bindEvents();
this.observeMutations();
}
_prototypeProperties(Editor, null, {
anchorNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentAnchor);
},
enumerable: true,
configurable: true
},
focusNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentFocus);
},
enumerable: true,
configurable: true
},
blockNodes: {
get: function () {
return this.blocks.map(function (block) {
return block.node;
});
},
enumerable: true,
configurable: true
},
currentAnchor: {
get: function () {
return this.getNode(window.getSelection().anchorNode);
},
enumerable: true,
configurable: true
},
currentBlock: {
get: function () {
return this.getBlockFromNode(this.currentNode);
},
enumerable: true,
configurable: true
},
currentFocus: {
get: function () {
return this.getNode(window.getSelection().focusNode);
},
enumerable: true,
configurable: true
},
currentNode: {
get: function () {
if (!this.isActive) {
return null;
}
if (this.isReversed) {
return this.currentFocus;
} else {
return this.currentAnchor;
}
},
enumerable: true,
configurable: true
},
foldingNodes: {
get: function () {
return slice.call(this.node.querySelectorAll(".md-folding, .md-pre"));
},
enumerable: true,
configurable: true
},
isActive: {
get: function () {
return document.activeElement === this.node;
},
enumerable: true,
configurable: true
},
isReversed: {
get: function () {
var _ref = this;
var currentAnchor = _ref.currentAnchor;
var currentFocus = _ref.currentFocus;
var nodes = _ref.nodes;
return nodes.indexOf(currentAnchor) > nodes.indexOf(currentFocus);
},
enumerable: true,
configurable: true
},
nodes: {
get: function () {
var nodeList = this.node.querySelectorAll(".Block");
return slice.call(nodeList);
},
enumerable: true,
configurable: true
},
toggleFoldingFn: {
get: function () {
if (this._toggleFoldingFn) {
return this._toggleFoldingFn;
}
return this._toggleFoldingFn = this.toggleFolding.bind(this);
},
enumerable: true,
configurable: true
},
source: {
get: function () {
return this.blocks.map(function (block) {
return block.source;
}).join("\n");
},
set: function (source) {
var _this = this;
this.blocks = source.split(/\n/).map(function (line) {
return new Block(_this, { source: line });
});
this.render();
},
enumerable: true,
configurable: true
},
bindEvents: {
value: function bindEvents() {
document.addEventListener("selectionchange", this.toggleFoldingFn);
this.node.addEventListener("input", this.startRenders.bind(this));
this.node.addEventListener("input", this.toggleFoldingFn);
this.node.addEventListener("keydown", this.onReturn.bind(this));
this.node.addEventListener("keydown", this.preventEmpty.bind(this));
this.node.addEventListener("copy", this.onCopy.bind(this));
this.node.addEventListener("cut", this.onCopy.bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement("div");
node.classList.add("Editor");
node.setAttribute("contenteditable", true);
return node;
},
writable: true,
enumerable: true,
configurable: true
},
eachSelectionNode: {
value: function eachSelectionNode(fn) {
var sel = window.getSelection();
var pointTypes = sel.isCollapsed ? ["anchor"] : ["anchor", "focus"];
for (var i = 0, len = pointTypes.length; i < len; i++) {
var pointType = pointTypes[i];
var node = sel["" + pointType + "Node"];
var offset = sel["" + pointType + "Offset"];
fn(node, offset, sel);
}
},
writable: true,
enumerable: true,
configurable: true
},
focusBlock: {
value: function focusBlock(block, hasContent) {
var range = document.createRange();
var sel = window.getSelection();
var pos = hasContent ? 0 : block.node.childNodes.length;
range.setStart(block.node, pos);
range.setEnd(block.node, pos);
sel.removeAllRanges();
sel.addRange(range);
},
writable: true,
enumerable: true,
configurable: true
},
getBlockFromNode: {
value: function getBlockFromNode(node) {
return this.blocks[this.nodes.indexOf(node)];
},
writable: true,
enumerable: true,
configurable: true
},
getNode: {
value: function getNode(node) {
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
while (!node.classList.contains("Block")) {
node = node.parentElement;
}
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBlock: {
value: function insertBlock(block, prevBlock, nextElementSibling) {
var parentNode = this.node;
var prevNode = prevBlock.node;
var prevParent = prevNode.parentElement;
if (prevBlock.shouldContinue) {
parentNode = prevParent;
block.continueFrom(prevBlock);
} else if (prevBlock.type.continues) {
block.reset();
block.content = block.content;
this.splitBlock(prevParent, prevNode);
prevNode.remove();
if (prevParent.childNodes.length === 0) {
nextElementSibling = prevParent.nextElementSibling;
prevParent.remove();
} else {
nextElementSibling = prevParent;
}
}
block.type.insertBefore(block.node, nextElementSibling, parentNode);
},
writable: true,
enumerable: true,
configurable: true
},
observeMutations: {
value: function observeMutations() {
new MutationObserver(this.onMutation.bind(this)).observe(this.node, { childList: true, subtree: true });
},
writable: true,
enumerable: true,
configurable: true
},
onMutation: {
value: function onMutation(mutationRecords) {
for (var i = 0, len = mutationRecords.length; i < len; i++) {
var mut = mutationRecords[i];
for (var _i = 0, _len = mut.removedNodes.length; _i < _len; _i++) {
this.removeNodes(mut.removedNodes);
}
}
},
writable: true,
enumerable: true,
configurable: true
},
onCopy: {
value: function onCopy(e) {
this.copying = true;
var sel = window.getSelection();
var range = sel.getRangeAt(0);
var copyBin = document.createElement("pre");
var text = "";
var anc = this.anchorNodeBlock;
var foc = this.focusNodeBlock;
var nodes = this.nodes;
text += anc.selectionSubstring(sel) + "\n";
var started = undefined;
for (var i = 0, len = nodes.length; i < len; i++) {
if (foc.node === nodes[i]) {
break;
}
if (anc.node === nodes[i]) {
started = true;
continue;
}
if (started) {
text += this.getBlockFromNode(nodes[i]).source + "\n";
}
}
if (anc !== foc) {
text += foc.selectionSubstring(sel);
}
copyBin.classList.add("CopyBin");
copyBin.textContent = text;
this.node.appendChild(copyBin);
var newRange = document.createRange();
newRange.selectNodeContents(copyBin);
sel.removeAllRanges();
sel.addRange(newRange);
setTimeout((function () {
copyBin.remove();
sel.removeAllRanges();
sel.addRange(range);
this.copying = false;
if (e.type === "cut") {
document.execCommand("insertText", null, "");
}
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
onReturn: {
value: function onReturn(e) {
if (e.keyCode !== RETURN) {
return;
}
e.preventDefault();
var _ref2 = this;
var currentAnchor = _ref2.currentAnchor;
var currentFocus = _ref2.currentFocus;
var currentNode = _ref2.currentNode;
var isReversed = _ref2.isReversed;
var startNode = isReversed ? currentFocus : currentAnchor;
var endNode = isReversed ? currentAnchor : currentFocus;
var nextElementSibling = endNode.nextElementSibling;
var range = window.getSelection().getRangeAt(0);
var collapsed = range.collapsed;
var startContainer = range.startContainer;
var endContainer = range.endContainer;
var startOffset = range.startOffset;
var endOffset = range.endOffset;
// In a copy of the range, select the entire end node of the selection
var rangeCopy = range.cloneRange();
rangeCopy.selectNodeContents(endNode);
// In the range copy, select only the text in the current node *after* the
// user's current selection.
if (range.collapsed) {
rangeCopy.setStart(startContainer, startOffset);
} else {
rangeCopy.setStart(endContainer, endOffset);
}
// Set the text after the user's selection to `source` so that it can be
// inserted into the new block being created.
var source = rangeCopy.toString();
var block = undefined;
if (endContainer === this.node || endOffset === 0) {
block = this.getBlockFromNode(endNode).clone();
} else {
block = new Block(this, { source: source });
}
rangeCopy.deleteContents();
// Delete the content selected by the user
range.deleteContents();
if (currentNode.textContent === "") {
currentNode.innerHTML = "<br>";
}
var idx = this.nodes.indexOf(currentNode) + 1;
this.blocks.splice(idx, 0, block);
this.insertBlock(block, this.blocks[idx - 1], nextElementSibling);
this.focusBlock(block, source);
// When not collapsed remove the end node since we're recreating it with its
// remaining contents.
if (!collapsed && startNode !== endNode) {
endNode.remove();
}
// Manually dispatch an `input` event since we called `preventDefault`.
this.node.dispatchEvent(new Event("input"));
},
writable: true,
enumerable: true,
configurable: true
},
toggleFolding: {
value: function toggleFolding() {
if (this.copying) {
return;
}
this.foldingNodes.forEach(function (node) {
return node.classList.remove("visible");
});
if (!this.isActive) {
return;
}
var range = window.getSelection().getRangeAt(0);
this.foldingNodes.forEach(function (node) {
if (range.intersectsNode(node)) {
node.classList.add("visible");
}
});
slice.call(this.currentNode.querySelectorAll(".md-pre")).forEach(function (node) {
return node.classList.add("visible");
});
this.eachSelectionNode((function maybeAddVisible(node, offset) {
var nextSibling = node.nextElementSibling;
if (nextSibling && nextSibling.classList.contains("md-has-folding") && offset === node.textContent.length) {
node = nextSibling;
}
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
if (!node.classList.contains("md-has-folding")) {
var parentEl = undefined;
var testNode = node;
while (parentEl = testNode.parentElement) {
testNode = parentEl;
if (parentEl.classList.contains("md-has-folding")) {
node = parentEl;
}
if (parentEl.classList.contains("Block")) {
break;
}
}
}
if (!node.classList.contains("md-has-folding")) {
return;
}
slice.call(node.querySelectorAll(".md-folding")).forEach(function (node) {
return node.classList.add("visible");
});
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
preventEmpty: {
value: function preventEmpty(e) {
if (!(window.getSelection().isCollapsed && e.keyCode === BACKSPACE)) {
return;
}
var currentNode = this.currentNode;
if (currentNode.textContent === "" && currentNode === this.nodes[0]) {
e.preventDefault();
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNode: {
value: function removeNode(node) {
if (!node.classList.contains("Block")) {
return;
}
var idx = this.blockNodes.indexOf(node);
if (idx !== -1 && !node.isMoving) {
this.blocks.splice(idx, 1);
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNodes: {
value: function removeNodes(nodes) {
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i];
if (node.nodeType !== ELEMENT_NODE || node.isMoving) {
continue;
}
if (node.classList.contains("Block")) {
this.removeNode(nodes[i]);
} else {
var children = node.querySelectorAll(".Block");
for (var _i2 = 0, _len2 = children.length; _i2 < _len2; _i2++) {
this.removeNode(children[_i2]);
}
}
}
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
this.innerHTML = "";
for (var i = 0, len = this.blocks.length; i < len; i++) {
this.blocks[i].appendTo(this.node);
}
},
writable: true,
enumerable: true,
configurable: true
},
splitBlock: {
value: function splitBlock(block, node) {
var blockOne = block.cloneNode();
// Cache, since we're removing some.
var children = slice.call(block.childNodes);
_loop: for (var i = 0, len = children.length; i < len; i++) {
var _ret = (function (i, len) {
var childNode = children[i];
if (childNode !== node) {
childNode.isMoving = true;
blockOne.appendChild(childNode);
setTimeout(function () {
return childNode.isMoving = false;
});
} else {
return "break";
}
})(i, len);
if (_ret === "break") break _loop;
}
if (blockOne.childNodes.length > 0) {
block.parentElement.insertBefore(blockOne, block);
}
return [blockOne, block];
},
writable: true,
enumerable: true,
configurable: true
},
startRenders: {
value: function startRenders() {
this.blocks.forEach(function (block) {
return block.render();
});
},
writable: true,
enumerable: true,
configurable: true
},
teardown: {
value: function teardown() {
document.removeEventListener("selectionchange", this.toggleFoldingFn);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Editor;
})();
module.exports = Editor;
},{"./block":3,"./curse":4}],6:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var types = _interopRequire(require("./types"));
var grammar = { blocks: [] };
for (var i = 1; i <= 6; i++) {
grammar.blocks.push(new types["H" + i]());
}
grammar.blocks.push(new types.OL());
grammar.blocks.push(new types.UL());
grammar.blocks.push(new types.Paragraph());
module.exports = grammar;
},{"./types":15}],7:[function(require,module,exports){
"use strict";
module.exports = {
PRE: -1
};
},{}],8:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H1 = (function (Heading) {
function H1() {
if (Object.getPrototypeOf(H1) !== null) {
Object.getPrototypeOf(H1).apply(this, arguments);
}
}
_inherits(H1, Heading);
_prototypeProperties(H1, null, {
level: {
get: function () {
return 1;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(# )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H1;
})(Heading);
module.exports = H1;
},{"./heading":14}],9:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H2 = (function (Heading) {
function H2() {
if (Object.getPrototypeOf(H2) !== null) {
Object.getPrototypeOf(H2).apply(this, arguments);
}
}
_inherits(H2, Heading);
_prototypeProperties(H2, null, {
level: {
get: function () {
return 2;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{2} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H2;
})(Heading);
module.exports = H2;
},{"./heading":14}],10:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H3 = (function (Heading) {
function H3() {
if (Object.getPrototypeOf(H3) !== null) {
Object.getPrototypeOf(H3).apply(this, arguments);
}
}
_inherits(H3, Heading);
_prototypeProperties(H3, null, {
level: {
get: function () {
return 3;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{3} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H3;
})(Heading);
module.exports = H3;
},{"./heading":14}],11:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H4 = (function (Heading) {
function H4() {
if (Object.getPrototypeOf(H4) !== null) {
Object.getPrototypeOf(H4).apply(this, arguments);
}
}
_inherits(H4, Heading);
_prototypeProperties(H4, null, {
level: {
get: function () {
return 4;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{4} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H4;
})(Heading);
module.exports = H4;
},{"./heading":14}],12:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H5 = (function (Heading) {
function H5() {
if (Object.getPrototypeOf(H5) !== null) {
Object.getPrototypeOf(H5).apply(this, arguments);
}
}
_inherits(H5, Heading);
_prototypeProperties(H5, null, {
level: {
get: function () {
return 5;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{5} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H5;
})(Heading);
module.exports = H5;
},{"./heading":14}],13:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H6 = (function (Heading) {
function H6() {
if (Object.getPrototypeOf(H6) !== null) {
Object.getPrototypeOf(H6).apply(this, arguments);
}
}
_inherits(H6, Heading);
_prototypeProperties(H6, null, {
level: {
get: function () {
return 6;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{6} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H6;
})(Heading);
module.exports = H6;
},{"./heading":14}],14:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./constants").PRE;
var Type = _interopRequire(require("./type"));
var Heading = (function (Type) {
function Heading() {
if (Object.getPrototypeOf(Heading) !== null) {
Object.getPrototypeOf(Heading).apply(this, arguments);
}
}
_inherits(Heading, Type);
_prototypeProperties(Heading, null, {
cssClass: {
get: function () {
return "h" + this.level;
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "H" + this.level;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return new RegExp("^(#{1,6} )(.*)$");
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Heading;
})(Type);
module.exports = Heading;
},{"./constants":7,"./type":20}],15:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var H1 = _interopRequire(require("./h1"));
var H2 = _interopRequire(require("./h2"));
var H3 = _interopRequire(require("./h3"));
var H4 = _interopRequire(require("./h4"));
var H5 = _interopRequire(require("./h5"));
var H6 = _interopRequire(require("./h6"));
var Null = _interopRequire(require("./null"));
var Paragraph = _interopRequire(require("./paragraph"));
var OL = _interopRequire(require("./ol"));
var UL = _interopRequire(require("./ul"));
module.exports = {
H1: H1,
H2: H2,
H3: H3,
H4: H4,
H5: H5,
H6: H6,
Null: Null,
Paragraph: Paragraph,
OL: OL,
UL: UL
};
},{"./h1":8,"./h2":9,"./h3":10,"./h4":11,"./h5":12,"./h6":13,"./null":17,"./ol":18,"./paragraph":19,"./ul":21}],16:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var PRE = require("./constants").PRE;
var List = (function (Type) {
function List() {
if (Object.getPrototypeOf(List) !== null) {
Object.getPrototypeOf(List).apply(this, arguments);
}
}
_inherits(List, Type);
_prototypeProperties(List, null, {
continues: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "li";
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "LI";
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
var listNode = undefined;
if (parent.lastChild && parent.lastChild.nodeName === this.parentNodeName) {
listNode = parent.lastChild;
} else {
listNode = this.createListNode();
}
listNode.appendChild(node);
parent.appendChild(listNode);
},
writable: true,
enumerable: true,
configurable: true
},
createListNode: {
value: function createListNode() {
var ul = document.createElement(this.parentNodeName.toLowerCase());
ul.classList.add("LineBreak");
return ul;
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
var listNode = undefined;
if (oldNode.previousElementSibling && oldNode.previousElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.previousElementSibling;
listNode.appendChild(node);
} else if (oldNode.nextElementSibling && oldNode.nextElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.nextElementSibling;
listNode.insertBefore(node, listNode.firstChild);
} else {
listNode = this.createListNode();
listNode.appendChild(node);
}
listNode.isMoving = true;
oldNode.parentElement.replaceChild(listNode, oldNode);
setTimeout(function () {
return listNode.isMoving = false;
});
},
writable: true,
enumerable: true,
configurable: true
}
});
return List;
})(Type);
module.exports = List;
},{"./constants":7,"./type":20}],17:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Null = (function (Type) {
function Null() {
if (Object.getPrototypeOf(Null) !== null) {
Object.getPrototypeOf(Null).apply(this, arguments);
}
}
_inherits(Null, Type);
_prototypeProperties(Null, null, {
isNull: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Null;
})(Type);
module.exports = Null;
},{"./type":20}],18:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var OL = (function (List) {
function OL() {
if (Object.getPrototypeOf(OL) !== null) {
Object.getPrototypeOf(OL).apply(this, arguments);
}
}
_inherits(OL, List);
_prototypeProperties(OL, null, {
cssClass: {
get: function () {
return "ol-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "OL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(\d+\. )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return OL;
})(List);
module.exports = OL;
},{"./list":16}],19:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Paragraph = (function (Type) {
function Paragraph() {
if (Object.getPrototypeOf(Paragraph) !== null) {
Object.getPrototypeOf(Paragraph).apply(this, arguments);
}
}
_inherits(Paragraph, Type);
_prototypeProperties(Paragraph, null, {
cssClass: {
get: function () {
return "p";
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "P";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(.*)$/;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Paragraph;
})(Type);
module.exports = Paragraph;
},{"./type":20}],20:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Type = (function () {
function Type() {}
_prototypeProperties(Type, null, {
continues: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "";
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isNull: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "DIV";
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
parent.appendChild(node);
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement(this.nodeName.toLowerCase());
node.className = "Block LineBreak";
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBefore: {
value: function insertBefore(node, next, parent) {
parent.insertBefore(node, next);
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
oldNode.parentElement.replaceChild(node, oldNode);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Type;
})();
module.exports = Type;
},{}],21:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var UL = (function (List) {
function UL() {
if (Object.getPrototypeOf(UL) !== null) {
Object.getPrototypeOf(UL).apply(this, arguments);
}
}
_inherits(UL, List);
_prototypeProperties(UL, null, {
cssClass: {
get: function () {
return "ul-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "UL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(- )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return UL;
})(List);
module.exports = UL;
},{"./list":16}]},{},[5])
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
"use strict";
!(function (e) {
if ("object" == typeof exports) module.exports = e();else if ("function" == typeof define && define.amd) define(e);else {
var f;"undefined" != typeof window ? f = window : "undefined" != typeof global ? f = global : "undefined" != typeof self && (f = self), f.Curse = e();
}
})(function () {
var define, module, exports;return (function e(t, n, r) {
var s = function (o, u) {
if (!n[o]) {
if (!t[o]) {
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);throw new Error("Cannot find module '" + o + "'");
}var f = n[o] = { exports: {} };t[o][0].call(f.exports, function (e) {
var n = t[o][1][e];return s(n ? n : e);
}, f, f.exports, e, t, n, r);
}return n[o].exports;
};
var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) s(r[o]);return s;
})({ 1: [function (_dereq_, module, exports) {
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
/**
* Captures and restores the cursor position inside of an HTML element. This
* is particularly useful for capturing, editing, and restoring selections
* in contenteditable elements, where the selection may span both text nodes
* and element nodes.
*
* var elem = document.querySelector('#editor');
* var curse = new Curse(elem);
* curse.capture();
*
* // ...
*
* curse.restore();
*
* @class Curse
* @constructor
* @param {HTMLElement} element an element to track the cursor inside of
*/
var Curse = (function () {
var Curse = function (element) {
var _ref = arguments[1] === undefined ? {} : arguments[1];
var lineBreak = _ref.lineBreak;
var nodeLengths = _ref.nodeLengths;
this.lineBreak = lineBreak;
this.nodeLengths = nodeLengths || {};
this.element = element;
this.reset();
};
_prototypeProperties(Curse, null, {
iterator: {
/**
* An iterator to iterate over the nodes in `this.element`.
*
* This returns a simple node iterator that skips `this.element`, but not its
* children.
*
* @property iterator
* @private
* @type {NodeIterator}
*/
get: function () {
var elem = this.element;
return document.createNodeIterator(this.element, NodeFilter.SHOW_ALL, function onNode(node) {
return node === elem ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
});
},
enumerable: true,
configurable: true
},
capture: {
/**
* Captures the current selection in the element, by storing "start" and
* "end" integer values. This allows for the text and text nodes to change
* inside the element and still have the Curse be able to restore selection
* state.
*
* A `<br>` tag, for example, is counted as a single "character", while
* a text node with the text "Hello, world" is counted as 12 characters.
*
* @method capture
*/
value: function capture() {
var _window$getSelection = window.getSelection();
var anchorNode = _window$getSelection.anchorNode;
var anchorOffset = _window$getSelection.anchorOffset;
var focusNode = _window$getSelection.focusNode;
var focusOffset = _window$getSelection.focusOffset;
var child = undefined,
start = undefined,
end = undefined;
if (anchorNode === null || focusNode === null) {
this.reset();
return;
}
if (anchorNode.nodeName === "#text") {
start = this.lengthUpTo(anchorNode) + anchorOffset;
} else {
child = anchorNode.childNodes[anchorOffset ? anchorOffset - 1 : 0];
start = this.lengthUpTo(child);
}
if (focusNode.nodeName === "#text") {
end = this.lengthUpTo(focusNode) + focusOffset;
} else {
child = focusNode.childNodes[focusOffset ? focusOffset - 1 : 0];
end = this.lengthUpTo(child) + this.nodeLength(child);
}
this.start = start;
this.end = end;
},
writable: true,
enumerable: true,
configurable: true
},
restore: {
/**
* Restore the captured cursor state by iterating over the child nodes in the
* element and counting their length.
*
* @method restore
* @param {Boolean} [onlyActive=true] only restore if the curse's element is
* the active element
*/
value: function restore() {
var onlyActive = arguments[0] === undefined ? true : arguments[0];
if (onlyActive && document.activeElement !== this.element) {
return;
}
if (!onlyActive) {
this.element.focus();
}
var range = document.createRange();
var idx = 0;
var _ref2 = this;
var start = _ref2.start;
var end = _ref2.end;
var iter = this.iterator;
var node = undefined,
setStart = undefined,
setEnd = undefined;
if (this.start > this.end) {
start = this.end;
end = this.start;
}
while (node = iter.nextNode()) {
if (setStart && setEnd) {
break;
}
var nodeLength = this.nodeLength(node);
var isText = node.nodeName === "#text";
var childIdx = undefined;
if (!setStart && start <= idx + nodeLength) {
if (isText) {
range.setStart(node, start - idx);
} else {
childIdx = this.indexOfNode(node);
range.setStart(node.parentNode, childIdx);
}
setStart = true;
}
if (!setEnd && end <= idx + nodeLength) {
if (isText) {
range.setEnd(node, end - idx);
} else {
childIdx = this.indexOfNode(node);
range.setEnd(node.parentNode, childIdx);
}
setEnd = true;
}
idx += nodeLength;
}
var selection = window.getSelection();
selection.removeAllRanges();
// Reverse the selection if it was originally backwards
if (this.start > this.end) {
var startContainer = range.startContainer;
var startOffset = range.startOffset;
range.collapse(false);
selection.addRange(range);
selection.extend(startContainer, startOffset);
} else {
selection.addRange(range);
}
},
writable: true,
enumerable: true,
configurable: true
},
indexOfNode: {
/**
* Get the index of a node in its parent node.
*
* @method indexOfNode
* @private
* @param {Node} child the child node to find the index of
* @returns {Number} the index of the child node
*/
value: function indexOfNode(child) {
var i = 0;
while (child = child.previousSibling) {
i++;
}
return i;
},
writable: true,
enumerable: true,
configurable: true
},
lengthUpTo: {
/**
* Get the number of characters up to a given node.
*
* @method lengthUpTo
* @private
* @param {Node} node a node to find the length up to
* @returns {Number} the length up to the given node
*/
value: function lengthUpTo(lastNode) {
var len = 0;
var iter = this.iterator;
var node = undefined;
while (node = iter.nextNode()) {
if (node === lastNode) {
break;
}
len += this.nodeLength(node);
}
return len;
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
/**
* Reset the state of the cursor.
*
* @method reset
* @private
*/
value: function reset() {
this.start = null;
this.end = null;
},
writable: true,
enumerable: true,
configurable: true
},
nodeLength: {
/**
* Get the "length" of a node. Text nodes are the length of their contents,
* and `<br>` tags, for example, have a length of 1 (a newline character,
* essentially).
*
* @method nodeLength
* @private
* @param {Node} node a Node, typically a Text or HTMLElement node
* @return {Number} the length of the node, as text
*/
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = undefined;
if (this.lineBreak) {
previousSibling = node.previousElementSibling;
}
if (previousSibling && previousSibling.classList.contains(this.lineBreak)) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return Curse;
})();
module.exports = Curse;
}, {}] }, {}, [1])(1);
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],2:[function(require,module,exports){
(function (global){
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.miniprism=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";
/*
* The syntax parsing algorithm in this file is copied heavily from Lea Verou's
* Prism project, which bears this license:
*
* MIT LICENSE
*
* Copyright (c) 2012-2013 Lea Verou
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var grammars = _dereq_("./grammars");
exports.grammars = grammars;
exports.highlight = function highlight(source, grammarName) {
var opts = arguments[2] === undefined ? {} : arguments[2];
var grammar = undefined;
if (typeof grammarName === "string") {
grammar = grammars[grammarName];
}
if (typeof grammarName === "object" && grammarName.constructor === Object) {
grammar = grammarName;
}
if (!grammar) {
throw new Error("Grammar \"" + grammarName + "\" not found.");
}
return stringify(encode(tokenize(source, grammar)), opts.lineClass);
};
function tokenize(source, grammar) {
var strings = [source];
var inlines = grammar.inlines;
if (inlines) {
// jshint -W089
for (var inlineToken in inlines) {
grammar[inlineToken] = inlines[inlineToken];
}
delete grammar.inlines;
}
for (var token in grammar) {
var patterns = grammar[token];
if (!Array.isArray(patterns)) {
patterns = [patterns];
}
for (var i = 0; i < patterns.length; i++) {
var pattern = patterns[i];
var block = pattern.block;
var classes = pattern.classes;
var inside = pattern.inside;
var lookbehind = !!pattern.lookbehind;
var lookbehindLength = 0;
var tag = undefined;
if (pattern.tag) {
tag = pattern.tag;
} else {
tag = block ? "div" : "span";
}
pattern = pattern.pattern || pattern;
for (var _i = 0; _i < strings.length; _i++) {
var string = strings[_i];
if (typeof string !== "string") {
continue;
}
pattern.lastIndex = 0;
var match = pattern.exec(string);
if (!match) {
continue;
}
if (lookbehind) {
lookbehindLength = match[1].length;
}
var from = match.index - 1 + lookbehindLength;
match = match[0].slice(lookbehindLength);
var len = match.length;
var to = from + len;
var before = string.slice(0, from + 1);
var after = string.slice(to + 1);
var args = [_i, 1];
if (before) {
args.push(before);
}
var wrapped = {
block: block,
classes: classes,
tag: tag,
text: inside ? tokenize(match, inside) : match,
token: token
};
args.push(wrapped);
if (after) {
args.push(after);
}
Array.prototype.splice.apply(strings, args);
}
}
}
return strings;
}
function stringify(source) {
var lineClass = arguments[1] === undefined ? "md-line" : arguments[1];
if (source === "\n") {
return "<br>";
}
if (typeof source === "string") {
return source.replace(/\n/g, "");
}
if (Array.isArray(source)) {
return source.reduce(function addItem(result, item) {
return result + stringify(item, lineClass);
}, "");
}
var tag = source.tag;
var classList = source.classes || source.token.split(" ");
var className = classList.map(function (token) {
return "md-" + token;
}).join(" ");
if (source.block) {
className += " " + lineClass;
}
return ["<" + tag + " class=\"" + className + "\">", stringify(source.text, lineClass), "</" + tag + ">"].join("");
}
function encode(src) {
if (Array.isArray(src)) {
return src.map(encode);
} else if (typeof src === "object") {
src.text = encode(src.text);
return src;
} else {
return escapeHTML(src);
}
}
function escapeHTML(str) {
return str.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/\//g, "&#x2F;");
}
},{"./grammars":2}],2:[function(_dereq_,module,exports){
"use strict";
exports.markdown = _dereq_("./markdown");
},{"./markdown":3}],3:[function(_dereq_,module,exports){
"use strict";
/*
* These regexes are in some places copies of, in others modifications of, and
* in some places wholly unrelated to the Markdown regexes found in the
* Stackedit project, which bears this license:
*
* StackEdit - The Markdown editor powered by PageDown.
* Copyright 2013 Benoit Schweblin (http://www.benoitschweblin.com)
* Licensed under an Apache License (http://www.apache.org/licenses/LICENSE-2.0)
*/
exports.gfm = {
block: true,
pattern: /^`{3}.*\n(?:[\s\S]*?)\n`{3} *(?:\n|$)/gm,
inside: {
"gfm-limit": {
block: true,
pattern: /^`{3}.*(?:\n|$)/gm,
inside: {
"gfm-info": {
lookbehind: true,
pattern: /^(`{3}).+(?:\n|$)/
},
"gfm-fence": /^`{3}(?:\n|$)/gm
}
},
"gfm-line": {
block: true,
pattern: /^.*(?:\n|$)/gm
} }
};
exports.blank = [{
block: true,
pattern: /\n(?![\s\S])/mg
}, {
block: true,
pattern: /^\n/mg
}];
exports["setex-h1"] = {
block: true,
pattern: /^.+\n=+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^=].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^=+[ \t]*(?:\n|$)/
}
}
};
exports["setex-h2"] = {
block: true,
pattern: /^(?!^- ).+\n-+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^-].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^-+[ \t]*(?:\n|$)/
}
}
};
exports.code = {
block: true,
pattern: /^(?: {4,}|\t).+(?:\n|$)/gm
};
// h1 through h6
for (var i = 1; i < 7; i++) {
exports["h" + i] = {
classes: ["h" + i, "has-folding"],
block: true,
pattern: new RegExp("^#{" + i + "} .*(?:\n|$)", "gm"),
inside: {
"hash folding": new RegExp("^#{" + i + "} ")
}
};
}
exports.ul = {
classes: ["ul", "has-folding"],
block: true,
pattern: /^[ \t]*(?:[*+\-])[ \t].*(?:\n|$)/gm,
inside: {
"ul-marker folding": /^[ \t]*(?:[*+\-])[ \t]/
}
};
exports.ol = {
block: true,
pattern: /^[ \t]*(?:\d+)\.[ \t].*(?:\n|$)/gm,
inside: {
"ol-marker": /^[ \t]*(?:\d+)\.[ \t]/
}
};
exports.blockquote = {
block: true,
pattern: /^ {0,3}> *.*(?:\n|$)/gm,
inside: {
"blockquote-marker": /^ {0,3}> */
}
};
exports.hr = {
block: true,
pattern: /^(?:[*\-_] *){3,}(?:\n|$)/gm
};
exports["link-def"] = {
block: true,
pattern: /^ {0,3}\[.*?\]:[ \t]+.+(?:\n|$)/gm,
inside: {
"link-def-name": {
pattern: /^ {0,3}\[.*?\]:/,
inside: {
"bracket-start": /^\[/,
"bracket-end": /\](?=:$)/,
colon: /:$/
}
},
"link-def-value": /.*(?:\n|$)/
}
};
exports.p = {
block: true,
pattern: /^.+(?:\n|$)/gm,
inside: {}
};
// jshint -W101
exports.link = {
classes: ["link", "has-folding"],
pattern: /\[(?:(?:\\.)|[^\[\]])*\]\([^\(\)\s]+(?:\(\S*?\))??[^\(\)\s]*?(?:\s(?:['‘][^'’]*['’]|["“][^"”]*["”]))?\)/gm,
inside: {
"bracket-start folding": {
pattern: /(^|[^\\])\[/,
lookbehind: true
},
ref: /(?:(?:\\.)|[^\[\]])+(?=\])/,
"bracket-end folding": /\](?=\s?\()/,
"paren-start folding": /^\(/,
"paren-end folding": /\)$/,
"href folding": /.*/
}
};
// jshint +W101
exports["link-ref"] = {
classes: ["link-ref", "has-folding"],
pattern: /\[(?:.*?)\] ?\[(?:.*?)\]/g,
inside: {
"ref-value folding": {
pattern: /\[[^\[\]]+\]$/,
inside: {
"bracket-start": /\[/,
"ref-href": /[^\[\]]+(?=]$)/,
"bracket-end": /\]/
}
},
"ref-text": {
pattern: /^\[[^\[\]]+\]/,
inside: {
"bracket-start folding": /^\[/,
ref: /^[^\[\]]+/,
"bracket-end folding": /\]$/
}
}
}
};
exports.em = {
classes: ["em", "has-folding"],
pattern: /(^|[^\\])(\*|_)(\S[^\2]*?)??[^\s\\]+?\2/g,
lookbehind: true,
inside: {
"em-marker folding": /(?:^(?:\*|_))|(?:(?:\*|_)$)/
}
};
exports.strong = {
classes: ["strong", "has-folding"],
pattern: /([_\*]){2}(?:(?!\1{2}).)*\1{2}/g,
inside: {
"strong-marker folding": /(?:^(?:\*|_){2})|(?:(?:\*|_){2}$)/
}
};
exports["inline-code"] = {
classes: ["inline-code", "has-folding"],
pattern: /(^|[^\\])`(\S[^`]*?)??[^\s\\]+?`/g,
lookbehind: true,
inside: {
"inline-code-marker folding": /(?:^(?:`))|(?:(?:`)$)/
}
};
var inlines = {
strong: exports.strong,
em: exports.em,
link: exports.link,
"inline-code": exports["inline-code"],
"link-ref": exports["link-ref"]
};
["setex-h1", "setex-h2", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "blockquote", "p"].forEach(function (token) {
exports[token].inside.inlines = inlines;
});
["em", "strong"].forEach(function (token) {
exports[token].inside = exports[token].inside || {};
exports[token].inside.inlines = {
link: exports.link,
"link-ref": exports["link-ref"]
};
});
},{}]},{},[1])
(1)
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./types/constants").PRE;
var blocks = require("./grammar").blocks;
var Null = require("./types").Null;
var OL = require("./types").OL;
var miniprism = _interopRequire(require("miniprism"));
// Standard inlines:
var inlines = miniprism.grammars.markdown.p.inside.inlines;
var slice = Array.prototype.slice;
var Block = (function () {
function Block(editor, _ref) {
var node = _ref.node;
var pre = _ref.pre;
var source = _ref.source;
var type = _ref.type;
this.editor = editor;
this.type = type || new Null();
this.pre = pre || "";
this.content = source;
this.node = node || this.type.createNode();
this.render(true); // (isFirstRender)
}
_prototypeProperties(Block, null, {
source: {
get: function () {
if (this.type.constructor === OL) {
var children = this.node.parentElement ? slice.call(this.node.parentElement.childNodes) : [];
var digit = children.indexOf(this.node) + 1;
return "" + digit + ". " + this._content;
} else {
return this.pre + this._content;
}
},
enumerable: true,
configurable: true
},
content: {
get: function () {
if (this.type.isHeading) {
return "" + this.pre + "" + this._content;
} else {
return this._content;
}
},
set: function (content) {
this._content = content;
var match = undefined,
type = undefined;
if (this.type.isHeading && !content) {
this.type = new Null();
this.pre = "";
}
if (!this.type.shouldReparse) {
return;
}
// jshint -W089
for (var i = 0, len = blocks.length; i < len; i++) {
type = blocks[i];
if (match = content.match(type.pattern)) {
break;
}
}
this.type = type;
this._content = "";
match = match.slice(1);
var labels = type.labels;
for (var i = 0, len = match.length; i < len; i++) {
if (labels[i] === PRE) {
this.pre = match[i];
} else {
this._content += match[i];
}
}
},
enumerable: true,
configurable: true
},
html: {
get: function () {
if (this.type.isHeading) {
return "<span class=\"md-pre\">" + esc(this.pre) + "</span>" + ("" + miniprism.highlight(this._content, inlines));
} else {
return miniprism.highlight(this._content, inlines);
}
},
enumerable: true,
configurable: true
},
shouldContinue: {
get: function () {
return this.type.continues && this.content;
},
enumerable: true,
configurable: true
},
type: {
get: function () {
return this._type;
},
set: function (type) {
this.adjustedPre = false;
this.pre = "";
return this._type = type;
},
enumerable: true,
configurable: true
},
appendTo: {
value: function appendTo(node) {
this.type.appendChild(this.node, node);
},
writable: true,
enumerable: true,
configurable: true
},
clone: {
value: function clone() {
return new this.constructor(this.editor, {
node: this.node.cloneNode(true),
pre: this.pre,
source: this.content,
type: this.type
});
},
writable: true,
enumerable: true,
configurable: true
},
continueFrom: {
value: function continueFrom(block) {
this.type = block.type;
this.pre = block.pre;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
var isFirstRender = arguments[0] === undefined ? false : arguments[0];
if (this.content === this.node.textContent && !isFirstRender) {
return;
}
var oldNode = this.node;
var oldType = this.type;
if (!isFirstRender) {
this.content = this.node.textContent;
}
this.editor.curse.capture();
if (oldType !== this.type) {
this.node = this.type.createNode();
this.type.replaceNode(this.node, oldNode);
}
/*
* Adjust the Curse for `pre` since it is about to be removed from the
* DOM during `#render`. This does not apply to reparsing types, as their
* `pre` is still displayed when focused.
*/
if (!this.adjustedPre && !this.type.shouldReparse) {
this.editor.curse.start -= this.pre.length;
this.editor.curse.end -= this.pre.length;
this.adjustedPre = true;
}
if (this.content) {
this.node.innerHTML = this.html;
} else {
this.node.innerHTML = "<br>";
}
this.editor.curse.restore();
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
value: function reset() {
this.type = new Null();
this.content = this.content;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
selectionSubstring: {
value: function selectionSubstring(sel) {
var anchorNode = sel.anchorNode;
var focusNode = sel.focusNode;
var anchorOffset = sel.anchorOffset;
var focusOffset = sel.focusOffset;
var start = 0;
var end = Infinity;
var curse = this.editor.curse;
if (this.node.contains(anchorNode)) {
start = curse.lengthUpTo(anchorNode) - curse.lengthUpTo(this.node.firstChild) + anchorOffset;
if (this.type.isList) {
start += this.pre.length;
}
}
if (this.node.contains(focusNode)) {
end = curse.lengthUpTo(focusNode) - curse.lengthUpTo(this.node.firstChild) + focusOffset;
if (this.type.isList) {
end += this.pre.length;
}
}
return this.source.substring(start, end);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Block;
})();
module.exports = Block;
function esc(text) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(text));
return div.innerHTML;
}
},{"./grammar":6,"./types":15,"./types/constants":7,"miniprism":2}],4:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Curse = _interopRequire(require("../bower_components/curse/dist/curse"));
var _Curse = (function (Curse) {
function _Curse() {
if (Object.getPrototypeOf(_Curse) !== null) {
Object.getPrototypeOf(_Curse).apply(this, arguments);
}
}
_inherits(_Curse, Curse);
_prototypeProperties(_Curse, null, {
nodeLength: {
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = node.previousElementSibling;
if (previousSibling && previousSibling.classList.contains("LineBreak")) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return _Curse;
})(Curse);
module.exports = _Curse;
},{"../bower_components/curse/dist/curse":1}],5:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Block = _interopRequire(require("./block"));
var Curse = _interopRequire(require("./curse"));
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var BACKSPACE = 8;
var RETURN = 13;
var slice = Array.prototype.slice;
var Editor = (function () {
function Editor() {
var source = arguments[0] === undefined ? "" : arguments[0];
this.blocks = [];
this.node = this.createNode();
this.curse = new Curse(this.node, {
nodeLengths: { BR: 0 }
});
this.source = source;
this.bindEvents();
this.observeMutations();
}
_prototypeProperties(Editor, null, {
anchorNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentAnchor);
},
enumerable: true,
configurable: true
},
focusNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentFocus);
},
enumerable: true,
configurable: true
},
blockNodes: {
get: function () {
return this.blocks.map(function (block) {
return block.node;
});
},
enumerable: true,
configurable: true
},
currentAnchor: {
get: function () {
return this.getNode(window.getSelection().anchorNode);
},
enumerable: true,
configurable: true
},
currentBlock: {
get: function () {
return this.getBlockFromNode(this.currentNode);
},
enumerable: true,
configurable: true
},
currentFocus: {
get: function () {
return this.getNode(window.getSelection().focusNode);
},
enumerable: true,
configurable: true
},
currentNode: {
get: function () {
if (!this.isActive) {
return null;
}
if (this.isReversed) {
return this.currentFocus;
} else {
return this.currentAnchor;
}
},
enumerable: true,
configurable: true
},
foldingNodes: {
get: function () {
return slice.call(this.node.querySelectorAll(".md-folding, .md-pre"));
},
enumerable: true,
configurable: true
},
isActive: {
get: function () {
return document.activeElement === this.node;
},
enumerable: true,
configurable: true
},
isReversed: {
get: function () {
var _ref = this;
var currentAnchor = _ref.currentAnchor;
var currentFocus = _ref.currentFocus;
var nodes = _ref.nodes;
return nodes.indexOf(currentAnchor) > nodes.indexOf(currentFocus);
},
enumerable: true,
configurable: true
},
nodes: {
get: function () {
var nodeList = this.node.querySelectorAll(".Block");
return slice.call(nodeList);
},
enumerable: true,
configurable: true
},
toggleFoldingFn: {
get: function () {
if (this._toggleFoldingFn) {
return this._toggleFoldingFn;
}
return this._toggleFoldingFn = this.toggleFolding.bind(this);
},
enumerable: true,
configurable: true
},
source: {
get: function () {
return this.blocks.map(function (block) {
return block.source;
}).join("\n");
},
set: function (source) {
var _this = this;
this.blocks = source.split(/\n/).map(function (line) {
return new Block(_this, { source: line });
});
this.render();
},
enumerable: true,
configurable: true
},
bindEvents: {
value: function bindEvents() {
document.addEventListener("selectionchange", this.toggleFoldingFn);
this.node.addEventListener("input", this.startRenders.bind(this));
this.node.addEventListener("input", this.toggleFoldingFn);
this.node.addEventListener("keydown", this.onReturn.bind(this));
this.node.addEventListener("keydown", this.preventEmpty.bind(this));
this.node.addEventListener("copy", this.onCopy.bind(this));
this.node.addEventListener("cut", this.onCopy.bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement("div");
node.classList.add("Editor");
node.setAttribute("contenteditable", true);
return node;
},
writable: true,
enumerable: true,
configurable: true
},
eachSelectionNode: {
value: function eachSelectionNode(fn) {
var sel = window.getSelection();
var pointTypes = sel.isCollapsed ? ["anchor"] : ["anchor", "focus"];
for (var i = 0, len = pointTypes.length; i < len; i++) {
var pointType = pointTypes[i];
var node = sel["" + pointType + "Node"];
var offset = sel["" + pointType + "Offset"];
fn(node, offset, sel);
}
},
writable: true,
enumerable: true,
configurable: true
},
focusBlock: {
value: function focusBlock(block, hasContent) {
var range = document.createRange();
var sel = window.getSelection();
var pos = hasContent ? 0 : block.node.childNodes.length;
range.setStart(block.node, pos);
range.setEnd(block.node, pos);
sel.removeAllRanges();
sel.addRange(range);
},
writable: true,
enumerable: true,
configurable: true
},
getBlockFromNode: {
value: function getBlockFromNode(node) {
return this.blocks[this.nodes.indexOf(node)];
},
writable: true,
enumerable: true,
configurable: true
},
getNode: {
value: function getNode(node) {
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
while (!node.classList.contains("Block")) {
node = node.parentElement;
}
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBlock: {
value: function insertBlock(block, prevBlock, nextElementSibling) {
var parentNode = this.node;
var prevNode = prevBlock.node;
var prevParent = prevNode.parentElement;
if (prevBlock.shouldContinue) {
parentNode = prevParent;
block.continueFrom(prevBlock);
} else if (prevBlock.type.continues) {
block.reset();
block.content = block.content;
this.splitBlock(prevParent, prevNode);
prevNode.remove();
if (prevParent.childNodes.length === 0) {
nextElementSibling = prevParent.nextElementSibling;
prevParent.remove();
} else {
nextElementSibling = prevParent;
}
}
block.type.insertBefore(block.node, nextElementSibling, parentNode);
},
writable: true,
enumerable: true,
configurable: true
},
observeMutations: {
value: function observeMutations() {
new MutationObserver(this.onMutation.bind(this)).observe(this.node, { childList: true, subtree: true });
},
writable: true,
enumerable: true,
configurable: true
},
onMutation: {
value: function onMutation(mutationRecords) {
for (var i = 0, len = mutationRecords.length; i < len; i++) {
var mut = mutationRecords[i];
for (var _i = 0, _len = mut.removedNodes.length; _i < _len; _i++) {
this.removeNodes(mut.removedNodes);
}
}
},
writable: true,
enumerable: true,
configurable: true
},
onCopy: {
value: function onCopy(e) {
this.copying = true;
var sel = window.getSelection();
var range = sel.getRangeAt(0);
var copyBin = document.createElement("pre");
var text = "";
var anc = this.anchorNodeBlock;
var foc = this.focusNodeBlock;
var nodes = this.nodes;
text += anc.selectionSubstring(sel) + "\n";
var started = undefined;
for (var i = 0, len = nodes.length; i < len; i++) {
if (foc.node === nodes[i]) {
break;
}
if (anc.node === nodes[i]) {
started = true;
continue;
}
if (started) {
text += this.getBlockFromNode(nodes[i]).source + "\n";
}
}
if (anc !== foc) {
text += foc.selectionSubstring(sel);
}
copyBin.classList.add("CopyBin");
copyBin.textContent = text;
this.node.appendChild(copyBin);
var newRange = document.createRange();
newRange.selectNodeContents(copyBin);
sel.removeAllRanges();
sel.addRange(newRange);
setTimeout((function () {
copyBin.remove();
sel.removeAllRanges();
sel.addRange(range);
this.copying = false;
if (e.type === "cut") {
document.execCommand("insertText", null, "");
}
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
onReturn: {
value: function onReturn(e) {
if (e.keyCode !== RETURN) {
return;
}
e.preventDefault();
var _ref2 = this;
var currentAnchor = _ref2.currentAnchor;
var currentFocus = _ref2.currentFocus;
var currentNode = _ref2.currentNode;
var isReversed = _ref2.isReversed;
var startNode = isReversed ? currentFocus : currentAnchor;
var endNode = isReversed ? currentAnchor : currentFocus;
var nextElementSibling = endNode.nextElementSibling;
var range = window.getSelection().getRangeAt(0);
var collapsed = range.collapsed;
var startContainer = range.startContainer;
var endContainer = range.endContainer;
var startOffset = range.startOffset;
var endOffset = range.endOffset;
// In a copy of the range, select the entire end node of the selection
var rangeCopy = range.cloneRange();
rangeCopy.selectNodeContents(endNode);
// In the range copy, select only the text in the current node *after* the
// user's current selection.
if (range.collapsed) {
rangeCopy.setStart(startContainer, startOffset);
} else {
rangeCopy.setStart(endContainer, endOffset);
}
// Set the text after the user's selection to `source` so that it can be
// inserted into the new block being created.
var source = rangeCopy.toString();
var block = undefined;
if (endContainer === this.node || endOffset === 0) {
block = this.getBlockFromNode(endNode).clone();
} else {
block = new Block(this, { source: source });
}
rangeCopy.deleteContents();
// Delete the content selected by the user
range.deleteContents();
if (currentNode.textContent === "") {
currentNode.innerHTML = "<br>";
}
var idx = this.nodes.indexOf(currentNode) + 1;
this.blocks.splice(idx, 0, block);
this.insertBlock(block, this.blocks[idx - 1], nextElementSibling);
this.focusBlock(block, source);
// When not collapsed remove the end node since we're recreating it with its
// remaining contents.
if (!collapsed && startNode !== endNode) {
endNode.remove();
}
// Manually dispatch an `input` event since we called `preventDefault`.
this.node.dispatchEvent(new Event("input"));
},
writable: true,
enumerable: true,
configurable: true
},
toggleFolding: {
value: function toggleFolding() {
if (this.copying) {
return;
}
this.foldingNodes.forEach(function (node) {
return node.classList.remove("visible");
});
if (!this.isActive) {
return;
}
var range = window.getSelection().getRangeAt(0);
this.foldingNodes.forEach(function (node) {
if (range.intersectsNode(node)) {
node.classList.add("visible");
}
});
slice.call(this.currentNode.querySelectorAll(".md-pre")).forEach(function (node) {
return node.classList.add("visible");
});
this.eachSelectionNode((function maybeAddVisible(node, offset) {
var nextSibling = node.nextElementSibling;
if (nextSibling && nextSibling.classList.contains("md-has-folding") && offset === node.textContent.length) {
node = nextSibling;
}
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
if (!node.classList.contains("md-has-folding")) {
var parentEl = undefined;
var testNode = node;
while (parentEl = testNode.parentElement) {
testNode = parentEl;
if (parentEl.classList.contains("md-has-folding")) {
node = parentEl;
}
if (parentEl.classList.contains("Block")) {
break;
}
}
}
if (!node.classList.contains("md-has-folding")) {
return;
}
slice.call(node.querySelectorAll(".md-folding")).forEach(function (node) {
return node.classList.add("visible");
});
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
preventEmpty: {
value: function preventEmpty(e) {
if (!(window.getSelection().isCollapsed && e.keyCode === BACKSPACE)) {
return;
}
var currentNode = this.currentNode;
if (currentNode.textContent === "" && currentNode === this.nodes[0]) {
e.preventDefault();
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNode: {
value: function removeNode(node) {
if (!node.classList.contains("Block")) {
return;
}
var idx = this.blockNodes.indexOf(node);
if (idx !== -1 && !node.isMoving) {
this.blocks.splice(idx, 1);
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNodes: {
value: function removeNodes(nodes) {
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i];
if (node.nodeType !== ELEMENT_NODE || node.isMoving) {
continue;
}
if (node.classList.contains("Block")) {
this.removeNode(nodes[i]);
} else {
var children = node.querySelectorAll(".Block");
for (var _i2 = 0, _len2 = children.length; _i2 < _len2; _i2++) {
this.removeNode(children[_i2]);
}
}
}
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
this.innerHTML = "";
for (var i = 0, len = this.blocks.length; i < len; i++) {
this.blocks[i].appendTo(this.node);
}
},
writable: true,
enumerable: true,
configurable: true
},
splitBlock: {
value: function splitBlock(block, node) {
var blockOne = block.cloneNode();
// Cache, since we're removing some.
var children = slice.call(block.childNodes);
_loop: for (var i = 0, len = children.length; i < len; i++) {
var _ret = (function (i, len) {
var childNode = children[i];
if (childNode !== node) {
childNode.isMoving = true;
blockOne.appendChild(childNode);
setTimeout(function () {
return childNode.isMoving = false;
});
} else {
return "break";
}
})(i, len);
if (_ret === "break") break _loop;
}
if (blockOne.childNodes.length > 0) {
block.parentElement.insertBefore(blockOne, block);
}
return [blockOne, block];
},
writable: true,
enumerable: true,
configurable: true
},
startRenders: {
value: function startRenders() {
this.blocks.forEach(function (block) {
return block.render();
});
},
writable: true,
enumerable: true,
configurable: true
},
teardown: {
value: function teardown() {
document.removeEventListener("selectionchange", this.toggleFoldingFn);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Editor;
})();
module.exports = Editor;
},{"./block":3,"./curse":4}],6:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var types = _interopRequire(require("./types"));
var grammar = { blocks: [] };
for (var i = 1; i <= 6; i++) {
grammar.blocks.push(new types["H" + i]());
}
grammar.blocks.push(new types.OL());
grammar.blocks.push(new types.UL());
grammar.blocks.push(new types.Paragraph());
module.exports = grammar;
},{"./types":15}],7:[function(require,module,exports){
"use strict";
module.exports = {
PRE: -1
};
},{}],8:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H1 = (function (Heading) {
function H1() {
if (Object.getPrototypeOf(H1) !== null) {
Object.getPrototypeOf(H1).apply(this, arguments);
}
}
_inherits(H1, Heading);
_prototypeProperties(H1, null, {
level: {
get: function () {
return 1;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(# )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H1;
})(Heading);
module.exports = H1;
},{"./heading":14}],9:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H2 = (function (Heading) {
function H2() {
if (Object.getPrototypeOf(H2) !== null) {
Object.getPrototypeOf(H2).apply(this, arguments);
}
}
_inherits(H2, Heading);
_prototypeProperties(H2, null, {
level: {
get: function () {
return 2;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{2} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H2;
})(Heading);
module.exports = H2;
},{"./heading":14}],10:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H3 = (function (Heading) {
function H3() {
if (Object.getPrototypeOf(H3) !== null) {
Object.getPrototypeOf(H3).apply(this, arguments);
}
}
_inherits(H3, Heading);
_prototypeProperties(H3, null, {
level: {
get: function () {
return 3;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{3} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H3;
})(Heading);
module.exports = H3;
},{"./heading":14}],11:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H4 = (function (Heading) {
function H4() {
if (Object.getPrototypeOf(H4) !== null) {
Object.getPrototypeOf(H4).apply(this, arguments);
}
}
_inherits(H4, Heading);
_prototypeProperties(H4, null, {
level: {
get: function () {
return 4;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{4} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H4;
})(Heading);
module.exports = H4;
},{"./heading":14}],12:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H5 = (function (Heading) {
function H5() {
if (Object.getPrototypeOf(H5) !== null) {
Object.getPrototypeOf(H5).apply(this, arguments);
}
}
_inherits(H5, Heading);
_prototypeProperties(H5, null, {
level: {
get: function () {
return 5;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{5} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H5;
})(Heading);
module.exports = H5;
},{"./heading":14}],13:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H6 = (function (Heading) {
function H6() {
if (Object.getPrototypeOf(H6) !== null) {
Object.getPrototypeOf(H6).apply(this, arguments);
}
}
_inherits(H6, Heading);
_prototypeProperties(H6, null, {
level: {
get: function () {
return 6;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{6} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H6;
})(Heading);
module.exports = H6;
},{"./heading":14}],14:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./constants").PRE;
var Type = _interopRequire(require("./type"));
var Heading = (function (Type) {
function Heading() {
if (Object.getPrototypeOf(Heading) !== null) {
Object.getPrototypeOf(Heading).apply(this, arguments);
}
}
_inherits(Heading, Type);
_prototypeProperties(Heading, null, {
cssClass: {
get: function () {
return "h" + this.level;
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "H" + this.level;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return new RegExp("^(#{1,6} )(.*)$");
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Heading;
})(Type);
module.exports = Heading;
},{"./constants":7,"./type":20}],15:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var H1 = _interopRequire(require("./h1"));
var H2 = _interopRequire(require("./h2"));
var H3 = _interopRequire(require("./h3"));
var H4 = _interopRequire(require("./h4"));
var H5 = _interopRequire(require("./h5"));
var H6 = _interopRequire(require("./h6"));
var Null = _interopRequire(require("./null"));
var Paragraph = _interopRequire(require("./paragraph"));
var OL = _interopRequire(require("./ol"));
var UL = _interopRequire(require("./ul"));
module.exports = {
H1: H1,
H2: H2,
H3: H3,
H4: H4,
H5: H5,
H6: H6,
Null: Null,
Paragraph: Paragraph,
OL: OL,
UL: UL
};
},{"./h1":8,"./h2":9,"./h3":10,"./h4":11,"./h5":12,"./h6":13,"./null":17,"./ol":18,"./paragraph":19,"./ul":21}],16:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var PRE = require("./constants").PRE;
var List = (function (Type) {
function List() {
if (Object.getPrototypeOf(List) !== null) {
Object.getPrototypeOf(List).apply(this, arguments);
}
}
_inherits(List, Type);
_prototypeProperties(List, null, {
continues: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "li";
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "LI";
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
var listNode = undefined;
if (parent.lastChild && parent.lastChild.nodeName === this.parentNodeName) {
listNode = parent.lastChild;
} else {
listNode = this.createListNode();
}
listNode.appendChild(node);
parent.appendChild(listNode);
},
writable: true,
enumerable: true,
configurable: true
},
createListNode: {
value: function createListNode() {
var ul = document.createElement(this.parentNodeName.toLowerCase());
ul.classList.add("LineBreak");
return ul;
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
var listNode = undefined;
if (oldNode.previousElementSibling && oldNode.previousElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.previousElementSibling;
listNode.appendChild(node);
} else if (oldNode.nextElementSibling && oldNode.nextElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.nextElementSibling;
listNode.insertBefore(node, listNode.firstChild);
} else {
listNode = this.createListNode();
listNode.appendChild(node);
}
listNode.isMoving = true;
oldNode.parentElement.replaceChild(listNode, oldNode);
setTimeout(function () {
return listNode.isMoving = false;
});
},
writable: true,
enumerable: true,
configurable: true
}
});
return List;
})(Type);
module.exports = List;
},{"./constants":7,"./type":20}],17:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Null = (function (Type) {
function Null() {
if (Object.getPrototypeOf(Null) !== null) {
Object.getPrototypeOf(Null).apply(this, arguments);
}
}
_inherits(Null, Type);
_prototypeProperties(Null, null, {
isNull: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Null;
})(Type);
module.exports = Null;
},{"./type":20}],18:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var OL = (function (List) {
function OL() {
if (Object.getPrototypeOf(OL) !== null) {
Object.getPrototypeOf(OL).apply(this, arguments);
}
}
_inherits(OL, List);
_prototypeProperties(OL, null, {
cssClass: {
get: function () {
return "ol-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "OL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(\d+\. )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return OL;
})(List);
module.exports = OL;
},{"./list":16}],19:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Paragraph = (function (Type) {
function Paragraph() {
if (Object.getPrototypeOf(Paragraph) !== null) {
Object.getPrototypeOf(Paragraph).apply(this, arguments);
}
}
_inherits(Paragraph, Type);
_prototypeProperties(Paragraph, null, {
cssClass: {
get: function () {
return "p";
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "P";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(.*)$/;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Paragraph;
})(Type);
module.exports = Paragraph;
},{"./type":20}],20:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Type = (function () {
function Type() {}
_prototypeProperties(Type, null, {
continues: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "";
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isNull: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "DIV";
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
parent.appendChild(node);
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement(this.nodeName.toLowerCase());
node.className = "Block LineBreak";
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBefore: {
value: function insertBefore(node, next, parent) {
parent.insertBefore(node, next);
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
oldNode.parentElement.replaceChild(node, oldNode);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Type;
})();
module.exports = Type;
},{}],21:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var UL = (function (List) {
function UL() {
if (Object.getPrototypeOf(UL) !== null) {
Object.getPrototypeOf(UL).apply(this, arguments);
}
}
_inherits(UL, List);
_prototypeProperties(UL, null, {
cssClass: {
get: function () {
return "ul-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "UL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(- )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return UL;
})(List);
module.exports = UL;
},{"./list":16}]},{},[5])
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
"use strict";
!(function (e) {
if ("object" == typeof exports) module.exports = e();else if ("function" == typeof define && define.amd) define(e);else {
var f;"undefined" != typeof window ? f = window : "undefined" != typeof global ? f = global : "undefined" != typeof self && (f = self), f.Curse = e();
}
})(function () {
var define, module, exports;return (function e(t, n, r) {
var s = function (o, u) {
if (!n[o]) {
if (!t[o]) {
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);throw new Error("Cannot find module '" + o + "'");
}var f = n[o] = { exports: {} };t[o][0].call(f.exports, function (e) {
var n = t[o][1][e];return s(n ? n : e);
}, f, f.exports, e, t, n, r);
}return n[o].exports;
};
var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) s(r[o]);return s;
})({ 1: [function (_dereq_, module, exports) {
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
/**
* Captures and restores the cursor position inside of an HTML element. This
* is particularly useful for capturing, editing, and restoring selections
* in contenteditable elements, where the selection may span both text nodes
* and element nodes.
*
* var elem = document.querySelector('#editor');
* var curse = new Curse(elem);
* curse.capture();
*
* // ...
*
* curse.restore();
*
* @class Curse
* @constructor
* @param {HTMLElement} element an element to track the cursor inside of
*/
var Curse = (function () {
var Curse = function (element) {
var _ref = arguments[1] === undefined ? {} : arguments[1];
var lineBreak = _ref.lineBreak;
var nodeLengths = _ref.nodeLengths;
this.lineBreak = lineBreak;
this.nodeLengths = nodeLengths || {};
this.element = element;
this.reset();
};
_prototypeProperties(Curse, null, {
iterator: {
/**
* An iterator to iterate over the nodes in `this.element`.
*
* This returns a simple node iterator that skips `this.element`, but not its
* children.
*
* @property iterator
* @private
* @type {NodeIterator}
*/
get: function () {
var elem = this.element;
return document.createNodeIterator(this.element, NodeFilter.SHOW_ALL, function onNode(node) {
return node === elem ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
});
},
enumerable: true,
configurable: true
},
capture: {
/**
* Captures the current selection in the element, by storing "start" and
* "end" integer values. This allows for the text and text nodes to change
* inside the element and still have the Curse be able to restore selection
* state.
*
* A `<br>` tag, for example, is counted as a single "character", while
* a text node with the text "Hello, world" is counted as 12 characters.
*
* @method capture
*/
value: function capture() {
var _window$getSelection = window.getSelection();
var anchorNode = _window$getSelection.anchorNode;
var anchorOffset = _window$getSelection.anchorOffset;
var focusNode = _window$getSelection.focusNode;
var focusOffset = _window$getSelection.focusOffset;
var child = undefined,
start = undefined,
end = undefined;
if (anchorNode === null || focusNode === null) {
this.reset();
return;
}
if (anchorNode.nodeName === "#text") {
start = this.lengthUpTo(anchorNode) + anchorOffset;
} else {
child = anchorNode.childNodes[anchorOffset ? anchorOffset - 1 : 0];
start = this.lengthUpTo(child);
}
if (focusNode.nodeName === "#text") {
end = this.lengthUpTo(focusNode) + focusOffset;
} else {
child = focusNode.childNodes[focusOffset ? focusOffset - 1 : 0];
end = this.lengthUpTo(child) + this.nodeLength(child);
}
this.start = start;
this.end = end;
},
writable: true,
enumerable: true,
configurable: true
},
restore: {
/**
* Restore the captured cursor state by iterating over the child nodes in the
* element and counting their length.
*
* @method restore
* @param {Boolean} [onlyActive=true] only restore if the curse's element is
* the active element
*/
value: function restore() {
var onlyActive = arguments[0] === undefined ? true : arguments[0];
if (onlyActive && document.activeElement !== this.element) {
return;
}
if (!onlyActive) {
this.element.focus();
}
var range = document.createRange();
var idx = 0;
var _ref2 = this;
var start = _ref2.start;
var end = _ref2.end;
var iter = this.iterator;
var node = undefined,
setStart = undefined,
setEnd = undefined;
if (this.start > this.end) {
start = this.end;
end = this.start;
}
while (node = iter.nextNode()) {
if (setStart && setEnd) {
break;
}
var nodeLength = this.nodeLength(node);
var isText = node.nodeName === "#text";
var childIdx = undefined;
if (!setStart && start <= idx + nodeLength) {
if (isText) {
range.setStart(node, start - idx);
} else {
childIdx = this.indexOfNode(node);
range.setStart(node.parentNode, childIdx);
}
setStart = true;
}
if (!setEnd && end <= idx + nodeLength) {
if (isText) {
range.setEnd(node, end - idx);
} else {
childIdx = this.indexOfNode(node);
range.setEnd(node.parentNode, childIdx);
}
setEnd = true;
}
idx += nodeLength;
}
var selection = window.getSelection();
selection.removeAllRanges();
// Reverse the selection if it was originally backwards
if (this.start > this.end) {
var startContainer = range.startContainer;
var startOffset = range.startOffset;
range.collapse(false);
selection.addRange(range);
selection.extend(startContainer, startOffset);
} else {
selection.addRange(range);
}
},
writable: true,
enumerable: true,
configurable: true
},
indexOfNode: {
/**
* Get the index of a node in its parent node.
*
* @method indexOfNode
* @private
* @param {Node} child the child node to find the index of
* @returns {Number} the index of the child node
*/
value: function indexOfNode(child) {
var i = 0;
while (child = child.previousSibling) {
i++;
}
return i;
},
writable: true,
enumerable: true,
configurable: true
},
lengthUpTo: {
/**
* Get the number of characters up to a given node.
*
* @method lengthUpTo
* @private
* @param {Node} node a node to find the length up to
* @returns {Number} the length up to the given node
*/
value: function lengthUpTo(lastNode) {
var len = 0;
var iter = this.iterator;
var node = undefined;
while (node = iter.nextNode()) {
if (node === lastNode) {
break;
}
len += this.nodeLength(node);
}
return len;
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
/**
* Reset the state of the cursor.
*
* @method reset
* @private
*/
value: function reset() {
this.start = null;
this.end = null;
},
writable: true,
enumerable: true,
configurable: true
},
nodeLength: {
/**
* Get the "length" of a node. Text nodes are the length of their contents,
* and `<br>` tags, for example, have a length of 1 (a newline character,
* essentially).
*
* @method nodeLength
* @private
* @param {Node} node a Node, typically a Text or HTMLElement node
* @return {Number} the length of the node, as text
*/
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = undefined;
if (this.lineBreak) {
previousSibling = node.previousElementSibling;
}
if (previousSibling && previousSibling.classList.contains(this.lineBreak)) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return Curse;
})();
module.exports = Curse;
}, {}] }, {}, [1])(1);
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],2:[function(require,module,exports){
(function (global){
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.miniprism=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";
/*
* The syntax parsing algorithm in this file is copied heavily from Lea Verou's
* Prism project, which bears this license:
*
* MIT LICENSE
*
* Copyright (c) 2012-2013 Lea Verou
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var grammars = _dereq_("./grammars");
exports.grammars = grammars;
exports.highlight = function highlight(source, grammarName) {
var opts = arguments[2] === undefined ? {} : arguments[2];
var grammar = undefined;
if (typeof grammarName === "string") {
grammar = grammars[grammarName];
}
if (typeof grammarName === "object" && grammarName.constructor === Object) {
grammar = grammarName;
}
if (!grammar) {
throw new Error("Grammar \"" + grammarName + "\" not found.");
}
return stringify(encode(tokenize(source, grammar)), opts.lineClass);
};
function tokenize(source, grammar) {
var strings = [source];
var inlines = grammar.inlines;
if (inlines) {
// jshint -W089
for (var inlineToken in inlines) {
grammar[inlineToken] = inlines[inlineToken];
}
delete grammar.inlines;
}
for (var token in grammar) {
var patterns = grammar[token];
if (!Array.isArray(patterns)) {
patterns = [patterns];
}
for (var i = 0; i < patterns.length; i++) {
var pattern = patterns[i];
var block = pattern.block;
var classes = pattern.classes;
var inside = pattern.inside;
var lookbehind = !!pattern.lookbehind;
var lookbehindLength = 0;
var tag = undefined;
if (pattern.tag) {
tag = pattern.tag;
} else {
tag = block ? "div" : "span";
}
pattern = pattern.pattern || pattern;
for (var _i = 0; _i < strings.length; _i++) {
var string = strings[_i];
if (typeof string !== "string") {
continue;
}
pattern.lastIndex = 0;
var match = pattern.exec(string);
if (!match) {
continue;
}
if (lookbehind) {
lookbehindLength = match[1].length;
}
var from = match.index - 1 + lookbehindLength;
match = match[0].slice(lookbehindLength);
var len = match.length;
var to = from + len;
var before = string.slice(0, from + 1);
var after = string.slice(to + 1);
var args = [_i, 1];
if (before) {
args.push(before);
}
var wrapped = {
block: block,
classes: classes,
tag: tag,
text: inside ? tokenize(match, inside) : match,
token: token
};
args.push(wrapped);
if (after) {
args.push(after);
}
Array.prototype.splice.apply(strings, args);
}
}
}
return strings;
}
function stringify(source) {
var lineClass = arguments[1] === undefined ? "md-line" : arguments[1];
if (source === "\n") {
return "<br>";
}
if (typeof source === "string") {
return source.replace(/\n/g, "");
}
if (Array.isArray(source)) {
return source.reduce(function addItem(result, item) {
return result + stringify(item, lineClass);
}, "");
}
var tag = source.tag;
var classList = source.classes || source.token.split(" ");
var className = classList.map(function (token) {
return "md-" + token;
}).join(" ");
if (source.block) {
className += " " + lineClass;
}
return ["<" + tag + " class=\"" + className + "\">", stringify(source.text, lineClass), "</" + tag + ">"].join("");
}
function encode(src) {
if (Array.isArray(src)) {
return src.map(encode);
} else if (typeof src === "object") {
src.text = encode(src.text);
return src;
} else {
return escapeHTML(src);
}
}
function escapeHTML(str) {
return str.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/\//g, "&#x2F;");
}
},{"./grammars":2}],2:[function(_dereq_,module,exports){
"use strict";
exports.markdown = _dereq_("./markdown");
},{"./markdown":3}],3:[function(_dereq_,module,exports){
"use strict";
/*
* These regexes are in some places copies of, in others modifications of, and
* in some places wholly unrelated to the Markdown regexes found in the
* Stackedit project, which bears this license:
*
* StackEdit - The Markdown editor powered by PageDown.
* Copyright 2013 Benoit Schweblin (http://www.benoitschweblin.com)
* Licensed under an Apache License (http://www.apache.org/licenses/LICENSE-2.0)
*/
exports.gfm = {
block: true,
pattern: /^`{3}.*\n(?:[\s\S]*?)\n`{3} *(?:\n|$)/gm,
inside: {
"gfm-limit": {
block: true,
pattern: /^`{3}.*(?:\n|$)/gm,
inside: {
"gfm-info": {
lookbehind: true,
pattern: /^(`{3}).+(?:\n|$)/
},
"gfm-fence": /^`{3}(?:\n|$)/gm
}
},
"gfm-line": {
block: true,
pattern: /^.*(?:\n|$)/gm
} }
};
exports.blank = [{
block: true,
pattern: /\n(?![\s\S])/mg
}, {
block: true,
pattern: /^\n/mg
}];
exports["setex-h1"] = {
block: true,
pattern: /^.+\n=+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^=].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^=+[ \t]*(?:\n|$)/
}
}
};
exports["setex-h2"] = {
block: true,
pattern: /^(?!^- ).+\n-+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^-].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^-+[ \t]*(?:\n|$)/
}
}
};
exports.code = {
block: true,
pattern: /^(?: {4,}|\t).+(?:\n|$)/gm
};
// h1 through h6
for (var i = 1; i < 7; i++) {
exports["h" + i] = {
classes: ["h" + i, "has-folding"],
block: true,
pattern: new RegExp("^#{" + i + "} .*(?:\n|$)", "gm"),
inside: {
"hash folding": new RegExp("^#{" + i + "} ")
}
};
}
exports.ul = {
classes: ["ul", "has-folding"],
block: true,
pattern: /^[ \t]*(?:[*+\-])[ \t].*(?:\n|$)/gm,
inside: {
"ul-marker folding": /^[ \t]*(?:[*+\-])[ \t]/
}
};
exports.ol = {
block: true,
pattern: /^[ \t]*(?:\d+)\.[ \t].*(?:\n|$)/gm,
inside: {
"ol-marker": /^[ \t]*(?:\d+)\.[ \t]/
}
};
exports.blockquote = {
block: true,
pattern: /^ {0,3}> *.*(?:\n|$)/gm,
inside: {
"blockquote-marker": /^ {0,3}> */
}
};
exports.hr = {
block: true,
pattern: /^(?:[*\-_] *){3,}(?:\n|$)/gm
};
exports["link-def"] = {
block: true,
pattern: /^ {0,3}\[.*?\]:[ \t]+.+(?:\n|$)/gm,
inside: {
"link-def-name": {
pattern: /^ {0,3}\[.*?\]:/,
inside: {
"bracket-start": /^\[/,
"bracket-end": /\](?=:$)/,
colon: /:$/
}
},
"link-def-value": /.*(?:\n|$)/
}
};
exports.p = {
block: true,
pattern: /^.+(?:\n|$)/gm,
inside: {}
};
// jshint -W101
exports.link = {
classes: ["link", "has-folding"],
pattern: /\[(?:(?:\\.)|[^\[\]])*\]\([^\(\)\s]+(?:\(\S*?\))??[^\(\)\s]*?(?:\s(?:['‘][^'’]*['’]|["“][^"”]*["”]))?\)/gm,
inside: {
"bracket-start folding": {
pattern: /(^|[^\\])\[/,
lookbehind: true
},
ref: /(?:(?:\\.)|[^\[\]])+(?=\])/,
"bracket-end folding": /\](?=\s?\()/,
"paren-start folding": /^\(/,
"paren-end folding": /\)$/,
"href folding": /.*/
}
};
// jshint +W101
exports["link-ref"] = {
classes: ["link-ref", "has-folding"],
pattern: /\[(?:.*?)\] ?\[(?:.*?)\]/g,
inside: {
"ref-value folding": {
pattern: /\[[^\[\]]+\]$/,
inside: {
"bracket-start": /\[/,
"ref-href": /[^\[\]]+(?=]$)/,
"bracket-end": /\]/
}
},
"ref-text": {
pattern: /^\[[^\[\]]+\]/,
inside: {
"bracket-start folding": /^\[/,
ref: /^[^\[\]]+/,
"bracket-end folding": /\]$/
}
}
}
};
exports.em = {
classes: ["em", "has-folding"],
pattern: /(^|[^\\])(\*|_)(\S[^\2]*?)??[^\s\\]+?\2/g,
lookbehind: true,
inside: {
"em-marker folding": /(?:^(?:\*|_))|(?:(?:\*|_)$)/
}
};
exports.strong = {
classes: ["strong", "has-folding"],
pattern: /([_\*]){2}(?:(?!\1{2}).)*\1{2}/g,
inside: {
"strong-marker folding": /(?:^(?:\*|_){2})|(?:(?:\*|_){2}$)/
}
};
exports["inline-code"] = {
classes: ["inline-code", "has-folding"],
pattern: /(^|[^\\])`(\S[^`]*?)??[^\s\\]+?`/g,
lookbehind: true,
inside: {
"inline-code-marker folding": /(?:^(?:`))|(?:(?:`)$)/
}
};
var inlines = {
strong: exports.strong,
em: exports.em,
link: exports.link,
"inline-code": exports["inline-code"],
"link-ref": exports["link-ref"]
};
["setex-h1", "setex-h2", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "blockquote", "p"].forEach(function (token) {
exports[token].inside.inlines = inlines;
});
["em", "strong"].forEach(function (token) {
exports[token].inside = exports[token].inside || {};
exports[token].inside.inlines = {
link: exports.link,
"link-ref": exports["link-ref"]
};
});
},{}]},{},[1])
(1)
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./types/constants").PRE;
var blocks = require("./grammar").blocks;
var Null = require("./types").Null;
var OL = require("./types").OL;
var miniprism = _interopRequire(require("miniprism"));
// Standard inlines:
var inlines = miniprism.grammars.markdown.p.inside.inlines;
var slice = Array.prototype.slice;
var Block = (function () {
function Block(editor, _ref) {
var node = _ref.node;
var pre = _ref.pre;
var source = _ref.source;
var type = _ref.type;
this.editor = editor;
this.type = type || new Null();
this.pre = pre || "";
this.content = source;
this.node = node || this.type.createNode();
this.render(true); // (isFirstRender)
}
_prototypeProperties(Block, null, {
source: {
get: function () {
if (this.type.constructor === OL) {
var children = this.node.parentElement ? slice.call(this.node.parentElement.childNodes) : [];
var digit = children.indexOf(this.node) + 1;
return "" + digit + ". " + this._content;
} else {
return this.pre + this._content;
}
},
enumerable: true,
configurable: true
},
content: {
get: function () {
if (this.type.isHeading) {
return "" + this.pre + "" + this._content;
} else {
return this._content;
}
},
set: function (content) {
this._content = content;
var match = undefined,
type = undefined;
if (this.type.isHeading && !content) {
this.type = new Null();
this.pre = "";
}
if (!this.type.shouldReparse) {
return;
}
// jshint -W089
for (var i = 0, len = blocks.length; i < len; i++) {
type = blocks[i];
if (match = content.match(type.pattern)) {
break;
}
}
this.type = type;
this._content = "";
match = match.slice(1);
var labels = type.labels;
for (var i = 0, len = match.length; i < len; i++) {
if (labels[i] === PRE) {
this.pre = match[i];
} else {
this._content += match[i];
}
}
},
enumerable: true,
configurable: true
},
html: {
get: function () {
if (this.type.isHeading) {
return "<span class=\"md-pre\">" + esc(this.pre) + "</span>" + ("" + miniprism.highlight(this._content, inlines));
} else {
return miniprism.highlight(this._content, inlines);
}
},
enumerable: true,
configurable: true
},
shouldContinue: {
get: function () {
return this.type.continues && this.content;
},
enumerable: true,
configurable: true
},
type: {
get: function () {
return this._type;
},
set: function (type) {
this.adjustedPre = false;
this.pre = "";
return this._type = type;
},
enumerable: true,
configurable: true
},
appendTo: {
value: function appendTo(node) {
this.type.appendChild(this.node, node);
},
writable: true,
enumerable: true,
configurable: true
},
clone: {
value: function clone() {
return new this.constructor(this.editor, {
node: this.node.cloneNode(true),
pre: this.pre,
source: this.content,
type: this.type
});
},
writable: true,
enumerable: true,
configurable: true
},
continueFrom: {
value: function continueFrom(block) {
this.type = block.type;
this.pre = block.pre;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
var isFirstRender = arguments[0] === undefined ? false : arguments[0];
if (this.content === this.node.textContent && !isFirstRender) {
return;
}
var oldNode = this.node;
var oldType = this.type;
if (!isFirstRender) {
this.content = this.node.textContent;
}
this.editor.curse.capture();
if (oldType !== this.type) {
this.node = this.type.createNode();
this.type.replaceNode(this.node, oldNode);
}
/*
* Adjust the Curse for `pre` since it is about to be removed from the
* DOM during `#render`. This does not apply to reparsing types, as their
* `pre` is still displayed when focused.
*/
if (!this.adjustedPre && !this.type.shouldReparse) {
this.editor.curse.start -= this.pre.length;
this.editor.curse.end -= this.pre.length;
this.adjustedPre = true;
}
if (this.content) {
this.node.innerHTML = this.html;
} else {
this.node.innerHTML = "<br>";
}
this.editor.curse.restore();
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
value: function reset() {
this.type = new Null();
this.content = this.content;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
selectionSubstring: {
value: function selectionSubstring(sel) {
var anchorNode = sel.anchorNode;
var focusNode = sel.focusNode;
var anchorOffset = sel.anchorOffset;
var focusOffset = sel.focusOffset;
var start = 0;
var end = Infinity;
var curse = this.editor.curse;
if (this.node.contains(anchorNode)) {
start = curse.lengthUpTo(anchorNode) - curse.lengthUpTo(this.node.firstChild) + anchorOffset;
if (this.type.isList) {
start += this.pre.length;
}
}
if (this.node.contains(focusNode)) {
end = curse.lengthUpTo(focusNode) - curse.lengthUpTo(this.node.firstChild) + focusOffset;
if (this.type.isList) {
end += this.pre.length;
}
}
return this.source.substring(start, end);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Block;
})();
module.exports = Block;
function esc(text) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(text));
return div.innerHTML;
}
},{"./grammar":6,"./types":15,"./types/constants":7,"miniprism":2}],4:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Curse = _interopRequire(require("../bower_components/curse/dist/curse"));
var _Curse = (function (Curse) {
function _Curse() {
if (Object.getPrototypeOf(_Curse) !== null) {
Object.getPrototypeOf(_Curse).apply(this, arguments);
}
}
_inherits(_Curse, Curse);
_prototypeProperties(_Curse, null, {
nodeLength: {
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = node.previousElementSibling;
if (previousSibling && previousSibling.classList.contains("LineBreak")) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return _Curse;
})(Curse);
module.exports = _Curse;
},{"../bower_components/curse/dist/curse":1}],5:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Block = _interopRequire(require("./block"));
var Curse = _interopRequire(require("./curse"));
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var BACKSPACE = 8;
var RETURN = 13;
var slice = Array.prototype.slice;
var Editor = (function () {
function Editor() {
var source = arguments[0] === undefined ? "" : arguments[0];
this.blocks = [];
this.node = this.createNode();
this.curse = new Curse(this.node, {
nodeLengths: { BR: 0 }
});
this.source = source;
this.bindEvents();
this.observeMutations();
}
_prototypeProperties(Editor, null, {
anchorNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentAnchor);
},
enumerable: true,
configurable: true
},
focusNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentFocus);
},
enumerable: true,
configurable: true
},
blockNodes: {
get: function () {
return this.blocks.map(function (block) {
return block.node;
});
},
enumerable: true,
configurable: true
},
currentAnchor: {
get: function () {
return this.getNode(window.getSelection().anchorNode);
},
enumerable: true,
configurable: true
},
currentBlock: {
get: function () {
return this.getBlockFromNode(this.currentNode);
},
enumerable: true,
configurable: true
},
currentFocus: {
get: function () {
return this.getNode(window.getSelection().focusNode);
},
enumerable: true,
configurable: true
},
currentNode: {
get: function () {
if (!this.isActive) {
return null;
}
if (this.isReversed) {
return this.currentFocus;
} else {
return this.currentAnchor;
}
},
enumerable: true,
configurable: true
},
foldingNodes: {
get: function () {
return slice.call(this.node.querySelectorAll(".md-folding, .md-pre"));
},
enumerable: true,
configurable: true
},
isActive: {
get: function () {
return document.activeElement === this.node;
},
enumerable: true,
configurable: true
},
isReversed: {
get: function () {
var _ref = this;
var currentAnchor = _ref.currentAnchor;
var currentFocus = _ref.currentFocus;
var nodes = _ref.nodes;
return nodes.indexOf(currentAnchor) > nodes.indexOf(currentFocus);
},
enumerable: true,
configurable: true
},
nodes: {
get: function () {
var nodeList = this.node.querySelectorAll(".Block");
return slice.call(nodeList);
},
enumerable: true,
configurable: true
},
toggleFoldingFn: {
get: function () {
if (this._toggleFoldingFn) {
return this._toggleFoldingFn;
}
return this._toggleFoldingFn = this.toggleFolding.bind(this);
},
enumerable: true,
configurable: true
},
source: {
get: function () {
return this.blocks.map(function (block) {
return block.source;
}).join("\n");
},
set: function (source) {
var _this = this;
this.blocks = source.split(/\n/).map(function (line) {
return new Block(_this, { source: line });
});
this.render();
},
enumerable: true,
configurable: true
},
bindEvents: {
value: function bindEvents() {
document.addEventListener("selectionchange", this.toggleFoldingFn);
this.node.addEventListener("input", this.startRenders.bind(this));
this.node.addEventListener("input", this.toggleFoldingFn);
this.node.addEventListener("keydown", this.onReturn.bind(this));
this.node.addEventListener("keydown", this.preventEmpty.bind(this));
this.node.addEventListener("copy", this.onCopy.bind(this));
this.node.addEventListener("cut", this.onCopy.bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement("div");
node.classList.add("Editor");
node.setAttribute("contenteditable", true);
return node;
},
writable: true,
enumerable: true,
configurable: true
},
eachSelectionNode: {
value: function eachSelectionNode(fn) {
var sel = window.getSelection();
var pointTypes = sel.isCollapsed ? ["anchor"] : ["anchor", "focus"];
for (var i = 0, len = pointTypes.length; i < len; i++) {
var pointType = pointTypes[i];
var node = sel["" + pointType + "Node"];
var offset = sel["" + pointType + "Offset"];
fn(node, offset, sel);
}
},
writable: true,
enumerable: true,
configurable: true
},
focusBlock: {
value: function focusBlock(block, hasContent) {
var range = document.createRange();
var sel = window.getSelection();
var pos = hasContent ? 0 : block.node.childNodes.length;
range.setStart(block.node, pos);
range.setEnd(block.node, pos);
sel.removeAllRanges();
sel.addRange(range);
},
writable: true,
enumerable: true,
configurable: true
},
getBlockFromNode: {
value: function getBlockFromNode(node) {
return this.blocks[this.nodes.indexOf(node)];
},
writable: true,
enumerable: true,
configurable: true
},
getNode: {
value: function getNode(node) {
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
while (!node.classList.contains("Block")) {
node = node.parentElement;
}
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBlock: {
value: function insertBlock(block, prevBlock, nextElementSibling) {
var parentNode = this.node;
var prevNode = prevBlock.node;
var prevParent = prevNode.parentElement;
if (prevBlock.shouldContinue) {
parentNode = prevParent;
block.continueFrom(prevBlock);
} else if (prevBlock.type.continues) {
block.reset();
block.content = block.content;
this.splitBlock(prevParent, prevNode);
prevNode.remove();
if (prevParent.childNodes.length === 0) {
nextElementSibling = prevParent.nextElementSibling;
prevParent.remove();
} else {
nextElementSibling = prevParent;
}
}
block.type.insertBefore(block.node, nextElementSibling, parentNode);
},
writable: true,
enumerable: true,
configurable: true
},
observeMutations: {
value: function observeMutations() {
new MutationObserver(this.onMutation.bind(this)).observe(this.node, { childList: true, subtree: true });
},
writable: true,
enumerable: true,
configurable: true
},
onMutation: {
value: function onMutation(mutationRecords) {
for (var i = 0, len = mutationRecords.length; i < len; i++) {
var mut = mutationRecords[i];
for (var _i = 0, _len = mut.removedNodes.length; _i < _len; _i++) {
this.removeNodes(mut.removedNodes);
}
}
},
writable: true,
enumerable: true,
configurable: true
},
onCopy: {
value: function onCopy(e) {
this.copying = true;
var sel = window.getSelection();
var range = sel.getRangeAt(0);
var copyBin = document.createElement("pre");
var text = "";
var anc = this.anchorNodeBlock;
var foc = this.focusNodeBlock;
var nodes = this.nodes;
text += anc.selectionSubstring(sel) + "\n";
var started = undefined;
for (var i = 0, len = nodes.length; i < len; i++) {
if (foc.node === nodes[i]) {
break;
}
if (anc.node === nodes[i]) {
started = true;
continue;
}
if (started) {
text += this.getBlockFromNode(nodes[i]).source + "\n";
}
}
if (anc !== foc) {
text += foc.selectionSubstring(sel);
}
copyBin.classList.add("CopyBin");
copyBin.textContent = text;
this.node.appendChild(copyBin);
var newRange = document.createRange();
newRange.selectNodeContents(copyBin);
sel.removeAllRanges();
sel.addRange(newRange);
setTimeout((function () {
copyBin.remove();
sel.removeAllRanges();
sel.addRange(range);
this.copying = false;
if (e.type === "cut") {
document.execCommand("insertText", null, "");
}
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
onReturn: {
value: function onReturn(e) {
if (e.keyCode !== RETURN) {
return;
}
e.preventDefault();
var _ref2 = this;
var currentAnchor = _ref2.currentAnchor;
var currentFocus = _ref2.currentFocus;
var currentNode = _ref2.currentNode;
var isReversed = _ref2.isReversed;
var startNode = isReversed ? currentFocus : currentAnchor;
var endNode = isReversed ? currentAnchor : currentFocus;
var nextElementSibling = endNode.nextElementSibling;
var range = window.getSelection().getRangeAt(0);
var collapsed = range.collapsed;
var startContainer = range.startContainer;
var endContainer = range.endContainer;
var startOffset = range.startOffset;
var endOffset = range.endOffset;
// In a copy of the range, select the entire end node of the selection
var rangeCopy = range.cloneRange();
rangeCopy.selectNodeContents(endNode);
// In the range copy, select only the text in the current node *after* the
// user's current selection.
if (range.collapsed) {
rangeCopy.setStart(startContainer, startOffset);
} else {
rangeCopy.setStart(endContainer, endOffset);
}
// Set the text after the user's selection to `source` so that it can be
// inserted into the new block being created.
var source = rangeCopy.toString();
var block = undefined;
if (endContainer === this.node || endOffset === 0) {
block = this.getBlockFromNode(endNode).clone();
} else {
block = new Block(this, { source: source });
}
rangeCopy.deleteContents();
// Delete the content selected by the user
range.deleteContents();
if (currentNode.textContent === "") {
currentNode.innerHTML = "<br>";
}
var idx = this.nodes.indexOf(currentNode) + 1;
this.blocks.splice(idx, 0, block);
this.insertBlock(block, this.blocks[idx - 1], nextElementSibling);
this.focusBlock(block, source);
// When not collapsed remove the end node since we're recreating it with its
// remaining contents.
if (!collapsed && startNode !== endNode) {
endNode.remove();
}
// Manually dispatch an `input` event since we called `preventDefault`.
this.node.dispatchEvent(new Event("input"));
},
writable: true,
enumerable: true,
configurable: true
},
toggleFolding: {
value: function toggleFolding() {
if (this.copying) {
return;
}
this.foldingNodes.forEach(function (node) {
return node.classList.remove("visible");
});
if (!this.isActive) {
return;
}
var range = window.getSelection().getRangeAt(0);
this.foldingNodes.forEach(function (node) {
if (range.intersectsNode(node)) {
node.classList.add("visible");
}
});
slice.call(this.currentNode.querySelectorAll(".md-pre")).forEach(function (node) {
return node.classList.add("visible");
});
this.eachSelectionNode((function maybeAddVisible(node, offset) {
var nextSibling = node.nextElementSibling;
if (nextSibling && nextSibling.classList.contains("md-has-folding") && offset === node.textContent.length) {
node = nextSibling;
}
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
if (!node.classList.contains("md-has-folding")) {
var parentEl = undefined;
var testNode = node;
while (parentEl = testNode.parentElement) {
testNode = parentEl;
if (parentEl.classList.contains("md-has-folding")) {
node = parentEl;
}
if (parentEl.classList.contains("Block")) {
break;
}
}
}
if (!node.classList.contains("md-has-folding")) {
return;
}
slice.call(node.querySelectorAll(".md-folding")).forEach(function (node) {
return node.classList.add("visible");
});
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
preventEmpty: {
value: function preventEmpty(e) {
if (!(window.getSelection().isCollapsed && e.keyCode === BACKSPACE)) {
return;
}
var currentNode = this.currentNode;
if (currentNode.textContent === "" && currentNode === this.nodes[0]) {
e.preventDefault();
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNode: {
value: function removeNode(node) {
if (!node.classList.contains("Block")) {
return;
}
var idx = this.blockNodes.indexOf(node);
if (idx !== -1 && !node.isMoving) {
this.blocks.splice(idx, 1);
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNodes: {
value: function removeNodes(nodes) {
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i];
if (node.nodeType !== ELEMENT_NODE || node.isMoving) {
continue;
}
if (node.classList.contains("Block")) {
this.removeNode(nodes[i]);
} else {
var children = node.querySelectorAll(".Block");
for (var _i2 = 0, _len2 = children.length; _i2 < _len2; _i2++) {
this.removeNode(children[_i2]);
}
}
}
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
this.innerHTML = "";
for (var i = 0, len = this.blocks.length; i < len; i++) {
this.blocks[i].appendTo(this.node);
}
},
writable: true,
enumerable: true,
configurable: true
},
splitBlock: {
value: function splitBlock(block, node) {
var blockOne = block.cloneNode();
// Cache, since we're removing some.
var children = slice.call(block.childNodes);
_loop: for (var i = 0, len = children.length; i < len; i++) {
var _ret = (function (i, len) {
var childNode = children[i];
if (childNode !== node) {
childNode.isMoving = true;
blockOne.appendChild(childNode);
setTimeout(function () {
return childNode.isMoving = false;
});
} else {
return "break";
}
})(i, len);
if (_ret === "break") break _loop;
}
if (blockOne.childNodes.length > 0) {
block.parentElement.insertBefore(blockOne, block);
}
return [blockOne, block];
},
writable: true,
enumerable: true,
configurable: true
},
startRenders: {
value: function startRenders() {
this.blocks.forEach(function (block) {
return block.render();
});
},
writable: true,
enumerable: true,
configurable: true
},
teardown: {
value: function teardown() {
document.removeEventListener("selectionchange", this.toggleFoldingFn);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Editor;
})();
module.exports = Editor;
},{"./block":3,"./curse":4}],6:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var types = _interopRequire(require("./types"));
var grammar = { blocks: [] };
for (var i = 1; i <= 6; i++) {
grammar.blocks.push(new types["H" + i]());
}
grammar.blocks.push(new types.OL());
grammar.blocks.push(new types.UL());
grammar.blocks.push(new types.Paragraph());
module.exports = grammar;
},{"./types":15}],7:[function(require,module,exports){
"use strict";
module.exports = {
PRE: -1
};
},{}],8:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H1 = (function (Heading) {
function H1() {
if (Object.getPrototypeOf(H1) !== null) {
Object.getPrototypeOf(H1).apply(this, arguments);
}
}
_inherits(H1, Heading);
_prototypeProperties(H1, null, {
level: {
get: function () {
return 1;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(# )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H1;
})(Heading);
module.exports = H1;
},{"./heading":14}],9:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H2 = (function (Heading) {
function H2() {
if (Object.getPrototypeOf(H2) !== null) {
Object.getPrototypeOf(H2).apply(this, arguments);
}
}
_inherits(H2, Heading);
_prototypeProperties(H2, null, {
level: {
get: function () {
return 2;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{2} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H2;
})(Heading);
module.exports = H2;
},{"./heading":14}],10:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H3 = (function (Heading) {
function H3() {
if (Object.getPrototypeOf(H3) !== null) {
Object.getPrototypeOf(H3).apply(this, arguments);
}
}
_inherits(H3, Heading);
_prototypeProperties(H3, null, {
level: {
get: function () {
return 3;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{3} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H3;
})(Heading);
module.exports = H3;
},{"./heading":14}],11:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H4 = (function (Heading) {
function H4() {
if (Object.getPrototypeOf(H4) !== null) {
Object.getPrototypeOf(H4).apply(this, arguments);
}
}
_inherits(H4, Heading);
_prototypeProperties(H4, null, {
level: {
get: function () {
return 4;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{4} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H4;
})(Heading);
module.exports = H4;
},{"./heading":14}],12:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H5 = (function (Heading) {
function H5() {
if (Object.getPrototypeOf(H5) !== null) {
Object.getPrototypeOf(H5).apply(this, arguments);
}
}
_inherits(H5, Heading);
_prototypeProperties(H5, null, {
level: {
get: function () {
return 5;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{5} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H5;
})(Heading);
module.exports = H5;
},{"./heading":14}],13:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H6 = (function (Heading) {
function H6() {
if (Object.getPrototypeOf(H6) !== null) {
Object.getPrototypeOf(H6).apply(this, arguments);
}
}
_inherits(H6, Heading);
_prototypeProperties(H6, null, {
level: {
get: function () {
return 6;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{6} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H6;
})(Heading);
module.exports = H6;
},{"./heading":14}],14:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./constants").PRE;
var Type = _interopRequire(require("./type"));
var Heading = (function (Type) {
function Heading() {
if (Object.getPrototypeOf(Heading) !== null) {
Object.getPrototypeOf(Heading).apply(this, arguments);
}
}
_inherits(Heading, Type);
_prototypeProperties(Heading, null, {
cssClass: {
get: function () {
return "h" + this.level;
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "H" + this.level;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return new RegExp("^(#{1,6} )(.*)$");
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Heading;
})(Type);
module.exports = Heading;
},{"./constants":7,"./type":20}],15:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var H1 = _interopRequire(require("./h1"));
var H2 = _interopRequire(require("./h2"));
var H3 = _interopRequire(require("./h3"));
var H4 = _interopRequire(require("./h4"));
var H5 = _interopRequire(require("./h5"));
var H6 = _interopRequire(require("./h6"));
var Null = _interopRequire(require("./null"));
var Paragraph = _interopRequire(require("./paragraph"));
var OL = _interopRequire(require("./ol"));
var UL = _interopRequire(require("./ul"));
module.exports = {
H1: H1,
H2: H2,
H3: H3,
H4: H4,
H5: H5,
H6: H6,
Null: Null,
Paragraph: Paragraph,
OL: OL,
UL: UL
};
},{"./h1":8,"./h2":9,"./h3":10,"./h4":11,"./h5":12,"./h6":13,"./null":17,"./ol":18,"./paragraph":19,"./ul":21}],16:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var PRE = require("./constants").PRE;
var List = (function (Type) {
function List() {
if (Object.getPrototypeOf(List) !== null) {
Object.getPrototypeOf(List).apply(this, arguments);
}
}
_inherits(List, Type);
_prototypeProperties(List, null, {
continues: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "li";
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "LI";
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
var listNode = undefined;
if (parent.lastChild && parent.lastChild.nodeName === this.parentNodeName) {
listNode = parent.lastChild;
} else {
listNode = this.createListNode();
}
listNode.appendChild(node);
parent.appendChild(listNode);
},
writable: true,
enumerable: true,
configurable: true
},
createListNode: {
value: function createListNode() {
var ul = document.createElement(this.parentNodeName.toLowerCase());
ul.classList.add("LineBreak");
return ul;
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
var listNode = undefined;
if (oldNode.previousElementSibling && oldNode.previousElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.previousElementSibling;
listNode.appendChild(node);
} else if (oldNode.nextElementSibling && oldNode.nextElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.nextElementSibling;
listNode.insertBefore(node, listNode.firstChild);
} else {
listNode = this.createListNode();
listNode.appendChild(node);
}
listNode.isMoving = true;
oldNode.parentElement.replaceChild(listNode, oldNode);
setTimeout(function () {
return listNode.isMoving = false;
});
},
writable: true,
enumerable: true,
configurable: true
}
});
return List;
})(Type);
module.exports = List;
},{"./constants":7,"./type":20}],17:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Null = (function (Type) {
function Null() {
if (Object.getPrototypeOf(Null) !== null) {
Object.getPrototypeOf(Null).apply(this, arguments);
}
}
_inherits(Null, Type);
_prototypeProperties(Null, null, {
isNull: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Null;
})(Type);
module.exports = Null;
},{"./type":20}],18:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var OL = (function (List) {
function OL() {
if (Object.getPrototypeOf(OL) !== null) {
Object.getPrototypeOf(OL).apply(this, arguments);
}
}
_inherits(OL, List);
_prototypeProperties(OL, null, {
cssClass: {
get: function () {
return "ol-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "OL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(\d+\. )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return OL;
})(List);
module.exports = OL;
},{"./list":16}],19:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Paragraph = (function (Type) {
function Paragraph() {
if (Object.getPrototypeOf(Paragraph) !== null) {
Object.getPrototypeOf(Paragraph).apply(this, arguments);
}
}
_inherits(Paragraph, Type);
_prototypeProperties(Paragraph, null, {
cssClass: {
get: function () {
return "p";
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "P";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(.*)$/;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Paragraph;
})(Type);
module.exports = Paragraph;
},{"./type":20}],20:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Type = (function () {
function Type() {}
_prototypeProperties(Type, null, {
continues: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "";
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isNull: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "DIV";
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
parent.appendChild(node);
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement(this.nodeName.toLowerCase());
node.className = "Block LineBreak";
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBefore: {
value: function insertBefore(node, next, parent) {
parent.insertBefore(node, next);
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
oldNode.parentElement.replaceChild(node, oldNode);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Type;
})();
module.exports = Type;
},{}],21:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var UL = (function (List) {
function UL() {
if (Object.getPrototypeOf(UL) !== null) {
Object.getPrototypeOf(UL).apply(this, arguments);
}
}
_inherits(UL, List);
_prototypeProperties(UL, null, {
cssClass: {
get: function () {
return "ul-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "UL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(- )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return UL;
})(List);
module.exports = UL;
},{"./list":16}]},{},[5])
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
"use strict";
!(function (e) {
if ("object" == typeof exports) module.exports = e();else if ("function" == typeof define && define.amd) define(e);else {
var f;"undefined" != typeof window ? f = window : "undefined" != typeof global ? f = global : "undefined" != typeof self && (f = self), f.Curse = e();
}
})(function () {
var define, module, exports;return (function e(t, n, r) {
var s = function (o, u) {
if (!n[o]) {
if (!t[o]) {
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);throw new Error("Cannot find module '" + o + "'");
}var f = n[o] = { exports: {} };t[o][0].call(f.exports, function (e) {
var n = t[o][1][e];return s(n ? n : e);
}, f, f.exports, e, t, n, r);
}return n[o].exports;
};
var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) s(r[o]);return s;
})({ 1: [function (_dereq_, module, exports) {
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
/**
* Captures and restores the cursor position inside of an HTML element. This
* is particularly useful for capturing, editing, and restoring selections
* in contenteditable elements, where the selection may span both text nodes
* and element nodes.
*
* var elem = document.querySelector('#editor');
* var curse = new Curse(elem);
* curse.capture();
*
* // ...
*
* curse.restore();
*
* @class Curse
* @constructor
* @param {HTMLElement} element an element to track the cursor inside of
*/
var Curse = (function () {
var Curse = function (element) {
var _ref = arguments[1] === undefined ? {} : arguments[1];
var lineBreak = _ref.lineBreak;
var nodeLengths = _ref.nodeLengths;
this.lineBreak = lineBreak;
this.nodeLengths = nodeLengths || {};
this.element = element;
this.reset();
};
_prototypeProperties(Curse, null, {
iterator: {
/**
* An iterator to iterate over the nodes in `this.element`.
*
* This returns a simple node iterator that skips `this.element`, but not its
* children.
*
* @property iterator
* @private
* @type {NodeIterator}
*/
get: function () {
var elem = this.element;
return document.createNodeIterator(this.element, NodeFilter.SHOW_ALL, function onNode(node) {
return node === elem ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
});
},
enumerable: true,
configurable: true
},
capture: {
/**
* Captures the current selection in the element, by storing "start" and
* "end" integer values. This allows for the text and text nodes to change
* inside the element and still have the Curse be able to restore selection
* state.
*
* A `<br>` tag, for example, is counted as a single "character", while
* a text node with the text "Hello, world" is counted as 12 characters.
*
* @method capture
*/
value: function capture() {
var _window$getSelection = window.getSelection();
var anchorNode = _window$getSelection.anchorNode;
var anchorOffset = _window$getSelection.anchorOffset;
var focusNode = _window$getSelection.focusNode;
var focusOffset = _window$getSelection.focusOffset;
var child = undefined,
start = undefined,
end = undefined;
if (anchorNode === null || focusNode === null) {
this.reset();
return;
}
if (anchorNode.nodeName === "#text") {
start = this.lengthUpTo(anchorNode) + anchorOffset;
} else {
child = anchorNode.childNodes[anchorOffset ? anchorOffset - 1 : 0];
start = this.lengthUpTo(child);
}
if (focusNode.nodeName === "#text") {
end = this.lengthUpTo(focusNode) + focusOffset;
} else {
child = focusNode.childNodes[focusOffset ? focusOffset - 1 : 0];
end = this.lengthUpTo(child) + this.nodeLength(child);
}
this.start = start;
this.end = end;
},
writable: true,
enumerable: true,
configurable: true
},
restore: {
/**
* Restore the captured cursor state by iterating over the child nodes in the
* element and counting their length.
*
* @method restore
* @param {Boolean} [onlyActive=true] only restore if the curse's element is
* the active element
*/
value: function restore() {
var onlyActive = arguments[0] === undefined ? true : arguments[0];
if (onlyActive && document.activeElement !== this.element) {
return;
}
if (!onlyActive) {
this.element.focus();
}
var range = document.createRange();
var idx = 0;
var _ref2 = this;
var start = _ref2.start;
var end = _ref2.end;
var iter = this.iterator;
var node = undefined,
setStart = undefined,
setEnd = undefined;
if (this.start > this.end) {
start = this.end;
end = this.start;
}
while (node = iter.nextNode()) {
if (setStart && setEnd) {
break;
}
var nodeLength = this.nodeLength(node);
var isText = node.nodeName === "#text";
var childIdx = undefined;
if (!setStart && start <= idx + nodeLength) {
if (isText) {
range.setStart(node, start - idx);
} else {
childIdx = this.indexOfNode(node);
range.setStart(node.parentNode, childIdx);
}
setStart = true;
}
if (!setEnd && end <= idx + nodeLength) {
if (isText) {
range.setEnd(node, end - idx);
} else {
childIdx = this.indexOfNode(node);
range.setEnd(node.parentNode, childIdx);
}
setEnd = true;
}
idx += nodeLength;
}
var selection = window.getSelection();
selection.removeAllRanges();
// Reverse the selection if it was originally backwards
if (this.start > this.end) {
var startContainer = range.startContainer;
var startOffset = range.startOffset;
range.collapse(false);
selection.addRange(range);
selection.extend(startContainer, startOffset);
} else {
selection.addRange(range);
}
},
writable: true,
enumerable: true,
configurable: true
},
indexOfNode: {
/**
* Get the index of a node in its parent node.
*
* @method indexOfNode
* @private
* @param {Node} child the child node to find the index of
* @returns {Number} the index of the child node
*/
value: function indexOfNode(child) {
var i = 0;
while (child = child.previousSibling) {
i++;
}
return i;
},
writable: true,
enumerable: true,
configurable: true
},
lengthUpTo: {
/**
* Get the number of characters up to a given node.
*
* @method lengthUpTo
* @private
* @param {Node} node a node to find the length up to
* @returns {Number} the length up to the given node
*/
value: function lengthUpTo(lastNode) {
var len = 0;
var iter = this.iterator;
var node = undefined;
while (node = iter.nextNode()) {
if (node === lastNode) {
break;
}
len += this.nodeLength(node);
}
return len;
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
/**
* Reset the state of the cursor.
*
* @method reset
* @private
*/
value: function reset() {
this.start = null;
this.end = null;
},
writable: true,
enumerable: true,
configurable: true
},
nodeLength: {
/**
* Get the "length" of a node. Text nodes are the length of their contents,
* and `<br>` tags, for example, have a length of 1 (a newline character,
* essentially).
*
* @method nodeLength
* @private
* @param {Node} node a Node, typically a Text or HTMLElement node
* @return {Number} the length of the node, as text
*/
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = undefined;
if (this.lineBreak) {
previousSibling = node.previousElementSibling;
}
if (previousSibling && previousSibling.classList.contains(this.lineBreak)) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return Curse;
})();
module.exports = Curse;
}, {}] }, {}, [1])(1);
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],2:[function(require,module,exports){
(function (global){
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.miniprism=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";
/*
* The syntax parsing algorithm in this file is copied heavily from Lea Verou's
* Prism project, which bears this license:
*
* MIT LICENSE
*
* Copyright (c) 2012-2013 Lea Verou
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var grammars = _dereq_("./grammars");
exports.grammars = grammars;
exports.highlight = function highlight(source, grammarName) {
var opts = arguments[2] === undefined ? {} : arguments[2];
var grammar = undefined;
if (typeof grammarName === "string") {
grammar = grammars[grammarName];
}
if (typeof grammarName === "object" && grammarName.constructor === Object) {
grammar = grammarName;
}
if (!grammar) {
throw new Error("Grammar \"" + grammarName + "\" not found.");
}
return stringify(encode(tokenize(source, grammar)), opts.lineClass);
};
function tokenize(source, grammar) {
var strings = [source];
var inlines = grammar.inlines;
if (inlines) {
// jshint -W089
for (var inlineToken in inlines) {
grammar[inlineToken] = inlines[inlineToken];
}
delete grammar.inlines;
}
for (var token in grammar) {
var patterns = grammar[token];
if (!Array.isArray(patterns)) {
patterns = [patterns];
}
for (var i = 0; i < patterns.length; i++) {
var pattern = patterns[i];
var block = pattern.block;
var classes = pattern.classes;
var inside = pattern.inside;
var lookbehind = !!pattern.lookbehind;
var lookbehindLength = 0;
var tag = undefined;
if (pattern.tag) {
tag = pattern.tag;
} else {
tag = block ? "div" : "span";
}
pattern = pattern.pattern || pattern;
for (var _i = 0; _i < strings.length; _i++) {
var string = strings[_i];
if (typeof string !== "string") {
continue;
}
pattern.lastIndex = 0;
var match = pattern.exec(string);
if (!match) {
continue;
}
if (lookbehind) {
lookbehindLength = match[1].length;
}
var from = match.index - 1 + lookbehindLength;
match = match[0].slice(lookbehindLength);
var len = match.length;
var to = from + len;
var before = string.slice(0, from + 1);
var after = string.slice(to + 1);
var args = [_i, 1];
if (before) {
args.push(before);
}
var wrapped = {
block: block,
classes: classes,
tag: tag,
text: inside ? tokenize(match, inside) : match,
token: token
};
args.push(wrapped);
if (after) {
args.push(after);
}
Array.prototype.splice.apply(strings, args);
}
}
}
return strings;
}
function stringify(source) {
var lineClass = arguments[1] === undefined ? "md-line" : arguments[1];
if (source === "\n") {
return "<br>";
}
if (typeof source === "string") {
return source.replace(/\n/g, "");
}
if (Array.isArray(source)) {
return source.reduce(function addItem(result, item) {
return result + stringify(item, lineClass);
}, "");
}
var tag = source.tag;
var classList = source.classes || source.token.split(" ");
var className = classList.map(function (token) {
return "md-" + token;
}).join(" ");
if (source.block) {
className += " " + lineClass;
}
return ["<" + tag + " class=\"" + className + "\">", stringify(source.text, lineClass), "</" + tag + ">"].join("");
}
function encode(src) {
if (Array.isArray(src)) {
return src.map(encode);
} else if (typeof src === "object") {
src.text = encode(src.text);
return src;
} else {
return escapeHTML(src);
}
}
function escapeHTML(str) {
return str.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/\//g, "&#x2F;");
}
},{"./grammars":2}],2:[function(_dereq_,module,exports){
"use strict";
exports.markdown = _dereq_("./markdown");
},{"./markdown":3}],3:[function(_dereq_,module,exports){
"use strict";
/*
* These regexes are in some places copies of, in others modifications of, and
* in some places wholly unrelated to the Markdown regexes found in the
* Stackedit project, which bears this license:
*
* StackEdit - The Markdown editor powered by PageDown.
* Copyright 2013 Benoit Schweblin (http://www.benoitschweblin.com)
* Licensed under an Apache License (http://www.apache.org/licenses/LICENSE-2.0)
*/
exports.gfm = {
block: true,
pattern: /^`{3}.*\n(?:[\s\S]*?)\n`{3} *(?:\n|$)/gm,
inside: {
"gfm-limit": {
block: true,
pattern: /^`{3}.*(?:\n|$)/gm,
inside: {
"gfm-info": {
lookbehind: true,
pattern: /^(`{3}).+(?:\n|$)/
},
"gfm-fence": /^`{3}(?:\n|$)/gm
}
},
"gfm-line": {
block: true,
pattern: /^.*(?:\n|$)/gm
} }
};
exports.blank = [{
block: true,
pattern: /\n(?![\s\S])/mg
}, {
block: true,
pattern: /^\n/mg
}];
exports["setex-h1"] = {
block: true,
pattern: /^.+\n=+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^=].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^=+[ \t]*(?:\n|$)/
}
}
};
exports["setex-h2"] = {
block: true,
pattern: /^(?!^- ).+\n-+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^-].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^-+[ \t]*(?:\n|$)/
}
}
};
exports.code = {
block: true,
pattern: /^(?: {4,}|\t).+(?:\n|$)/gm
};
// h1 through h6
for (var i = 1; i < 7; i++) {
exports["h" + i] = {
classes: ["h" + i, "has-folding"],
block: true,
pattern: new RegExp("^#{" + i + "} .*(?:\n|$)", "gm"),
inside: {
"hash folding": new RegExp("^#{" + i + "} ")
}
};
}
exports.ul = {
classes: ["ul", "has-folding"],
block: true,
pattern: /^[ \t]*(?:[*+\-])[ \t].*(?:\n|$)/gm,
inside: {
"ul-marker folding": /^[ \t]*(?:[*+\-])[ \t]/
}
};
exports.ol = {
block: true,
pattern: /^[ \t]*(?:\d+)\.[ \t].*(?:\n|$)/gm,
inside: {
"ol-marker": /^[ \t]*(?:\d+)\.[ \t]/
}
};
exports.blockquote = {
block: true,
pattern: /^ {0,3}> *.*(?:\n|$)/gm,
inside: {
"blockquote-marker": /^ {0,3}> */
}
};
exports.hr = {
block: true,
pattern: /^(?:[*\-_] *){3,}(?:\n|$)/gm
};
exports["link-def"] = {
block: true,
pattern: /^ {0,3}\[.*?\]:[ \t]+.+(?:\n|$)/gm,
inside: {
"link-def-name": {
pattern: /^ {0,3}\[.*?\]:/,
inside: {
"bracket-start": /^\[/,
"bracket-end": /\](?=:$)/,
colon: /:$/
}
},
"link-def-value": /.*(?:\n|$)/
}
};
exports.p = {
block: true,
pattern: /^.+(?:\n|$)/gm,
inside: {}
};
// jshint -W101
exports.link = {
classes: ["link", "has-folding"],
pattern: /\[(?:(?:\\.)|[^\[\]])*\]\([^\(\)\s]+(?:\(\S*?\))??[^\(\)\s]*?(?:\s(?:['‘][^'’]*['’]|["“][^"”]*["”]))?\)/gm,
inside: {
"bracket-start folding": {
pattern: /(^|[^\\])\[/,
lookbehind: true
},
ref: /(?:(?:\\.)|[^\[\]])+(?=\])/,
"bracket-end folding": /\](?=\s?\()/,
"paren-start folding": /^\(/,
"paren-end folding": /\)$/,
"href folding": /.*/
}
};
// jshint +W101
exports["link-ref"] = {
classes: ["link-ref", "has-folding"],
pattern: /\[(?:.*?)\] ?\[(?:.*?)\]/g,
inside: {
"ref-value folding": {
pattern: /\[[^\[\]]+\]$/,
inside: {
"bracket-start": /\[/,
"ref-href": /[^\[\]]+(?=]$)/,
"bracket-end": /\]/
}
},
"ref-text": {
pattern: /^\[[^\[\]]+\]/,
inside: {
"bracket-start folding": /^\[/,
ref: /^[^\[\]]+/,
"bracket-end folding": /\]$/
}
}
}
};
exports.em = {
classes: ["em", "has-folding"],
pattern: /(^|[^\\])(\*|_)(\S[^\2]*?)??[^\s\\]+?\2/g,
lookbehind: true,
inside: {
"em-marker folding": /(?:^(?:\*|_))|(?:(?:\*|_)$)/
}
};
exports.strong = {
classes: ["strong", "has-folding"],
pattern: /([_\*]){2}(?:(?!\1{2}).)*\1{2}/g,
inside: {
"strong-marker folding": /(?:^(?:\*|_){2})|(?:(?:\*|_){2}$)/
}
};
exports["inline-code"] = {
classes: ["inline-code", "has-folding"],
pattern: /(^|[^\\])`(\S[^`]*?)??[^\s\\]+?`/g,
lookbehind: true,
inside: {
"inline-code-marker folding": /(?:^(?:`))|(?:(?:`)$)/
}
};
var inlines = {
strong: exports.strong,
em: exports.em,
link: exports.link,
"inline-code": exports["inline-code"],
"link-ref": exports["link-ref"]
};
["setex-h1", "setex-h2", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "blockquote", "p"].forEach(function (token) {
exports[token].inside.inlines = inlines;
});
["em", "strong"].forEach(function (token) {
exports[token].inside = exports[token].inside || {};
exports[token].inside.inlines = {
link: exports.link,
"link-ref": exports["link-ref"]
};
});
},{}]},{},[1])
(1)
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./types/constants").PRE;
var blocks = require("./grammar").blocks;
var Null = require("./types").Null;
var OL = require("./types").OL;
var miniprism = _interopRequire(require("miniprism"));
// Standard inlines:
var inlines = miniprism.grammars.markdown.p.inside.inlines;
var slice = Array.prototype.slice;
var Block = (function () {
function Block(editor, _ref) {
var node = _ref.node;
var pre = _ref.pre;
var source = _ref.source;
var type = _ref.type;
this.editor = editor;
this.type = type || new Null();
this.pre = pre || "";
this.content = source;
this.node = node || this.type.createNode();
this.render(true); // (isFirstRender)
}
_prototypeProperties(Block, null, {
source: {
get: function () {
if (this.type.constructor === OL) {
var children = this.node.parentElement ? slice.call(this.node.parentElement.childNodes) : [];
var digit = children.indexOf(this.node) + 1;
return "" + digit + ". " + this._content;
} else {
return this.pre + this._content;
}
},
enumerable: true,
configurable: true
},
content: {
get: function () {
if (this.type.isHeading) {
return "" + this.pre + "" + this._content;
} else {
return this._content;
}
},
set: function (content) {
this._content = content;
var match = undefined,
type = undefined;
if (this.type.isHeading && !content) {
this.type = new Null();
this.pre = "";
}
if (!this.type.shouldReparse) {
return;
}
// jshint -W089
for (var i = 0, len = blocks.length; i < len; i++) {
type = blocks[i];
if (match = content.match(type.pattern)) {
break;
}
}
this.type = type;
this._content = "";
match = match.slice(1);
var labels = type.labels;
for (var i = 0, len = match.length; i < len; i++) {
if (labels[i] === PRE) {
this.pre = match[i];
} else {
this._content += match[i];
}
}
},
enumerable: true,
configurable: true
},
html: {
get: function () {
if (this.type.isHeading) {
return "<span class=\"md-pre\">" + esc(this.pre) + "</span>" + ("" + miniprism.highlight(this._content, inlines));
} else {
return miniprism.highlight(this._content, inlines);
}
},
enumerable: true,
configurable: true
},
shouldContinue: {
get: function () {
return this.type.continues && this.content;
},
enumerable: true,
configurable: true
},
type: {
get: function () {
return this._type;
},
set: function (type) {
this.adjustedPre = false;
this.pre = "";
return this._type = type;
},
enumerable: true,
configurable: true
},
appendTo: {
value: function appendTo(node) {
this.type.appendChild(this.node, node);
},
writable: true,
enumerable: true,
configurable: true
},
clone: {
value: function clone() {
return new this.constructor(this.editor, {
node: this.node.cloneNode(true),
pre: this.pre,
source: this.content,
type: this.type
});
},
writable: true,
enumerable: true,
configurable: true
},
continueFrom: {
value: function continueFrom(block) {
this.type = block.type;
this.pre = block.pre;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
var isFirstRender = arguments[0] === undefined ? false : arguments[0];
if (this.content === this.node.textContent && !isFirstRender) {
return;
}
var oldNode = this.node;
var oldType = this.type;
if (!isFirstRender) {
this.content = this.node.textContent;
}
this.editor.curse.capture();
if (oldType !== this.type) {
this.node = this.type.createNode();
this.type.replaceNode(this.node, oldNode);
}
/*
* Adjust the Curse for `pre` since it is about to be removed from the
* DOM during `#render`. This does not apply to reparsing types, as their
* `pre` is still displayed when focused.
*/
if (!this.adjustedPre && !this.type.shouldReparse) {
this.editor.curse.start -= this.pre.length;
this.editor.curse.end -= this.pre.length;
this.adjustedPre = true;
}
if (this.content) {
this.node.innerHTML = this.html;
} else {
this.node.innerHTML = "<br>";
}
this.editor.curse.restore();
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
value: function reset() {
this.type = new Null();
this.content = this.content;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
selectionSubstring: {
value: function selectionSubstring(sel) {
var anchorNode = sel.anchorNode;
var focusNode = sel.focusNode;
var anchorOffset = sel.anchorOffset;
var focusOffset = sel.focusOffset;
var start = 0;
var end = Infinity;
var curse = this.editor.curse;
if (this.node.contains(anchorNode)) {
start = curse.lengthUpTo(anchorNode) - curse.lengthUpTo(this.node.firstChild) + anchorOffset;
if (this.type.isList) {
start += this.pre.length;
}
}
if (this.node.contains(focusNode)) {
end = curse.lengthUpTo(focusNode) - curse.lengthUpTo(this.node.firstChild) + focusOffset;
if (this.type.isList) {
end += this.pre.length;
}
}
return this.source.substring(start, end);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Block;
})();
module.exports = Block;
function esc(text) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(text));
return div.innerHTML;
}
},{"./grammar":6,"./types":15,"./types/constants":7,"miniprism":2}],4:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Curse = _interopRequire(require("../bower_components/curse/dist/curse"));
var _Curse = (function (Curse) {
function _Curse() {
if (Object.getPrototypeOf(_Curse) !== null) {
Object.getPrototypeOf(_Curse).apply(this, arguments);
}
}
_inherits(_Curse, Curse);
_prototypeProperties(_Curse, null, {
nodeLength: {
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = node.previousElementSibling;
if (previousSibling && previousSibling.classList.contains("LineBreak")) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return _Curse;
})(Curse);
module.exports = _Curse;
},{"../bower_components/curse/dist/curse":1}],5:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Block = _interopRequire(require("./block"));
var Curse = _interopRequire(require("./curse"));
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var BACKSPACE = 8;
var RETURN = 13;
var slice = Array.prototype.slice;
var Editor = (function () {
function Editor() {
var source = arguments[0] === undefined ? "" : arguments[0];
this.blocks = [];
this.node = this.createNode();
this.curse = new Curse(this.node, {
nodeLengths: { BR: 0 }
});
this.source = source;
this.bindEvents();
this.observeMutations();
}
_prototypeProperties(Editor, null, {
anchorNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentAnchor);
},
enumerable: true,
configurable: true
},
focusNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentFocus);
},
enumerable: true,
configurable: true
},
blockNodes: {
get: function () {
return this.blocks.map(function (block) {
return block.node;
});
},
enumerable: true,
configurable: true
},
currentAnchor: {
get: function () {
return this.getNode(window.getSelection().anchorNode);
},
enumerable: true,
configurable: true
},
currentBlock: {
get: function () {
return this.getBlockFromNode(this.currentNode);
},
enumerable: true,
configurable: true
},
currentFocus: {
get: function () {
return this.getNode(window.getSelection().focusNode);
},
enumerable: true,
configurable: true
},
currentNode: {
get: function () {
if (!this.isActive) {
return null;
}
if (this.isReversed) {
return this.currentFocus;
} else {
return this.currentAnchor;
}
},
enumerable: true,
configurable: true
},
foldingNodes: {
get: function () {
return slice.call(this.node.querySelectorAll(".md-folding, .md-pre"));
},
enumerable: true,
configurable: true
},
isActive: {
get: function () {
return document.activeElement === this.node;
},
enumerable: true,
configurable: true
},
isReversed: {
get: function () {
var _ref = this;
var currentAnchor = _ref.currentAnchor;
var currentFocus = _ref.currentFocus;
var nodes = _ref.nodes;
return nodes.indexOf(currentAnchor) > nodes.indexOf(currentFocus);
},
enumerable: true,
configurable: true
},
nodes: {
get: function () {
var nodeList = this.node.querySelectorAll(".Block");
return slice.call(nodeList);
},
enumerable: true,
configurable: true
},
toggleFoldingFn: {
get: function () {
if (this._toggleFoldingFn) {
return this._toggleFoldingFn;
}
return this._toggleFoldingFn = this.toggleFolding.bind(this);
},
enumerable: true,
configurable: true
},
source: {
get: function () {
return this.blocks.map(function (block) {
return block.source;
}).join("\n");
},
set: function (source) {
var _this = this;
this.blocks = source.split(/\n/).map(function (line) {
return new Block(_this, { source: line });
});
this.render();
},
enumerable: true,
configurable: true
},
bindEvents: {
value: function bindEvents() {
document.addEventListener("selectionchange", this.toggleFoldingFn);
this.node.addEventListener("input", this.startRenders.bind(this));
this.node.addEventListener("input", this.toggleFoldingFn);
this.node.addEventListener("keydown", this.onReturn.bind(this));
this.node.addEventListener("keydown", this.preventEmpty.bind(this));
this.node.addEventListener("copy", this.onCopy.bind(this));
this.node.addEventListener("cut", this.onCopy.bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement("div");
node.classList.add("Editor");
node.setAttribute("contenteditable", true);
return node;
},
writable: true,
enumerable: true,
configurable: true
},
eachSelectionNode: {
value: function eachSelectionNode(fn) {
var sel = window.getSelection();
var pointTypes = sel.isCollapsed ? ["anchor"] : ["anchor", "focus"];
for (var i = 0, len = pointTypes.length; i < len; i++) {
var pointType = pointTypes[i];
var node = sel["" + pointType + "Node"];
var offset = sel["" + pointType + "Offset"];
fn(node, offset, sel);
}
},
writable: true,
enumerable: true,
configurable: true
},
focusBlock: {
value: function focusBlock(block, hasContent) {
var range = document.createRange();
var sel = window.getSelection();
var pos = hasContent ? 0 : block.node.childNodes.length;
range.setStart(block.node, pos);
range.setEnd(block.node, pos);
sel.removeAllRanges();
sel.addRange(range);
},
writable: true,
enumerable: true,
configurable: true
},
getBlockFromNode: {
value: function getBlockFromNode(node) {
return this.blocks[this.nodes.indexOf(node)];
},
writable: true,
enumerable: true,
configurable: true
},
getNode: {
value: function getNode(node) {
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
while (!node.classList.contains("Block")) {
node = node.parentElement;
}
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBlock: {
value: function insertBlock(block, prevBlock, nextElementSibling) {
var parentNode = this.node;
var prevNode = prevBlock.node;
var prevParent = prevNode.parentElement;
if (prevBlock.shouldContinue) {
parentNode = prevParent;
block.continueFrom(prevBlock);
} else if (prevBlock.type.continues) {
block.reset();
block.content = block.content;
this.splitBlock(prevParent, prevNode);
prevNode.remove();
if (prevParent.childNodes.length === 0) {
nextElementSibling = prevParent.nextElementSibling;
prevParent.remove();
} else {
nextElementSibling = prevParent;
}
}
block.type.insertBefore(block.node, nextElementSibling, parentNode);
},
writable: true,
enumerable: true,
configurable: true
},
observeMutations: {
value: function observeMutations() {
new MutationObserver(this.onMutation.bind(this)).observe(this.node, { childList: true, subtree: true });
},
writable: true,
enumerable: true,
configurable: true
},
onMutation: {
value: function onMutation(mutationRecords) {
for (var i = 0, len = mutationRecords.length; i < len; i++) {
var mut = mutationRecords[i];
for (var _i = 0, _len = mut.removedNodes.length; _i < _len; _i++) {
this.removeNodes(mut.removedNodes);
}
}
},
writable: true,
enumerable: true,
configurable: true
},
onCopy: {
value: function onCopy(e) {
this.copying = true;
var sel = window.getSelection();
var range = sel.getRangeAt(0);
var copyBin = document.createElement("pre");
var text = "";
var anc = this.anchorNodeBlock;
var foc = this.focusNodeBlock;
var nodes = this.nodes;
text += anc.selectionSubstring(sel) + "\n";
var started = undefined;
for (var i = 0, len = nodes.length; i < len; i++) {
if (foc.node === nodes[i]) {
break;
}
if (anc.node === nodes[i]) {
started = true;
continue;
}
if (started) {
text += this.getBlockFromNode(nodes[i]).source + "\n";
}
}
if (anc !== foc) {
text += foc.selectionSubstring(sel);
}
copyBin.classList.add("CopyBin");
copyBin.textContent = text;
this.node.appendChild(copyBin);
var newRange = document.createRange();
newRange.selectNodeContents(copyBin);
sel.removeAllRanges();
sel.addRange(newRange);
setTimeout((function () {
copyBin.remove();
sel.removeAllRanges();
sel.addRange(range);
this.copying = false;
if (e.type === "cut") {
document.execCommand("insertText", null, "");
}
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
onReturn: {
value: function onReturn(e) {
if (e.keyCode !== RETURN) {
return;
}
e.preventDefault();
var _ref2 = this;
var currentAnchor = _ref2.currentAnchor;
var currentFocus = _ref2.currentFocus;
var currentNode = _ref2.currentNode;
var isReversed = _ref2.isReversed;
var startNode = isReversed ? currentFocus : currentAnchor;
var endNode = isReversed ? currentAnchor : currentFocus;
var nextElementSibling = endNode.nextElementSibling;
var range = window.getSelection().getRangeAt(0);
var collapsed = range.collapsed;
var startContainer = range.startContainer;
var endContainer = range.endContainer;
var startOffset = range.startOffset;
var endOffset = range.endOffset;
// In a copy of the range, select the entire end node of the selection
var rangeCopy = range.cloneRange();
rangeCopy.selectNodeContents(endNode);
// In the range copy, select only the text in the current node *after* the
// user's current selection.
if (range.collapsed) {
rangeCopy.setStart(startContainer, startOffset);
} else {
rangeCopy.setStart(endContainer, endOffset);
}
// Set the text after the user's selection to `source` so that it can be
// inserted into the new block being created.
var source = rangeCopy.toString();
var block = undefined;
if (endContainer === this.node || endOffset === 0) {
block = this.getBlockFromNode(endNode).clone();
} else {
block = new Block(this, { source: source });
}
rangeCopy.deleteContents();
// Delete the content selected by the user
range.deleteContents();
if (currentNode.textContent === "") {
currentNode.innerHTML = "<br>";
}
var idx = this.nodes.indexOf(currentNode) + 1;
this.blocks.splice(idx, 0, block);
this.insertBlock(block, this.blocks[idx - 1], nextElementSibling);
this.focusBlock(block, source);
// When not collapsed remove the end node since we're recreating it with its
// remaining contents.
if (!collapsed && startNode !== endNode) {
endNode.remove();
}
// Manually dispatch an `input` event since we called `preventDefault`.
this.node.dispatchEvent(new Event("input"));
},
writable: true,
enumerable: true,
configurable: true
},
toggleFolding: {
value: function toggleFolding() {
if (this.copying) {
return;
}
this.foldingNodes.forEach(function (node) {
return node.classList.remove("visible");
});
if (!this.isActive) {
return;
}
var range = window.getSelection().getRangeAt(0);
this.foldingNodes.forEach(function (node) {
if (range.intersectsNode(node)) {
node.classList.add("visible");
}
});
slice.call(this.currentNode.querySelectorAll(".md-pre")).forEach(function (node) {
return node.classList.add("visible");
});
this.eachSelectionNode((function maybeAddVisible(node, offset) {
var nextSibling = node.nextElementSibling;
if (nextSibling && nextSibling.classList.contains("md-has-folding") && offset === node.textContent.length) {
node = nextSibling;
}
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
if (!node.classList.contains("md-has-folding")) {
var parentEl = undefined;
var testNode = node;
while (parentEl = testNode.parentElement) {
testNode = parentEl;
if (parentEl.classList.contains("md-has-folding")) {
node = parentEl;
}
if (parentEl.classList.contains("Block")) {
break;
}
}
}
if (!node.classList.contains("md-has-folding")) {
return;
}
slice.call(node.querySelectorAll(".md-folding")).forEach(function (node) {
return node.classList.add("visible");
});
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
preventEmpty: {
value: function preventEmpty(e) {
if (!(window.getSelection().isCollapsed && e.keyCode === BACKSPACE)) {
return;
}
var currentNode = this.currentNode;
if (currentNode.textContent === "" && currentNode === this.nodes[0]) {
e.preventDefault();
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNode: {
value: function removeNode(node) {
if (!node.classList.contains("Block")) {
return;
}
var idx = this.blockNodes.indexOf(node);
if (idx !== -1 && !node.isMoving) {
this.blocks.splice(idx, 1);
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNodes: {
value: function removeNodes(nodes) {
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i];
if (node.nodeType !== ELEMENT_NODE || node.isMoving) {
continue;
}
if (node.classList.contains("Block")) {
this.removeNode(nodes[i]);
} else {
var children = node.querySelectorAll(".Block");
for (var _i2 = 0, _len2 = children.length; _i2 < _len2; _i2++) {
this.removeNode(children[_i2]);
}
}
}
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
this.innerHTML = "";
for (var i = 0, len = this.blocks.length; i < len; i++) {
this.blocks[i].appendTo(this.node);
}
},
writable: true,
enumerable: true,
configurable: true
},
splitBlock: {
value: function splitBlock(block, node) {
var blockOne = block.cloneNode();
// Cache, since we're removing some.
var children = slice.call(block.childNodes);
_loop: for (var i = 0, len = children.length; i < len; i++) {
var _ret = (function (i, len) {
var childNode = children[i];
if (childNode !== node) {
childNode.isMoving = true;
blockOne.appendChild(childNode);
setTimeout(function () {
return childNode.isMoving = false;
});
} else {
return "break";
}
})(i, len);
if (_ret === "break") break _loop;
}
if (blockOne.childNodes.length > 0) {
block.parentElement.insertBefore(blockOne, block);
}
return [blockOne, block];
},
writable: true,
enumerable: true,
configurable: true
},
startRenders: {
value: function startRenders() {
this.blocks.forEach(function (block) {
return block.render();
});
},
writable: true,
enumerable: true,
configurable: true
},
teardown: {
value: function teardown() {
document.removeEventListener("selectionchange", this.toggleFoldingFn);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Editor;
})();
module.exports = Editor;
},{"./block":3,"./curse":4}],6:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var types = _interopRequire(require("./types"));
var grammar = { blocks: [] };
for (var i = 1; i <= 6; i++) {
grammar.blocks.push(new types["H" + i]());
}
grammar.blocks.push(new types.OL());
grammar.blocks.push(new types.UL());
grammar.blocks.push(new types.Paragraph());
module.exports = grammar;
},{"./types":15}],7:[function(require,module,exports){
"use strict";
module.exports = {
PRE: -1
};
},{}],8:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H1 = (function (Heading) {
function H1() {
if (Object.getPrototypeOf(H1) !== null) {
Object.getPrototypeOf(H1).apply(this, arguments);
}
}
_inherits(H1, Heading);
_prototypeProperties(H1, null, {
level: {
get: function () {
return 1;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(# )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H1;
})(Heading);
module.exports = H1;
},{"./heading":14}],9:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H2 = (function (Heading) {
function H2() {
if (Object.getPrototypeOf(H2) !== null) {
Object.getPrototypeOf(H2).apply(this, arguments);
}
}
_inherits(H2, Heading);
_prototypeProperties(H2, null, {
level: {
get: function () {
return 2;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{2} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H2;
})(Heading);
module.exports = H2;
},{"./heading":14}],10:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H3 = (function (Heading) {
function H3() {
if (Object.getPrototypeOf(H3) !== null) {
Object.getPrototypeOf(H3).apply(this, arguments);
}
}
_inherits(H3, Heading);
_prototypeProperties(H3, null, {
level: {
get: function () {
return 3;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{3} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H3;
})(Heading);
module.exports = H3;
},{"./heading":14}],11:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H4 = (function (Heading) {
function H4() {
if (Object.getPrototypeOf(H4) !== null) {
Object.getPrototypeOf(H4).apply(this, arguments);
}
}
_inherits(H4, Heading);
_prototypeProperties(H4, null, {
level: {
get: function () {
return 4;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{4} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H4;
})(Heading);
module.exports = H4;
},{"./heading":14}],12:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H5 = (function (Heading) {
function H5() {
if (Object.getPrototypeOf(H5) !== null) {
Object.getPrototypeOf(H5).apply(this, arguments);
}
}
_inherits(H5, Heading);
_prototypeProperties(H5, null, {
level: {
get: function () {
return 5;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{5} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H5;
})(Heading);
module.exports = H5;
},{"./heading":14}],13:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H6 = (function (Heading) {
function H6() {
if (Object.getPrototypeOf(H6) !== null) {
Object.getPrototypeOf(H6).apply(this, arguments);
}
}
_inherits(H6, Heading);
_prototypeProperties(H6, null, {
level: {
get: function () {
return 6;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{6} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H6;
})(Heading);
module.exports = H6;
},{"./heading":14}],14:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./constants").PRE;
var Type = _interopRequire(require("./type"));
var Heading = (function (Type) {
function Heading() {
if (Object.getPrototypeOf(Heading) !== null) {
Object.getPrototypeOf(Heading).apply(this, arguments);
}
}
_inherits(Heading, Type);
_prototypeProperties(Heading, null, {
cssClass: {
get: function () {
return "h" + this.level;
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "H" + this.level;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return new RegExp("^(#{1,6} )(.*)$");
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Heading;
})(Type);
module.exports = Heading;
},{"./constants":7,"./type":20}],15:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var H1 = _interopRequire(require("./h1"));
var H2 = _interopRequire(require("./h2"));
var H3 = _interopRequire(require("./h3"));
var H4 = _interopRequire(require("./h4"));
var H5 = _interopRequire(require("./h5"));
var H6 = _interopRequire(require("./h6"));
var Null = _interopRequire(require("./null"));
var Paragraph = _interopRequire(require("./paragraph"));
var OL = _interopRequire(require("./ol"));
var UL = _interopRequire(require("./ul"));
module.exports = {
H1: H1,
H2: H2,
H3: H3,
H4: H4,
H5: H5,
H6: H6,
Null: Null,
Paragraph: Paragraph,
OL: OL,
UL: UL
};
},{"./h1":8,"./h2":9,"./h3":10,"./h4":11,"./h5":12,"./h6":13,"./null":17,"./ol":18,"./paragraph":19,"./ul":21}],16:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var PRE = require("./constants").PRE;
var List = (function (Type) {
function List() {
if (Object.getPrototypeOf(List) !== null) {
Object.getPrototypeOf(List).apply(this, arguments);
}
}
_inherits(List, Type);
_prototypeProperties(List, null, {
continues: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "li";
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "LI";
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
var listNode = undefined;
if (parent.lastChild && parent.lastChild.nodeName === this.parentNodeName) {
listNode = parent.lastChild;
} else {
listNode = this.createListNode();
}
listNode.appendChild(node);
parent.appendChild(listNode);
},
writable: true,
enumerable: true,
configurable: true
},
createListNode: {
value: function createListNode() {
var ul = document.createElement(this.parentNodeName.toLowerCase());
ul.classList.add("LineBreak");
return ul;
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
var listNode = undefined;
if (oldNode.previousElementSibling && oldNode.previousElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.previousElementSibling;
listNode.appendChild(node);
} else if (oldNode.nextElementSibling && oldNode.nextElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.nextElementSibling;
listNode.insertBefore(node, listNode.firstChild);
} else {
listNode = this.createListNode();
listNode.appendChild(node);
}
listNode.isMoving = true;
oldNode.parentElement.replaceChild(listNode, oldNode);
setTimeout(function () {
return listNode.isMoving = false;
});
},
writable: true,
enumerable: true,
configurable: true
}
});
return List;
})(Type);
module.exports = List;
},{"./constants":7,"./type":20}],17:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Null = (function (Type) {
function Null() {
if (Object.getPrototypeOf(Null) !== null) {
Object.getPrototypeOf(Null).apply(this, arguments);
}
}
_inherits(Null, Type);
_prototypeProperties(Null, null, {
isNull: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Null;
})(Type);
module.exports = Null;
},{"./type":20}],18:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var OL = (function (List) {
function OL() {
if (Object.getPrototypeOf(OL) !== null) {
Object.getPrototypeOf(OL).apply(this, arguments);
}
}
_inherits(OL, List);
_prototypeProperties(OL, null, {
cssClass: {
get: function () {
return "ol-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "OL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(\d+\. )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return OL;
})(List);
module.exports = OL;
},{"./list":16}],19:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Paragraph = (function (Type) {
function Paragraph() {
if (Object.getPrototypeOf(Paragraph) !== null) {
Object.getPrototypeOf(Paragraph).apply(this, arguments);
}
}
_inherits(Paragraph, Type);
_prototypeProperties(Paragraph, null, {
cssClass: {
get: function () {
return "p";
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "P";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(.*)$/;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Paragraph;
})(Type);
module.exports = Paragraph;
},{"./type":20}],20:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Type = (function () {
function Type() {}
_prototypeProperties(Type, null, {
continues: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "";
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isNull: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "DIV";
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
parent.appendChild(node);
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement(this.nodeName.toLowerCase());
node.className = "Block LineBreak";
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBefore: {
value: function insertBefore(node, next, parent) {
parent.insertBefore(node, next);
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
oldNode.parentElement.replaceChild(node, oldNode);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Type;
})();
module.exports = Type;
},{}],21:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var UL = (function (List) {
function UL() {
if (Object.getPrototypeOf(UL) !== null) {
Object.getPrototypeOf(UL).apply(this, arguments);
}
}
_inherits(UL, List);
_prototypeProperties(UL, null, {
cssClass: {
get: function () {
return "ul-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "UL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(- )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return UL;
})(List);
module.exports = UL;
},{"./list":16}]},{},[5])
(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
(function (global){
"use strict";
!(function (e) {
if ("object" == typeof exports) module.exports = e();else if ("function" == typeof define && define.amd) define(e);else {
var f;"undefined" != typeof window ? f = window : "undefined" != typeof global ? f = global : "undefined" != typeof self && (f = self), f.Curse = e();
}
})(function () {
var define, module, exports;return (function e(t, n, r) {
var s = function (o, u) {
if (!n[o]) {
if (!t[o]) {
var a = typeof require == "function" && require;if (!u && a) return a(o, !0);if (i) return i(o, !0);throw new Error("Cannot find module '" + o + "'");
}var f = n[o] = { exports: {} };t[o][0].call(f.exports, function (e) {
var n = t[o][1][e];return s(n ? n : e);
}, f, f.exports, e, t, n, r);
}return n[o].exports;
};
var i = typeof require == "function" && require;for (var o = 0; o < r.length; o++) s(r[o]);return s;
})({ 1: [function (_dereq_, module, exports) {
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
/**
* Captures and restores the cursor position inside of an HTML element. This
* is particularly useful for capturing, editing, and restoring selections
* in contenteditable elements, where the selection may span both text nodes
* and element nodes.
*
* var elem = document.querySelector('#editor');
* var curse = new Curse(elem);
* curse.capture();
*
* // ...
*
* curse.restore();
*
* @class Curse
* @constructor
* @param {HTMLElement} element an element to track the cursor inside of
*/
var Curse = (function () {
var Curse = function (element) {
var _ref = arguments[1] === undefined ? {} : arguments[1];
var lineBreak = _ref.lineBreak;
var nodeLengths = _ref.nodeLengths;
this.lineBreak = lineBreak;
this.nodeLengths = nodeLengths || {};
this.element = element;
this.reset();
};
_prototypeProperties(Curse, null, {
iterator: {
/**
* An iterator to iterate over the nodes in `this.element`.
*
* This returns a simple node iterator that skips `this.element`, but not its
* children.
*
* @property iterator
* @private
* @type {NodeIterator}
*/
get: function () {
var elem = this.element;
return document.createNodeIterator(this.element, NodeFilter.SHOW_ALL, function onNode(node) {
return node === elem ? NodeFilter.FILTER_SKIP : NodeFilter.FILTER_ACCEPT;
});
},
enumerable: true,
configurable: true
},
capture: {
/**
* Captures the current selection in the element, by storing "start" and
* "end" integer values. This allows for the text and text nodes to change
* inside the element and still have the Curse be able to restore selection
* state.
*
* A `<br>` tag, for example, is counted as a single "character", while
* a text node with the text "Hello, world" is counted as 12 characters.
*
* @method capture
*/
value: function capture() {
var _window$getSelection = window.getSelection();
var anchorNode = _window$getSelection.anchorNode;
var anchorOffset = _window$getSelection.anchorOffset;
var focusNode = _window$getSelection.focusNode;
var focusOffset = _window$getSelection.focusOffset;
var child = undefined,
start = undefined,
end = undefined;
if (anchorNode === null || focusNode === null) {
this.reset();
return;
}
if (anchorNode.nodeName === "#text") {
start = this.lengthUpTo(anchorNode) + anchorOffset;
} else {
child = anchorNode.childNodes[anchorOffset ? anchorOffset - 1 : 0];
start = this.lengthUpTo(child);
}
if (focusNode.nodeName === "#text") {
end = this.lengthUpTo(focusNode) + focusOffset;
} else {
child = focusNode.childNodes[focusOffset ? focusOffset - 1 : 0];
end = this.lengthUpTo(child) + this.nodeLength(child);
}
this.start = start;
this.end = end;
},
writable: true,
enumerable: true,
configurable: true
},
restore: {
/**
* Restore the captured cursor state by iterating over the child nodes in the
* element and counting their length.
*
* @method restore
* @param {Boolean} [onlyActive=true] only restore if the curse's element is
* the active element
*/
value: function restore() {
var onlyActive = arguments[0] === undefined ? true : arguments[0];
if (onlyActive && document.activeElement !== this.element) {
return;
}
if (!onlyActive) {
this.element.focus();
}
var range = document.createRange();
var idx = 0;
var _ref2 = this;
var start = _ref2.start;
var end = _ref2.end;
var iter = this.iterator;
var node = undefined,
setStart = undefined,
setEnd = undefined;
if (this.start > this.end) {
start = this.end;
end = this.start;
}
while (node = iter.nextNode()) {
if (setStart && setEnd) {
break;
}
var nodeLength = this.nodeLength(node);
var isText = node.nodeName === "#text";
var childIdx = undefined;
if (!setStart && start <= idx + nodeLength) {
if (isText) {
range.setStart(node, start - idx);
} else {
childIdx = this.indexOfNode(node);
range.setStart(node.parentNode, childIdx);
}
setStart = true;
}
if (!setEnd && end <= idx + nodeLength) {
if (isText) {
range.setEnd(node, end - idx);
} else {
childIdx = this.indexOfNode(node);
range.setEnd(node.parentNode, childIdx);
}
setEnd = true;
}
idx += nodeLength;
}
var selection = window.getSelection();
selection.removeAllRanges();
// Reverse the selection if it was originally backwards
if (this.start > this.end) {
var startContainer = range.startContainer;
var startOffset = range.startOffset;
range.collapse(false);
selection.addRange(range);
selection.extend(startContainer, startOffset);
} else {
selection.addRange(range);
}
},
writable: true,
enumerable: true,
configurable: true
},
indexOfNode: {
/**
* Get the index of a node in its parent node.
*
* @method indexOfNode
* @private
* @param {Node} child the child node to find the index of
* @returns {Number} the index of the child node
*/
value: function indexOfNode(child) {
var i = 0;
while (child = child.previousSibling) {
i++;
}
return i;
},
writable: true,
enumerable: true,
configurable: true
},
lengthUpTo: {
/**
* Get the number of characters up to a given node.
*
* @method lengthUpTo
* @private
* @param {Node} node a node to find the length up to
* @returns {Number} the length up to the given node
*/
value: function lengthUpTo(lastNode) {
var len = 0;
var iter = this.iterator;
var node = undefined;
while (node = iter.nextNode()) {
if (node === lastNode) {
break;
}
len += this.nodeLength(node);
}
return len;
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
/**
* Reset the state of the cursor.
*
* @method reset
* @private
*/
value: function reset() {
this.start = null;
this.end = null;
},
writable: true,
enumerable: true,
configurable: true
},
nodeLength: {
/**
* Get the "length" of a node. Text nodes are the length of their contents,
* and `<br>` tags, for example, have a length of 1 (a newline character,
* essentially).
*
* @method nodeLength
* @private
* @param {Node} node a Node, typically a Text or HTMLElement node
* @return {Number} the length of the node, as text
*/
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = undefined;
if (this.lineBreak) {
previousSibling = node.previousElementSibling;
}
if (previousSibling && previousSibling.classList.contains(this.lineBreak)) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return Curse;
})();
module.exports = Curse;
}, {}] }, {}, [1])(1);
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],2:[function(require,module,exports){
(function (global){
!function(e){if("object"==typeof exports)module.exports=e();else if("function"==typeof define&&define.amd)define(e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.miniprism=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);throw new Error("Cannot find module '"+o+"'")}var f=n[o]={exports:{}};t[o][0].call(f.exports,function(e){var n=t[o][1][e];return s(n?n:e)},f,f.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){
"use strict";
/*
* The syntax parsing algorithm in this file is copied heavily from Lea Verou's
* Prism project, which bears this license:
*
* MIT LICENSE
*
* Copyright (c) 2012-2013 Lea Verou
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
var grammars = _dereq_("./grammars");
exports.grammars = grammars;
exports.highlight = function highlight(source, grammarName) {
var opts = arguments[2] === undefined ? {} : arguments[2];
var grammar = undefined;
if (typeof grammarName === "string") {
grammar = grammars[grammarName];
}
if (typeof grammarName === "object" && grammarName.constructor === Object) {
grammar = grammarName;
}
if (!grammar) {
throw new Error("Grammar \"" + grammarName + "\" not found.");
}
return stringify(encode(tokenize(source, grammar)), opts.lineClass);
};
function tokenize(source, grammar) {
var strings = [source];
var inlines = grammar.inlines;
if (inlines) {
// jshint -W089
for (var inlineToken in inlines) {
grammar[inlineToken] = inlines[inlineToken];
}
delete grammar.inlines;
}
for (var token in grammar) {
var patterns = grammar[token];
if (!Array.isArray(patterns)) {
patterns = [patterns];
}
for (var i = 0; i < patterns.length; i++) {
var pattern = patterns[i];
var block = pattern.block;
var classes = pattern.classes;
var inside = pattern.inside;
var lookbehind = !!pattern.lookbehind;
var lookbehindLength = 0;
var tag = undefined;
if (pattern.tag) {
tag = pattern.tag;
} else {
tag = block ? "div" : "span";
}
pattern = pattern.pattern || pattern;
for (var _i = 0; _i < strings.length; _i++) {
var string = strings[_i];
if (typeof string !== "string") {
continue;
}
pattern.lastIndex = 0;
var match = pattern.exec(string);
if (!match) {
continue;
}
if (lookbehind) {
lookbehindLength = match[1].length;
}
var from = match.index - 1 + lookbehindLength;
match = match[0].slice(lookbehindLength);
var len = match.length;
var to = from + len;
var before = string.slice(0, from + 1);
var after = string.slice(to + 1);
var args = [_i, 1];
if (before) {
args.push(before);
}
var wrapped = {
block: block,
classes: classes,
tag: tag,
text: inside ? tokenize(match, inside) : match,
token: token
};
args.push(wrapped);
if (after) {
args.push(after);
}
Array.prototype.splice.apply(strings, args);
}
}
}
return strings;
}
function stringify(source) {
var lineClass = arguments[1] === undefined ? "md-line" : arguments[1];
if (source === "\n") {
return "<br>";
}
if (typeof source === "string") {
return source.replace(/\n/g, "");
}
if (Array.isArray(source)) {
return source.reduce(function addItem(result, item) {
return result + stringify(item, lineClass);
}, "");
}
var tag = source.tag;
var classList = source.classes || source.token.split(" ");
var className = classList.map(function (token) {
return "md-" + token;
}).join(" ");
if (source.block) {
className += " " + lineClass;
}
return ["<" + tag + " class=\"" + className + "\">", stringify(source.text, lineClass), "</" + tag + ">"].join("");
}
function encode(src) {
if (Array.isArray(src)) {
return src.map(encode);
} else if (typeof src === "object") {
src.text = encode(src.text);
return src;
} else {
return escapeHTML(src);
}
}
function escapeHTML(str) {
return str.replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;").replace(/'/g, "&#x27;").replace(/\//g, "&#x2F;");
}
},{"./grammars":2}],2:[function(_dereq_,module,exports){
"use strict";
exports.markdown = _dereq_("./markdown");
},{"./markdown":3}],3:[function(_dereq_,module,exports){
"use strict";
/*
* These regexes are in some places copies of, in others modifications of, and
* in some places wholly unrelated to the Markdown regexes found in the
* Stackedit project, which bears this license:
*
* StackEdit - The Markdown editor powered by PageDown.
* Copyright 2013 Benoit Schweblin (http://www.benoitschweblin.com)
* Licensed under an Apache License (http://www.apache.org/licenses/LICENSE-2.0)
*/
exports.gfm = {
block: true,
pattern: /^`{3}.*\n(?:[\s\S]*?)\n`{3} *(?:\n|$)/gm,
inside: {
"gfm-limit": {
block: true,
pattern: /^`{3}.*(?:\n|$)/gm,
inside: {
"gfm-info": {
lookbehind: true,
pattern: /^(`{3}).+(?:\n|$)/
},
"gfm-fence": /^`{3}(?:\n|$)/gm
}
},
"gfm-line": {
block: true,
pattern: /^.*(?:\n|$)/gm
} }
};
exports.blank = [{
block: true,
pattern: /\n(?![\s\S])/mg
}, {
block: true,
pattern: /^\n/mg
}];
exports["setex-h1"] = {
block: true,
pattern: /^.+\n=+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^=].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^=+[ \t]*(?:\n|$)/
}
}
};
exports["setex-h2"] = {
block: true,
pattern: /^(?!^- ).+\n-+[ \t]*(?:\n|$)/gm,
inside: {
"setex-header": {
block: true,
pattern: /^[^-].*(?:\n|$)/gm
},
"setex-marker": {
block: true,
pattern: /^-+[ \t]*(?:\n|$)/
}
}
};
exports.code = {
block: true,
pattern: /^(?: {4,}|\t).+(?:\n|$)/gm
};
// h1 through h6
for (var i = 1; i < 7; i++) {
exports["h" + i] = {
classes: ["h" + i, "has-folding"],
block: true,
pattern: new RegExp("^#{" + i + "} .*(?:\n|$)", "gm"),
inside: {
"hash folding": new RegExp("^#{" + i + "} ")
}
};
}
exports.ul = {
classes: ["ul", "has-folding"],
block: true,
pattern: /^[ \t]*(?:[*+\-])[ \t].*(?:\n|$)/gm,
inside: {
"ul-marker folding": /^[ \t]*(?:[*+\-])[ \t]/
}
};
exports.ol = {
block: true,
pattern: /^[ \t]*(?:\d+)\.[ \t].*(?:\n|$)/gm,
inside: {
"ol-marker": /^[ \t]*(?:\d+)\.[ \t]/
}
};
exports.blockquote = {
block: true,
pattern: /^ {0,3}> *.*(?:\n|$)/gm,
inside: {
"blockquote-marker": /^ {0,3}> */
}
};
exports.hr = {
block: true,
pattern: /^(?:[*\-_] *){3,}(?:\n|$)/gm
};
exports["link-def"] = {
block: true,
pattern: /^ {0,3}\[.*?\]:[ \t]+.+(?:\n|$)/gm,
inside: {
"link-def-name": {
pattern: /^ {0,3}\[.*?\]:/,
inside: {
"bracket-start": /^\[/,
"bracket-end": /\](?=:$)/,
colon: /:$/
}
},
"link-def-value": /.*(?:\n|$)/
}
};
exports.p = {
block: true,
pattern: /^.+(?:\n|$)/gm,
inside: {}
};
// jshint -W101
exports.link = {
classes: ["link", "has-folding"],
pattern: /\[(?:(?:\\.)|[^\[\]])*\]\([^\(\)\s]+(?:\(\S*?\))??[^\(\)\s]*?(?:\s(?:['‘][^'’]*['’]|["“][^"”]*["”]))?\)/gm,
inside: {
"bracket-start folding": {
pattern: /(^|[^\\])\[/,
lookbehind: true
},
ref: /(?:(?:\\.)|[^\[\]])+(?=\])/,
"bracket-end folding": /\](?=\s?\()/,
"paren-start folding": /^\(/,
"paren-end folding": /\)$/,
"href folding": /.*/
}
};
// jshint +W101
exports["link-ref"] = {
classes: ["link-ref", "has-folding"],
pattern: /\[(?:.*?)\] ?\[(?:.*?)\]/g,
inside: {
"ref-value folding": {
pattern: /\[[^\[\]]+\]$/,
inside: {
"bracket-start": /\[/,
"ref-href": /[^\[\]]+(?=]$)/,
"bracket-end": /\]/
}
},
"ref-text": {
pattern: /^\[[^\[\]]+\]/,
inside: {
"bracket-start folding": /^\[/,
ref: /^[^\[\]]+/,
"bracket-end folding": /\]$/
}
}
}
};
exports.em = {
classes: ["em", "has-folding"],
pattern: /(^|[^\\])(\*|_)(\S[^\2]*?)??[^\s\\]+?\2/g,
lookbehind: true,
inside: {
"em-marker folding": /(?:^(?:\*|_))|(?:(?:\*|_)$)/
}
};
exports.strong = {
classes: ["strong", "has-folding"],
pattern: /([_\*]){2}(?:(?!\1{2}).)*\1{2}/g,
inside: {
"strong-marker folding": /(?:^(?:\*|_){2})|(?:(?:\*|_){2}$)/
}
};
exports["inline-code"] = {
classes: ["inline-code", "has-folding"],
pattern: /(^|[^\\])`(\S[^`]*?)??[^\s\\]+?`/g,
lookbehind: true,
inside: {
"inline-code-marker folding": /(?:^(?:`))|(?:(?:`)$)/
}
};
var inlines = {
strong: exports.strong,
em: exports.em,
link: exports.link,
"inline-code": exports["inline-code"],
"link-ref": exports["link-ref"]
};
["setex-h1", "setex-h2", "h1", "h2", "h3", "h4", "h5", "h6", "ul", "ol", "blockquote", "p"].forEach(function (token) {
exports[token].inside.inlines = inlines;
});
["em", "strong"].forEach(function (token) {
exports[token].inside = exports[token].inside || {};
exports[token].inside.inlines = {
link: exports.link,
"link-ref": exports["link-ref"]
};
});
},{}]},{},[1])
(1)
});
}).call(this,typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{}],3:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./types/constants").PRE;
var blocks = require("./grammar").blocks;
var Null = require("./types").Null;
var OL = require("./types").OL;
var miniprism = _interopRequire(require("miniprism"));
// Standard inlines:
var inlines = miniprism.grammars.markdown.p.inside.inlines;
var slice = Array.prototype.slice;
var Block = (function () {
function Block(editor, _ref) {
var node = _ref.node;
var pre = _ref.pre;
var source = _ref.source;
var type = _ref.type;
this.editor = editor;
this.type = type || new Null();
this.pre = pre || "";
this.content = source;
this.node = node || this.type.createNode();
this.render(true); // (isFirstRender)
}
_prototypeProperties(Block, null, {
source: {
get: function () {
if (this.type.constructor === OL) {
var children = this.node.parentElement ? slice.call(this.node.parentElement.childNodes) : [];
var digit = children.indexOf(this.node) + 1;
return "" + digit + ". " + this._content;
} else {
return this.pre + this._content;
}
},
enumerable: true,
configurable: true
},
content: {
get: function () {
if (this.type.isHeading) {
return "" + this.pre + "" + this._content;
} else {
return this._content;
}
},
set: function (content) {
this._content = content;
var match = undefined,
type = undefined;
if (this.type.isHeading && !content) {
this.type = new Null();
this.pre = "";
}
if (!this.type.shouldReparse) {
return;
}
// jshint -W089
for (var i = 0, len = blocks.length; i < len; i++) {
type = blocks[i];
if (match = content.match(type.pattern)) {
break;
}
}
this.type = type;
this._content = "";
match = match.slice(1);
var labels = type.labels;
for (var i = 0, len = match.length; i < len; i++) {
if (labels[i] === PRE) {
this.pre = match[i];
} else {
this._content += match[i];
}
}
},
enumerable: true,
configurable: true
},
html: {
get: function () {
if (this.type.isHeading) {
return "<span class=\"md-pre\">" + esc(this.pre) + "</span>" + ("" + miniprism.highlight(this._content, inlines));
} else {
return miniprism.highlight(this._content, inlines);
}
},
enumerable: true,
configurable: true
},
shouldContinue: {
get: function () {
return this.type.continues && this.content;
},
enumerable: true,
configurable: true
},
type: {
get: function () {
return this._type;
},
set: function (type) {
this.adjustedPre = false;
this.pre = "";
return this._type = type;
},
enumerable: true,
configurable: true
},
appendTo: {
value: function appendTo(node) {
this.type.appendChild(this.node, node);
},
writable: true,
enumerable: true,
configurable: true
},
clone: {
value: function clone() {
return new this.constructor(this.editor, {
node: this.node.cloneNode(true),
pre: this.pre,
source: this.content,
type: this.type
});
},
writable: true,
enumerable: true,
configurable: true
},
continueFrom: {
value: function continueFrom(block) {
this.type = block.type;
this.pre = block.pre;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
var isFirstRender = arguments[0] === undefined ? false : arguments[0];
if (this.content === this.node.textContent && !isFirstRender) {
return;
}
var oldNode = this.node;
var oldType = this.type;
if (!isFirstRender) {
this.content = this.node.textContent;
}
this.editor.curse.capture();
if (oldType !== this.type) {
this.node = this.type.createNode();
this.type.replaceNode(this.node, oldNode);
}
/*
* Adjust the Curse for `pre` since it is about to be removed from the
* DOM during `#render`. This does not apply to reparsing types, as their
* `pre` is still displayed when focused.
*/
if (!this.adjustedPre && !this.type.shouldReparse) {
this.editor.curse.start -= this.pre.length;
this.editor.curse.end -= this.pre.length;
this.adjustedPre = true;
}
if (this.content) {
this.node.innerHTML = this.html;
} else {
this.node.innerHTML = "<br>";
}
this.editor.curse.restore();
},
writable: true,
enumerable: true,
configurable: true
},
reset: {
value: function reset() {
this.type = new Null();
this.content = this.content;
this.node = this.type.createNode();
this.render(true);
},
writable: true,
enumerable: true,
configurable: true
},
selectionSubstring: {
value: function selectionSubstring(sel) {
var anchorNode = sel.anchorNode;
var focusNode = sel.focusNode;
var anchorOffset = sel.anchorOffset;
var focusOffset = sel.focusOffset;
var start = 0;
var end = Infinity;
var curse = this.editor.curse;
if (this.node.contains(anchorNode)) {
start = curse.lengthUpTo(anchorNode) - curse.lengthUpTo(this.node.firstChild) + anchorOffset;
if (this.type.isList) {
start += this.pre.length;
}
}
if (this.node.contains(focusNode)) {
end = curse.lengthUpTo(focusNode) - curse.lengthUpTo(this.node.firstChild) + focusOffset;
if (this.type.isList) {
end += this.pre.length;
}
}
return this.source.substring(start, end);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Block;
})();
module.exports = Block;
function esc(text) {
var div = document.createElement("div");
div.appendChild(document.createTextNode(text));
return div.innerHTML;
}
},{"./grammar":6,"./types":15,"./types/constants":7,"miniprism":2}],4:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Curse = _interopRequire(require("../bower_components/curse/dist/curse"));
var _Curse = (function (Curse) {
function _Curse() {
if (Object.getPrototypeOf(_Curse) !== null) {
Object.getPrototypeOf(_Curse).apply(this, arguments);
}
}
_inherits(_Curse, Curse);
_prototypeProperties(_Curse, null, {
nodeLength: {
value: function nodeLength(node) {
var charNodes = ["BR", "HR", "IMG"];
var previousSibling = node.previousElementSibling;
if (previousSibling && previousSibling.classList.contains("LineBreak")) {
return 1;
} else if (node.nodeName === "#text") {
return node.data.length;
} else if (this.nodeLengths[node.nodeName]) {
return this.nodeLengths[node.nodeName];
} else if (charNodes.indexOf(node.nodeName) > -1) {
return 1;
} else {
return 0;
}
},
writable: true,
enumerable: true,
configurable: true
}
});
return _Curse;
})(Curse);
module.exports = _Curse;
},{"../bower_components/curse/dist/curse":1}],5:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Block = _interopRequire(require("./block"));
var Curse = _interopRequire(require("./curse"));
var ELEMENT_NODE = 1;
var TEXT_NODE = 3;
var BACKSPACE = 8;
var RETURN = 13;
var slice = Array.prototype.slice;
var Editor = (function () {
function Editor() {
var source = arguments[0] === undefined ? "" : arguments[0];
this.blocks = [];
this.node = this.createNode();
this.curse = new Curse(this.node, {
nodeLengths: { BR: 0 }
});
this.source = source;
this.bindEvents();
this.observeMutations();
}
_prototypeProperties(Editor, null, {
anchorNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentAnchor);
},
enumerable: true,
configurable: true
},
focusNodeBlock: {
get: function () {
return this.getBlockFromNode(this.currentFocus);
},
enumerable: true,
configurable: true
},
blockNodes: {
get: function () {
return this.blocks.map(function (block) {
return block.node;
});
},
enumerable: true,
configurable: true
},
currentAnchor: {
get: function () {
return this.getNode(window.getSelection().anchorNode);
},
enumerable: true,
configurable: true
},
currentBlock: {
get: function () {
return this.getBlockFromNode(this.currentNode);
},
enumerable: true,
configurable: true
},
currentFocus: {
get: function () {
return this.getNode(window.getSelection().focusNode);
},
enumerable: true,
configurable: true
},
currentNode: {
get: function () {
if (!this.isActive) {
return null;
}
if (this.isReversed) {
return this.currentFocus;
} else {
return this.currentAnchor;
}
},
enumerable: true,
configurable: true
},
foldingNodes: {
get: function () {
return slice.call(this.node.querySelectorAll(".md-folding, .md-pre"));
},
enumerable: true,
configurable: true
},
isActive: {
get: function () {
return document.activeElement === this.node;
},
enumerable: true,
configurable: true
},
isReversed: {
get: function () {
var _ref = this;
var currentAnchor = _ref.currentAnchor;
var currentFocus = _ref.currentFocus;
var nodes = _ref.nodes;
return nodes.indexOf(currentAnchor) > nodes.indexOf(currentFocus);
},
enumerable: true,
configurable: true
},
nodes: {
get: function () {
var nodeList = this.node.querySelectorAll(".Block");
return slice.call(nodeList);
},
enumerable: true,
configurable: true
},
toggleFoldingFn: {
get: function () {
if (this._toggleFoldingFn) {
return this._toggleFoldingFn;
}
return this._toggleFoldingFn = this.toggleFolding.bind(this);
},
enumerable: true,
configurable: true
},
source: {
get: function () {
return this.blocks.map(function (block) {
return block.source;
}).join("\n");
},
set: function (source) {
var _this = this;
this.blocks = source.split(/\n/).map(function (line) {
return new Block(_this, { source: line });
});
this.render();
},
enumerable: true,
configurable: true
},
bindEvents: {
value: function bindEvents() {
document.addEventListener("selectionchange", this.toggleFoldingFn);
this.node.addEventListener("input", this.startRenders.bind(this));
this.node.addEventListener("input", this.toggleFoldingFn);
this.node.addEventListener("keydown", this.onReturn.bind(this));
this.node.addEventListener("keydown", this.preventEmpty.bind(this));
this.node.addEventListener("copy", this.onCopy.bind(this));
this.node.addEventListener("cut", this.onCopy.bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement("div");
node.classList.add("Editor");
node.setAttribute("contenteditable", true);
return node;
},
writable: true,
enumerable: true,
configurable: true
},
eachSelectionNode: {
value: function eachSelectionNode(fn) {
var sel = window.getSelection();
var pointTypes = sel.isCollapsed ? ["anchor"] : ["anchor", "focus"];
for (var i = 0, len = pointTypes.length; i < len; i++) {
var pointType = pointTypes[i];
var node = sel["" + pointType + "Node"];
var offset = sel["" + pointType + "Offset"];
fn(node, offset, sel);
}
},
writable: true,
enumerable: true,
configurable: true
},
focusBlock: {
value: function focusBlock(block, hasContent) {
var range = document.createRange();
var sel = window.getSelection();
var pos = hasContent ? 0 : block.node.childNodes.length;
range.setStart(block.node, pos);
range.setEnd(block.node, pos);
sel.removeAllRanges();
sel.addRange(range);
},
writable: true,
enumerable: true,
configurable: true
},
getBlockFromNode: {
value: function getBlockFromNode(node) {
return this.blocks[this.nodes.indexOf(node)];
},
writable: true,
enumerable: true,
configurable: true
},
getNode: {
value: function getNode(node) {
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
while (!node.classList.contains("Block")) {
node = node.parentElement;
}
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBlock: {
value: function insertBlock(block, prevBlock, nextElementSibling) {
var parentNode = this.node;
var prevNode = prevBlock.node;
var prevParent = prevNode.parentElement;
if (prevBlock.shouldContinue) {
parentNode = prevParent;
block.continueFrom(prevBlock);
} else if (prevBlock.type.continues) {
block.reset();
block.content = block.content;
this.splitBlock(prevParent, prevNode);
prevNode.remove();
if (prevParent.childNodes.length === 0) {
nextElementSibling = prevParent.nextElementSibling;
prevParent.remove();
} else {
nextElementSibling = prevParent;
}
}
block.type.insertBefore(block.node, nextElementSibling, parentNode);
},
writable: true,
enumerable: true,
configurable: true
},
observeMutations: {
value: function observeMutations() {
new MutationObserver(this.onMutation.bind(this)).observe(this.node, { childList: true, subtree: true });
},
writable: true,
enumerable: true,
configurable: true
},
onMutation: {
value: function onMutation(mutationRecords) {
for (var i = 0, len = mutationRecords.length; i < len; i++) {
var mut = mutationRecords[i];
for (var _i = 0, _len = mut.removedNodes.length; _i < _len; _i++) {
this.removeNodes(mut.removedNodes);
}
}
},
writable: true,
enumerable: true,
configurable: true
},
onCopy: {
value: function onCopy(e) {
this.copying = true;
var sel = window.getSelection();
var range = sel.getRangeAt(0);
var copyBin = document.createElement("pre");
var text = "";
var anc = this.anchorNodeBlock;
var foc = this.focusNodeBlock;
var nodes = this.nodes;
text += anc.selectionSubstring(sel) + "\n";
var started = undefined;
for (var i = 0, len = nodes.length; i < len; i++) {
if (foc.node === nodes[i]) {
break;
}
if (anc.node === nodes[i]) {
started = true;
continue;
}
if (started) {
text += this.getBlockFromNode(nodes[i]).source + "\n";
}
}
if (anc !== foc) {
text += foc.selectionSubstring(sel);
}
copyBin.classList.add("CopyBin");
copyBin.textContent = text;
this.node.appendChild(copyBin);
var newRange = document.createRange();
newRange.selectNodeContents(copyBin);
sel.removeAllRanges();
sel.addRange(newRange);
setTimeout((function () {
copyBin.remove();
sel.removeAllRanges();
sel.addRange(range);
this.copying = false;
if (e.type === "cut") {
document.execCommand("insertText", null, "");
}
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
onReturn: {
value: function onReturn(e) {
if (e.keyCode !== RETURN) {
return;
}
e.preventDefault();
var _ref2 = this;
var currentAnchor = _ref2.currentAnchor;
var currentFocus = _ref2.currentFocus;
var currentNode = _ref2.currentNode;
var isReversed = _ref2.isReversed;
var startNode = isReversed ? currentFocus : currentAnchor;
var endNode = isReversed ? currentAnchor : currentFocus;
var nextElementSibling = endNode.nextElementSibling;
var range = window.getSelection().getRangeAt(0);
var collapsed = range.collapsed;
var startContainer = range.startContainer;
var endContainer = range.endContainer;
var startOffset = range.startOffset;
var endOffset = range.endOffset;
// In a copy of the range, select the entire end node of the selection
var rangeCopy = range.cloneRange();
rangeCopy.selectNodeContents(endNode);
// In the range copy, select only the text in the current node *after* the
// user's current selection.
if (range.collapsed) {
rangeCopy.setStart(startContainer, startOffset);
} else {
rangeCopy.setStart(endContainer, endOffset);
}
// Set the text after the user's selection to `source` so that it can be
// inserted into the new block being created.
var source = rangeCopy.toString();
var block = undefined;
if (endContainer === this.node || endOffset === 0) {
block = this.getBlockFromNode(endNode).clone();
} else {
block = new Block(this, { source: source });
}
rangeCopy.deleteContents();
// Delete the content selected by the user
range.deleteContents();
if (currentNode.textContent === "") {
currentNode.innerHTML = "<br>";
}
var idx = this.nodes.indexOf(currentNode) + 1;
this.blocks.splice(idx, 0, block);
this.insertBlock(block, this.blocks[idx - 1], nextElementSibling);
this.focusBlock(block, source);
// When not collapsed remove the end node since we're recreating it with its
// remaining contents.
if (!collapsed && startNode !== endNode) {
endNode.remove();
}
// Manually dispatch an `input` event since we called `preventDefault`.
this.node.dispatchEvent(new Event("input"));
},
writable: true,
enumerable: true,
configurable: true
},
toggleFolding: {
value: function toggleFolding() {
if (this.copying) {
return;
}
this.foldingNodes.forEach(function (node) {
return node.classList.remove("visible");
});
if (!this.isActive) {
return;
}
var range = window.getSelection().getRangeAt(0);
this.foldingNodes.forEach(function (node) {
if (range.intersectsNode(node)) {
node.classList.add("visible");
}
});
slice.call(this.currentNode.querySelectorAll(".md-pre")).forEach(function (node) {
return node.classList.add("visible");
});
this.eachSelectionNode((function maybeAddVisible(node, offset) {
var nextSibling = node.nextElementSibling;
if (nextSibling && nextSibling.classList.contains("md-has-folding") && offset === node.textContent.length) {
node = nextSibling;
}
if (node.nodeType === TEXT_NODE) {
node = node.parentElement;
}
if (!node.classList.contains("md-has-folding")) {
var parentEl = undefined;
var testNode = node;
while (parentEl = testNode.parentElement) {
testNode = parentEl;
if (parentEl.classList.contains("md-has-folding")) {
node = parentEl;
}
if (parentEl.classList.contains("Block")) {
break;
}
}
}
if (!node.classList.contains("md-has-folding")) {
return;
}
slice.call(node.querySelectorAll(".md-folding")).forEach(function (node) {
return node.classList.add("visible");
});
}).bind(this));
},
writable: true,
enumerable: true,
configurable: true
},
preventEmpty: {
value: function preventEmpty(e) {
if (!(window.getSelection().isCollapsed && e.keyCode === BACKSPACE)) {
return;
}
var currentNode = this.currentNode;
if (currentNode.textContent === "" && currentNode === this.nodes[0]) {
e.preventDefault();
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNode: {
value: function removeNode(node) {
if (!node.classList.contains("Block")) {
return;
}
var idx = this.blockNodes.indexOf(node);
if (idx !== -1 && !node.isMoving) {
this.blocks.splice(idx, 1);
}
},
writable: true,
enumerable: true,
configurable: true
},
removeNodes: {
value: function removeNodes(nodes) {
for (var i = 0, len = nodes.length; i < len; i++) {
var node = nodes[i];
if (node.nodeType !== ELEMENT_NODE || node.isMoving) {
continue;
}
if (node.classList.contains("Block")) {
this.removeNode(nodes[i]);
} else {
var children = node.querySelectorAll(".Block");
for (var _i2 = 0, _len2 = children.length; _i2 < _len2; _i2++) {
this.removeNode(children[_i2]);
}
}
}
},
writable: true,
enumerable: true,
configurable: true
},
render: {
value: function render() {
this.innerHTML = "";
for (var i = 0, len = this.blocks.length; i < len; i++) {
this.blocks[i].appendTo(this.node);
}
},
writable: true,
enumerable: true,
configurable: true
},
splitBlock: {
value: function splitBlock(block, node) {
var blockOne = block.cloneNode();
// Cache, since we're removing some.
var children = slice.call(block.childNodes);
_loop: for (var i = 0, len = children.length; i < len; i++) {
var _ret = (function (i, len) {
var childNode = children[i];
if (childNode !== node) {
childNode.isMoving = true;
blockOne.appendChild(childNode);
setTimeout(function () {
return childNode.isMoving = false;
});
} else {
return "break";
}
})(i, len);
if (_ret === "break") break _loop;
}
if (blockOne.childNodes.length > 0) {
block.parentElement.insertBefore(blockOne, block);
}
return [blockOne, block];
},
writable: true,
enumerable: true,
configurable: true
},
startRenders: {
value: function startRenders() {
this.blocks.forEach(function (block) {
return block.render();
});
},
writable: true,
enumerable: true,
configurable: true
},
teardown: {
value: function teardown() {
document.removeEventListener("selectionchange", this.toggleFoldingFn);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Editor;
})();
module.exports = Editor;
},{"./block":3,"./curse":4}],6:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var types = _interopRequire(require("./types"));
var grammar = { blocks: [] };
for (var i = 1; i <= 6; i++) {
grammar.blocks.push(new types["H" + i]());
}
grammar.blocks.push(new types.OL());
grammar.blocks.push(new types.UL());
grammar.blocks.push(new types.Paragraph());
module.exports = grammar;
},{"./types":15}],7:[function(require,module,exports){
"use strict";
module.exports = {
PRE: -1
};
},{}],8:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H1 = (function (Heading) {
function H1() {
if (Object.getPrototypeOf(H1) !== null) {
Object.getPrototypeOf(H1).apply(this, arguments);
}
}
_inherits(H1, Heading);
_prototypeProperties(H1, null, {
level: {
get: function () {
return 1;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(# )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H1;
})(Heading);
module.exports = H1;
},{"./heading":14}],9:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H2 = (function (Heading) {
function H2() {
if (Object.getPrototypeOf(H2) !== null) {
Object.getPrototypeOf(H2).apply(this, arguments);
}
}
_inherits(H2, Heading);
_prototypeProperties(H2, null, {
level: {
get: function () {
return 2;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{2} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H2;
})(Heading);
module.exports = H2;
},{"./heading":14}],10:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H3 = (function (Heading) {
function H3() {
if (Object.getPrototypeOf(H3) !== null) {
Object.getPrototypeOf(H3).apply(this, arguments);
}
}
_inherits(H3, Heading);
_prototypeProperties(H3, null, {
level: {
get: function () {
return 3;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{3} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H3;
})(Heading);
module.exports = H3;
},{"./heading":14}],11:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H4 = (function (Heading) {
function H4() {
if (Object.getPrototypeOf(H4) !== null) {
Object.getPrototypeOf(H4).apply(this, arguments);
}
}
_inherits(H4, Heading);
_prototypeProperties(H4, null, {
level: {
get: function () {
return 4;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{4} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H4;
})(Heading);
module.exports = H4;
},{"./heading":14}],12:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H5 = (function (Heading) {
function H5() {
if (Object.getPrototypeOf(H5) !== null) {
Object.getPrototypeOf(H5).apply(this, arguments);
}
}
_inherits(H5, Heading);
_prototypeProperties(H5, null, {
level: {
get: function () {
return 5;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{5} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H5;
})(Heading);
module.exports = H5;
},{"./heading":14}],13:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Heading = _interopRequire(require("./heading"));
var H6 = (function (Heading) {
function H6() {
if (Object.getPrototypeOf(H6) !== null) {
Object.getPrototypeOf(H6).apply(this, arguments);
}
}
_inherits(H6, Heading);
_prototypeProperties(H6, null, {
level: {
get: function () {
return 6;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(#{6} )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return H6;
})(Heading);
module.exports = H6;
},{"./heading":14}],14:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var PRE = require("./constants").PRE;
var Type = _interopRequire(require("./type"));
var Heading = (function (Type) {
function Heading() {
if (Object.getPrototypeOf(Heading) !== null) {
Object.getPrototypeOf(Heading).apply(this, arguments);
}
}
_inherits(Heading, Type);
_prototypeProperties(Heading, null, {
cssClass: {
get: function () {
return "h" + this.level;
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "H" + this.level;
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return new RegExp("^(#{1,6} )(.*)$");
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Heading;
})(Type);
module.exports = Heading;
},{"./constants":7,"./type":20}],15:[function(require,module,exports){
"use strict";
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var H1 = _interopRequire(require("./h1"));
var H2 = _interopRequire(require("./h2"));
var H3 = _interopRequire(require("./h3"));
var H4 = _interopRequire(require("./h4"));
var H5 = _interopRequire(require("./h5"));
var H6 = _interopRequire(require("./h6"));
var Null = _interopRequire(require("./null"));
var Paragraph = _interopRequire(require("./paragraph"));
var OL = _interopRequire(require("./ol"));
var UL = _interopRequire(require("./ul"));
module.exports = {
H1: H1,
H2: H2,
H3: H3,
H4: H4,
H5: H5,
H6: H6,
Null: Null,
Paragraph: Paragraph,
OL: OL,
UL: UL
};
},{"./h1":8,"./h2":9,"./h3":10,"./h4":11,"./h5":12,"./h6":13,"./null":17,"./ol":18,"./paragraph":19,"./ul":21}],16:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var PRE = require("./constants").PRE;
var List = (function (Type) {
function List() {
if (Object.getPrototypeOf(List) !== null) {
Object.getPrototypeOf(List).apply(this, arguments);
}
}
_inherits(List, Type);
_prototypeProperties(List, null, {
continues: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "li";
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [PRE, null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "LI";
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
var listNode = undefined;
if (parent.lastChild && parent.lastChild.nodeName === this.parentNodeName) {
listNode = parent.lastChild;
} else {
listNode = this.createListNode();
}
listNode.appendChild(node);
parent.appendChild(listNode);
},
writable: true,
enumerable: true,
configurable: true
},
createListNode: {
value: function createListNode() {
var ul = document.createElement(this.parentNodeName.toLowerCase());
ul.classList.add("LineBreak");
return ul;
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
var listNode = undefined;
if (oldNode.previousElementSibling && oldNode.previousElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.previousElementSibling;
listNode.appendChild(node);
} else if (oldNode.nextElementSibling && oldNode.nextElementSibling.nodeName === this.parentNodeName) {
listNode = oldNode.nextElementSibling;
listNode.insertBefore(node, listNode.firstChild);
} else {
listNode = this.createListNode();
listNode.appendChild(node);
}
listNode.isMoving = true;
oldNode.parentElement.replaceChild(listNode, oldNode);
setTimeout(function () {
return listNode.isMoving = false;
});
},
writable: true,
enumerable: true,
configurable: true
}
});
return List;
})(Type);
module.exports = List;
},{"./constants":7,"./type":20}],17:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Null = (function (Type) {
function Null() {
if (Object.getPrototypeOf(Null) !== null) {
Object.getPrototypeOf(Null).apply(this, arguments);
}
}
_inherits(Null, Type);
_prototypeProperties(Null, null, {
isNull: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Null;
})(Type);
module.exports = Null;
},{"./type":20}],18:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var OL = (function (List) {
function OL() {
if (Object.getPrototypeOf(OL) !== null) {
Object.getPrototypeOf(OL).apply(this, arguments);
}
}
_inherits(OL, List);
_prototypeProperties(OL, null, {
cssClass: {
get: function () {
return "ol-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "OL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(\d+\. )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return OL;
})(List);
module.exports = OL;
},{"./list":16}],19:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var Type = _interopRequire(require("./type"));
var Paragraph = (function (Type) {
function Paragraph() {
if (Object.getPrototypeOf(Paragraph) !== null) {
Object.getPrototypeOf(Paragraph).apply(this, arguments);
}
}
_inherits(Paragraph, Type);
_prototypeProperties(Paragraph, null, {
cssClass: {
get: function () {
return "p";
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return true;
},
enumerable: true,
configurable: true
},
labels: {
get: function () {
return [null];
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "P";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(.*)$/;
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return true;
},
enumerable: true,
configurable: true
}
});
return Paragraph;
})(Type);
module.exports = Paragraph;
},{"./type":20}],20:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var Type = (function () {
function Type() {}
_prototypeProperties(Type, null, {
continues: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
cssClass: {
get: function () {
return "";
},
enumerable: true,
configurable: true
},
isHeading: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isList: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isNull: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
isParagraph: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
nodeName: {
get: function () {
return "DIV";
},
enumerable: true,
configurable: true
},
shouldReparse: {
get: function () {
return false;
},
enumerable: true,
configurable: true
},
appendChild: {
value: function appendChild(node, parent) {
parent.appendChild(node);
},
writable: true,
enumerable: true,
configurable: true
},
createNode: {
value: function createNode() {
var node = document.createElement(this.nodeName.toLowerCase());
node.className = "Block LineBreak";
return node;
},
writable: true,
enumerable: true,
configurable: true
},
insertBefore: {
value: function insertBefore(node, next, parent) {
parent.insertBefore(node, next);
},
writable: true,
enumerable: true,
configurable: true
},
replaceNode: {
value: function replaceNode(node, oldNode) {
oldNode.parentElement.replaceChild(node, oldNode);
},
writable: true,
enumerable: true,
configurable: true
}
});
return Type;
})();
module.exports = Type;
},{}],21:[function(require,module,exports){
"use strict";
var _prototypeProperties = function (child, staticProps, instanceProps) {
if (staticProps) Object.defineProperties(child, staticProps);
if (instanceProps) Object.defineProperties(child.prototype, instanceProps);
};
var _inherits = function (subClass, superClass) {
if (typeof superClass !== "function" && superClass !== null) {
throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
}
subClass.prototype = Object.create(superClass && superClass.prototype, {
constructor: {
value: subClass,
enumerable: false,
writable: true,
configurable: true
}
});
if (superClass) subClass.__proto__ = superClass;
};
var _interopRequire = function (obj) {
return obj && (obj["default"] || obj);
};
var List = _interopRequire(require("./list"));
var UL = (function (List) {
function UL() {
if (Object.getPrototypeOf(UL) !== null) {
Object.getPrototypeOf(UL).apply(this, arguments);
}
}
_inherits(UL, List);
_prototypeProperties(UL, null, {
cssClass: {
get: function () {
return "ul-li";
},
enumerable: true,
configurable: true
},
parentNodeName: {
get: function () {
return "UL";
},
enumerable: true,
configurable: true
},
pattern: {
get: function () {
return /^(- )(.*)$/;
},
enumerable: true,
configurable: true
}
});
return UL;
})(List);
module.exports = UL;
},{"./list":16}]},{},[5])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment