Socket
Socket
Sign inDemoInstall

medium-editor-markdown

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

medium-editor-markdown - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0

879

dist/me-markdown.standalone.js

@@ -6,248 +6,718 @@ (function (root) {

var he = { decode: function (html, options) {
options = merge(options, decode.options);
var strict = options.strict;
if (strict && regexInvalidEntity.test(html)) {
parseError('malformed character reference');
}
return html.replace(regexDecode, function($0, $1, $2, $3, $4, $5, $6, $7) {
var codePoint;
var semicolon;
var hexDigits;
var reference;
var next;
if ($1) {
// Decode decimal escapes, e.g. `𝌆`.
codePoint = $1;
semicolon = $2;
if (strict && !semicolon) {
parseError('character reference was not terminated by a semicolon');
}
return codePointToSymbol(codePoint, strict);
}
if ($3) {
// Decode hexadecimal escapes, e.g. `𝌆`.
hexDigits = $3;
semicolon = $4;
if (strict && !semicolon) {
parseError('character reference was not terminated by a semicolon');
}
codePoint = parseInt(hexDigits, 16);
return codePointToSymbol(codePoint, strict);
}
if ($5) {
// Decode named character references with trailing `;`, e.g. `©`.
reference = $5;
if (has(decodeMap, reference)) {
return decodeMap[reference];
} else {
// Ambiguous ampersand; see http://mths.be/notes/ambiguous-ampersands.
if (strict) {
parseError(
'named character reference was not terminated by a semicolon'
);
}
return $0;
}
}
// If we’re still here, it’s a legacy reference for sure. No need for an
// extra `if` check.
// Decode named character references without trailing `;`, e.g. `&amp`
// This is only a parse error if it gets converted to `&`, or if it is
// followed by `=` in an attribute context.
reference = $6;
next = $7;
if (next && options.isAttributeValue) {
if (strict && next == '=') {
parseError('`&` did not start a character reference');
}
return $0;
} else {
if (strict) {
parseError(
'named character reference was not terminated by a semicolon'
);
}
// Note: there is no need to check `has(decodeMapLegacy, reference)`.
return decodeMapLegacy[reference] + (next || '');
}
});
} }
, toMarkdown = function (string) {
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.toMarkdown = f()}})(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);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.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){
/*
* to-markdown - an HTML to Markdown converter
*
* Copyright 2011-15, Dom Christie
* Licenced under the MIT licence
*
*/
var ELEMENTS = [
{
patterns: 'p',
replacement: function(str, attrs, innerHTML) {
return innerHTML ? '\n\n' + innerHTML + '\n' : '';
'use strict';
var toMarkdown;
var converters;
var mdConverters = require('./lib/md-converters');
var gfmConverters = require('./lib/gfm-converters');
var collapse = require('collapse-whitespace');
/*
* Set up window and document for Node.js
*/
var _window = (typeof window !== 'undefined' ? window : this), _document;
if (typeof document === 'undefined') {
_document = require('jsdom').jsdom();
}
else {
_document = document;
}
/*
* Utilities
*/
function trim(string) {
return string.replace(/^[ \r\n\t]+|[ \r\n\t]+$/g, '');
}
var blocks = ['address', 'article', 'aside', 'audio', 'blockquote', 'body',
'canvas', 'center', 'dd', 'dir', 'div', 'dl', 'dt', 'fieldset', 'figcaption',
'figure', 'footer', 'form', 'frameset', 'h1', 'h2', 'h3', 'h4','h5', 'h6',
'header', 'hgroup', 'hr', 'html', 'isindex', 'li', 'main', 'menu', 'nav',
'noframes', 'noscript', 'ol', 'output', 'p', 'pre', 'section', 'table',
'tbody', 'td', 'tfoot', 'th', 'thead', 'tr', 'ul'
];
function isBlock(node) {
return blocks.indexOf(node.nodeName.toLowerCase()) !== -1;
}
var voids = [
'area', 'base', 'br', 'col', 'command', 'embed', 'hr', 'img', 'input',
'keygen', 'link', 'meta', 'param', 'source', 'track', 'wbr'
];
function isVoid(node) {
return voids.indexOf(node.nodeName.toLowerCase()) !== -1;
}
/*
* Parsing HTML strings
*/
function canParseHtml() {
var Parser = _window.DOMParser, canParse = false;
// Adapted from https://gist.github.com/1129031
// Firefox/Opera/IE throw errors on unsupported types
try {
// WebKit returns null on unsupported types
if (new Parser().parseFromString('', 'text/html')) {
canParse = true;
}
} catch (e) {}
return canParse;
}
function createHtmlParser() {
var Parser = function () {};
Parser.prototype.parseFromString = function (string) {
var newDoc = _document.implementation.createHTMLDocument('');
if (string.toLowerCase().indexOf('<!doctype') > -1) {
newDoc.documentElement.innerHTML = string;
}
else {
newDoc.body.innerHTML = string;
}
return newDoc;
};
return Parser;
}
var HtmlParser = canParseHtml() ? _window.DOMParser : createHtmlParser();
function htmlToDom(string) {
var tree = new HtmlParser().parseFromString(string, 'text/html');
collapse(tree, isBlock);
return tree;
}
/*
* Flattens DOM tree into single array
*/
function bfsOrder(node) {
var inqueue = [node],
outqueue = [],
elem, children, i;
while (inqueue.length > 0) {
elem = inqueue.shift();
outqueue.push(elem);
children = elem.childNodes;
for (i = 0 ; i < children.length; i++) {
if (children[i].nodeType === 1) { inqueue.push(children[i]); }
}
}
outqueue.shift();
return outqueue;
}
/*
* Contructs a Markdown string of replacement text for a given node
*/
function getContent(node) {
var text = '';
for (var i = 0; i < node.childNodes.length; i++) {
if (node.childNodes[i].nodeType === 1) {
text += node.childNodes[i]._replacement;
}
else if (node.childNodes[i].nodeType === 3) {
text += node.childNodes[i].data;
}
else { continue; }
}
return text;
}
/*
* Returns the HTML string of an element with its contents converted
*/
function outer(node, content) {
return node.cloneNode(false).outerHTML.replace('><', '>'+ content +'<');
}
function canConvert(node, filter) {
if (typeof filter === 'string') {
return filter === node.nodeName.toLowerCase();
}
if (Array.isArray(filter)) {
return filter.indexOf(node.nodeName.toLowerCase()) !== -1;
}
else if (typeof filter === 'function') {
return filter.call(toMarkdown, node);
}
else {
throw new TypeError('`filter` needs to be a string, array, or function');
}
}
function isFlankedByWhitespace(side, node) {
var sibling, regExp, isFlanked;
if (side === 'left') {
sibling = node.previousSibling;
regExp = / $/;
}
else {
sibling = node.nextSibling;
regExp = /^ /;
}
if (sibling) {
if (sibling.nodeType === 3) {
isFlanked = regExp.test(sibling.nodeValue);
}
else if(sibling.nodeType === 1 && !isBlock(sibling)) {
isFlanked = regExp.test(sibling.textContent);
}
}
return isFlanked;
}
function flankingWhitespace(node) {
var leading = '', trailing = '';
if (!isBlock(node)) {
var hasLeading = /^[ \r\n\t]/.test(node.innerHTML),
hasTrailing = /[ \r\n\t]$/.test(node.innerHTML);
if (hasLeading && !isFlankedByWhitespace('left', node)) {
leading = ' ';
}
if (hasTrailing && !isFlankedByWhitespace('right', node)) {
trailing = ' ';
}
}
return { leading: leading, trailing: trailing };
}
/*
* Finds a Markdown converter, gets the replacement, and sets it on
* `_replacement`
*/
function process(node) {
var replacement, content = getContent(node);
for (var i = 0; i < converters.length; i++) {
var converter = converters[i];
if (canConvert(node, converter.filter)) {
if (typeof converter.replacement !== 'function') {
throw new TypeError(
'`replacement` needs to be a function that returns a string'
);
}
var whitespace = flankingWhitespace(node);
if (whitespace.leading || whitespace.trailing) {
content = trim(content);
}
replacement = whitespace.leading +
converter.replacement.call(toMarkdown, content, node) +
whitespace.trailing;
break;
}
}
// Remove blank nodes
if (!isVoid(node) && !/A/.test(node.nodeName) && /^\s*$/i.test(content)) {
replacement = '';
}
node._replacement = replacement;
}
toMarkdown = function (input, options) {
options = options || {};
if (typeof input !== 'string') {
throw new TypeError(input + ' is not a string');
}
// Escape potential ol triggers
input = input.replace(/(\d+)\. /g, '$1\\. ');
var clone = htmlToDom(input).body,
nodes = bfsOrder(clone),
output;
converters = mdConverters.slice(0);
if (options.gfm) {
converters = gfmConverters.concat(converters);
}
if (options.converters) {
converters = options.converters.concat(converters);
}
// Process through nodes in reverse (so deepest child elements are first).
for (var i = nodes.length - 1; i >= 0; i--) {
process(nodes[i]);
}
output = getContent(clone);
return output.replace(/^[\t\r\n]+|[\t\r\n\s]+$/g, '')
.replace(/\n\s+\n/g, '\n\n')
.replace(/\n{3,}/g, '\n\n');
};
toMarkdown.isBlock = isBlock;
toMarkdown.isVoid = isVoid;
toMarkdown.trim = trim;
toMarkdown.outer = outer;
module.exports = toMarkdown;
},{"./lib/gfm-converters":2,"./lib/md-converters":3,"collapse-whitespace":5,"jsdom":6}],2:[function(require,module,exports){
'use strict';
function cell(content, node) {
var index = Array.prototype.indexOf.call(node.parentNode.childNodes, node);
var prefix = ' ';
if (index === 0) { prefix = '| '; }
return prefix + content + ' |';
}
var highlightRegEx = /highlight highlight-(\S+)/;
module.exports = [
{
filter: 'br',
replacement: function () {
return '\n';
}
},
{
filter: ['del', 's', 'strike'],
replacement: function (content) {
return '~~' + content + '~~';
}
},
{
filter: function (node) {
return node.type === 'checkbox' && node.parentNode.nodeName === 'LI';
},
{
patterns: 'br',
type: 'void',
replacement: ' \n'
},
{
patterns: 'h([1-6])',
replacement: function(str, hLevel, attrs, innerHTML) {
var hPrefix = '';
for(var i = 0; i < hLevel; i++) {
hPrefix += '#';
replacement: function (content, node) {
return (node.checked ? '[x]' : '[ ]') + ' ';
}
},
{
filter: ['th', 'td'],
replacement: function (content, node) {
return cell(content, node);
}
},
{
filter: 'tr',
replacement: function (content, node) {
var borderCells = '';
var alignMap = { left: ':--', right: '--:', center: ':-:' };
if (node.parentNode.nodeName === 'THEAD') {
for (var i = 0; i < node.childNodes.length; i++) {
var align = node.childNodes[i].attributes.align;
var border = '---';
if (align) { border = alignMap[align.value] || border; }
borderCells += cell(border, node.childNodes[i]);
}
return '\n\n' + hPrefix + ' ' + innerHTML + '\n';
}
return '\n' + content + (borderCells ? '\n' + borderCells : '');
}
},
{
filter: 'table',
replacement: function (content) {
return '\n\n' + content + '\n\n';
}
},
{
filter: ['thead', 'tbody', 'tfoot'],
replacement: function (content) {
return content;
}
},
// Fenced code blocks
{
filter: function (node) {
return node.nodeName === 'PRE' &&
node.firstChild &&
node.firstChild.nodeName === 'CODE';
},
{
patterns: 'hr',
type: 'void',
replacement: '\n\n* * *\n'
replacement: function(content, node) {
return '\n\n```\n' + node.firstChild.textContent + '\n```\n\n';
}
},
// Syntax-highlighted code blocks
{
filter: function (node) {
return node.nodeName === 'PRE' &&
node.parentNode.nodeName === 'DIV' &&
highlightRegEx.test(node.parentNode.className);
},
{
patterns: 'a',
replacement: function(str, attrs, innerHTML) {
var href = attrs.match(attrRegExp('href')),
title = attrs.match(attrRegExp('title'));
return href ? '[' + innerHTML + ']' + '(' + href[1] + (title && title[1] ? ' "' + title[1] + '"' : '') + ')' : str;
}
replacement: function (content, node) {
var language = node.parentNode.className.match(highlightRegEx)[1];
return '\n\n```' + language + '\n' + node.textContent + '\n```\n\n';
}
},
{
filter: function (node) {
return node.nodeName === 'DIV' &&
highlightRegEx.test(node.className);
},
{
patterns: ['b', 'strong'],
replacement: function(str, attrs, innerHTML) {
return innerHTML ? '**' + innerHTML + '**' : '';
replacement: function (content) {
return '\n\n' + content + '\n\n';
}
}
];
},{}],3:[function(require,module,exports){
'use strict';
module.exports = [
{
filter: 'p',
replacement: function (content) {
return '\n\n' + content + '\n\n';
}
},
{
filter: 'br',
replacement: function () {
return ' \n';
}
},
{
filter: ['h1', 'h2', 'h3', 'h4','h5', 'h6'],
replacement: function(content, node) {
var hLevel = node.nodeName.charAt(1);
var hPrefix = '';
for(var i = 0; i < hLevel; i++) {
hPrefix += '#';
}
return '\n\n' + hPrefix + ' ' + content + '\n\n';
}
},
{
filter: 'hr',
replacement: function () {
return '\n\n* * *\n\n';
}
},
{
filter: ['em', 'i'],
replacement: function (content) {
return '_' + content + '_';
}
},
{
filter: ['strong', 'b'],
replacement: function (content) {
return '**' + content + '**';
}
},
// Inline code
{
filter: function (node) {
var hasSiblings = node.previousSibling || node.nextSibling;
var isCodeBlock = node.parentNode.nodeName === 'PRE' && !hasSiblings;
return node.nodeName === 'CODE' && !isCodeBlock;
},
{
patterns: ['i', 'em'],
replacement: function(str, attrs, innerHTML) {
return innerHTML ? '_' + innerHTML + '_' : '';
}
replacement: function(content) {
return '`' + content + '`';
}
},
{
filter: function (node) {
return node.nodeName === 'A' && node.getAttribute('href');
},
{
patterns: 'code',
replacement: function(str, attrs, innerHTML) {
return innerHTML ? '`' + he.decode(innerHTML) + '`' : '';
}
replacement: function(content, node) {
var titlePart = node.title ? ' "'+ node.title +'"' : '';
return '[' + content + '](' + node.getAttribute('href') + titlePart + ')';
}
},
{
filter: 'img',
replacement: function(content, node) {
var alt = node.alt || '';
var src = node.getAttribute('src') || '';
var title = node.title || '';
var titlePart = title ? ' "'+ title +'"' : '';
return src ? '![' + alt + ']' + '(' + src + titlePart + ')' : '';
}
},
// Code blocks
{
filter: function (node) {
return node.nodeName === 'PRE' && node.firstChild.nodeName === 'CODE';
},
{
patterns: 'img',
type: 'void',
replacement: function(str, attrs, innerHTML) {
var src = attrs.match(attrRegExp('src')),
alt = attrs.match(attrRegExp('alt')),
title = attrs.match(attrRegExp('title'));
return src ? '![' + (alt && alt[1] ? alt[1] : '') + ']' + '(' + src[1] + (title && title[1] ? ' "' + title[1] + '"' : '') + ')' : '';
}
replacement: function(content, node) {
return '\n\n ' + node.firstChild.textContent.replace(/\n/g, '\n ') + '\n\n';
}
];
},
for(var i = 0, len = ELEMENTS.length; i < len; i++) {
if(typeof ELEMENTS[i].patterns === 'string') {
string = replaceEls(string, { tag: ELEMENTS[i].patterns, replacement: ELEMENTS[i].replacement, type: ELEMENTS[i].type });
{
filter: 'blockquote',
replacement: function (content) {
content = this.trim(content);
content = content.replace(/\n{3,}/g, '\n\n');
content = content.replace(/^/gm, '> ');
return '\n\n' + content + '\n\n';
}
else {
for(var j = 0, pLen = ELEMENTS[i].patterns.length; j < pLen; j++) {
string = replaceEls(string, { tag: ELEMENTS[i].patterns[j], replacement: ELEMENTS[i].replacement, type: ELEMENTS[i].type });
},
{
filter: 'li',
replacement: function (content, node) {
content = content.replace(/^\s+/, '').replace(/\n/gm, '\n ');
var prefix = '* ';
var parent = node.parentNode;
var index = Array.prototype.indexOf.call(parent.children, node) + 1;
prefix = /ol/i.test(parent.nodeName) ? index + '. ' : '* ';
return prefix + content;
}
},
{
filter: ['ul', 'ol'],
replacement: function (content, node) {
var strings = [];
for (var i = 0; i < node.childNodes.length; i++) {
strings.push(node.childNodes[i]._replacement);
}
if (/li/i.test(node.parentNode.nodeName)) {
return '\n' + strings.join('\n');
}
return '\n\n' + strings.join('\n') + '\n\n';
}
}
},
function replaceEls(html, elProperties) {
var pattern = elProperties.type === 'void' ? '<' + elProperties.tag + '\\b([^>]*)\\/?>' : '<' + elProperties.tag + '\\b([^>]*)>([\\s\\S]*?)<\\/' + elProperties.tag + '>',
regex = new RegExp(pattern, 'gi'),
markdown = '';
if(typeof elProperties.replacement === 'string') {
markdown = html.replace(regex, elProperties.replacement);
{
filter: function (node) {
return this.isBlock(node);
},
replacement: function (content, node) {
return '\n\n' + this.outer(node, content) + '\n\n';
}
else {
markdown = html.replace(regex, function(str, p1, p2, p3) {
return elProperties.replacement.call(this, str, p1, p2, p3);
});
},
// Anything else!
{
filter: function () {
return true;
},
replacement: function (content, node) {
return this.outer(node, content);
}
return markdown;
}
];
},{}],4:[function(require,module,exports){
/**
* This file automatically generated from `build.js`.
* Do not manually edit.
*/
function attrRegExp(attr) {
return new RegExp(attr + '\\s*=\\s*["\']?([^"\']*)["\']?', 'i');
}
module.exports = [
"address",
"article",
"aside",
"audio",
"blockquote",
"canvas",
"dd",
"div",
"dl",
"fieldset",
"figcaption",
"figure",
"footer",
"form",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"header",
"hgroup",
"hr",
"noscript",
"ol",
"output",
"p",
"pre",
"section",
"table",
"tfoot",
"ul",
"video"
];
// Pre code blocks
},{}],5:[function(require,module,exports){
'use strict';
string = string.replace(/<pre\b[^>]*>`([\s\S]*?)`<\/pre>/gi, function(str, innerHTML) {
var text = he.decode(innerHTML);
text = text.replace(/^\t+/g, ' '); // convert tabs to spaces (you know it makes sense)
text = text.replace(/\n/g, '\n ');
return '\n\n ' + text + '\n';
});
var blocks = require('block-elements').map(function (name) {
return name.toUpperCase()
})
// Lists
function defaultBlockTest (node) {
return isElem(node) && blocks.indexOf(node.nodeName) >= 0
}
// Escape numbers that could trigger an ol
// If there are more than three spaces before the code, it would be in a pre tag
// Make sure we are escaping the period not matching any character
string = string.replace(/^(\s{0,3}\d+)\. /g, '$1\\. ');
function isText (node) {
return node && node.nodeType === 3
}
// Converts lists that have no child lists (of same type) first, then works its way up
var noChildrenRegex = /<(ul|ol)\b[^>]*>(?:(?!<ul|<ol)[\s\S])*?<\/\1>/gi;
while(string.match(noChildrenRegex)) {
string = string.replace(noChildrenRegex, function(str) {
return replaceLists(str);
});
}
function isElem (node) {
return node && node.nodeType === 1
}
function replaceLists(html) {
/**
* whitespace(elem [, isBlock]) removes extraneous whitespace from an
* the given element. The function isBlock may optionally be passed in
* to determine whether or not an element is a block element; if none
* is provided, defaults to using the list of block elements provided
* by the `block-elements` module.
*
* @param {Element} root
* @param {Function} isBlock
*/
function whitespace (root, isBlock) {
var startSpace = /^ /,
endSpace = / $/,
nextNode,
prevNode,
prevText,
node,
text
html = html.replace(/<(ul|ol)\b[^>]*>([\s\S]*?)<\/\1>/gi, function(str, listType, innerHTML) {
var lis = innerHTML.split('</li>');
lis.splice(lis.length - 1, 1);
if (typeof isBlock !== 'function')
isBlock = defaultBlockTest
for(i = 0, len = lis.length; i < len; i++) {
if(lis[i]) {
var prefix = (listType === 'ol') ? (i + 1) + ". " : "* ";
lis[i] = lis[i].replace(/\s*<li[^>]*>([\s\S]*)/i, function(str, innerHTML) {
function next (node) {
while (node && node !== root) {
if (node.nextSibling)
return node.nextSibling
innerHTML = innerHTML.replace(/^\s+/, '');
innerHTML = innerHTML.replace(/\n\n/g, '\n\n ');
// indent nested lists
innerHTML = innerHTML.replace(/\n([ ]*)+(\*|\d+\.) /g, '\n$1 $2 ');
return prefix + innerHTML;
});
}
lis[i] = lis[i].replace(/(.) +$/m, '$1');
node = node.parentNode
if (prevText && isBlock(node)) {
prevText.data = prevText.data.replace(/[ \r\n\t]$/, '')
prevText = null
}
return lis.join('\n');
});
}
return '\n\n' + html.replace(/[ \t]+\n|\s+$/g, '');
return null
}
// Blockquotes
var deepest = /<blockquote\b[^>]*>((?:(?!<blockquote)[\s\S])*?)<\/blockquote>/gi;
while(string.match(deepest)) {
string = string.replace(deepest, function(str) {
return replaceBlockquotes(str);
});
function first (node) {
return node.firstChild ? node.firstChild : next(node)
}
function replaceBlockquotes(html) {
html = html.replace(/<blockquote\b[^>]*>([\s\S]*?)<\/blockquote>/gi, function(str, inner) {
inner = inner.replace(/^\s+|\s+$/g, '');
inner = cleanUp(inner);
inner = inner.replace(/^/gm, '> ');
inner = inner.replace(/^(>([ \t]{2,}>)+)/gm, '> >');
return inner;
});
return html;
function remove (node) {
var nextNode = next(node)
node.parentNode.removeChild(node)
return nextNode
}
function cleanUp(string) {
string = string.replace(/^[\t\r\n]+|[\t\r\n]+$/g, ''); // trim leading/trailing whitespace
string = string.replace(/\n\s+\n/g, '\n\n');
string = string.replace(/\n{3,}/g, '\n\n'); // limit consecutive linebreaks to 2
return string;
if (root.nodeName === 'PRE') return
// Join adjacent text nodes and whatnot.
root.normalize()
node = first(root)
while (node) {
prevNode = node.previousSibling
nextNode = node.nextSibling
if (isText(node)) {
text = node.data.replace(/[ \r\n\t]+/g, ' ')
if (!prevText || prevNode && isBlock(prevNode))
text = text.replace(startSpace, '')
if (nextNode && isBlock(nextNode))
text = text.replace(endSpace, '')
if (prevText && endSpace.test(prevText.data) &&
startSpace.test(text))
text = text.substr(1)
if (text) {
node.data = text
prevText = node
node = next(node)
} else {
node = remove(node)
}
} else if (isElem(node)) {
if (node.nodeName === 'PRE') {
node = next(node)
continue
}
if (prevText && isBlock(node)) {
prevText.data = prevText.data.replace(endSpace, '')
prevText = null
}
node = first(node)
} else {
node = remove(node)
}
}
return cleanUp(string);
// Trim trailing space from last text node
if (prevText)
prevText.data = prevText.data.replace(endSpace, '')
}
, MeMarkdown = function (options, callback) {
module.exports = whitespace
},{"block-elements":4}],6:[function(require,module,exports){
},{}]},{},[1])(1)
});
var MeMarkdown = function (options, callback) {
if (typeof options === "function") {

@@ -286,6 +756,5 @@ callback = options;

};
}
;
};
root.MeMarkdown = MeMarkdown;
})(this);

@@ -1,1 +0,1 @@

!function(e){if("function"!=typeof MediumEditor)throw new Error("Medium Editor is not loaded on the page.");var t={decode:function(e,t){t=merge(t,decode.options);var n=t.strict;return n&&regexInvalidEntity.test(e)&&parseError("malformed character reference"),e.replace(regexDecode,function(e,r,a,c,o,i,p,l){var s,u,m,f,d;return r?(s=r,u=a,n&&!u&&parseError("character reference was not terminated by a semicolon"),codePointToSymbol(s,n)):c?(m=c,u=o,n&&!u&&parseError("character reference was not terminated by a semicolon"),s=parseInt(m,16),codePointToSymbol(s,n)):i?(f=i,has(decodeMap,f)?decodeMap[f]:(n&&parseError("named character reference was not terminated by a semicolon"),e)):(f=p,d=l,d&&t.isAttributeValue?(n&&"="==d&&parseError("`&` did not start a character reference"),e):(n&&parseError("named character reference was not terminated by a semicolon"),decodeMapLegacy[f]+(d||"")))})}},n=function(e){function n(e,t){var n="void"===t.type?"<"+t.tag+"\\b([^>]*)\\/?>":"<"+t.tag+"\\b([^>]*)>([\\s\\S]*?)<\\/"+t.tag+">",r=new RegExp(n,"gi"),a="";return a="string"==typeof t.replacement?e.replace(r,t.replacement):e.replace(r,function(e,n,r,a){return t.replacement.call(this,e,n,r,a)})}function r(e){return new RegExp(e+"\\s*=\\s*[\"']?([^\"']*)[\"']?","i")}function a(e){return e=e.replace(/<(ul|ol)\b[^>]*>([\s\S]*?)<\/\1>/gi,function(e,t,n){var r=n.split("</li>");for(r.splice(r.length-1,1),p=0,l=r.length;l>p;p++){if(r[p]){var a="ol"===t?p+1+". ":"* ";r[p]=r[p].replace(/\s*<li[^>]*>([\s\S]*)/i,function(e,t){return t=t.replace(/^\s+/,""),t=t.replace(/\n\n/g,"\n\n "),t=t.replace(/\n([ ]*)+(\*|\d+\.) /g,"\n$1 $2 "),a+t})}r[p]=r[p].replace(/(.) +$/m,"$1")}return r.join("\n")}),"\n\n"+e.replace(/[ \t]+\n|\s+$/g,"")}function c(e){return e=e.replace(/<blockquote\b[^>]*>([\s\S]*?)<\/blockquote>/gi,function(e,t){return t=t.replace(/^\s+|\s+$/g,""),t=o(t),t=t.replace(/^/gm,"> "),t=t.replace(/^(>([ \t]{2,}>)+)/gm,"> >")})}function o(e){return e=e.replace(/^[\t\r\n]+|[\t\r\n]+$/g,""),e=e.replace(/\n\s+\n/g,"\n\n"),e=e.replace(/\n{3,}/g,"\n\n")}for(var i=[{patterns:"p",replacement:function(e,t,n){return n?"\n\n"+n+"\n":""}},{patterns:"br",type:"void",replacement:" \n"},{patterns:"h([1-6])",replacement:function(e,t,n,r){for(var a="",c=0;t>c;c++)a+="#";return"\n\n"+a+" "+r+"\n"}},{patterns:"hr",type:"void",replacement:"\n\n* * *\n"},{patterns:"a",replacement:function(e,t,n){var a=t.match(r("href")),c=t.match(r("title"));return a?"["+n+"]("+a[1]+(c&&c[1]?' "'+c[1]+'"':"")+")":e}},{patterns:["b","strong"],replacement:function(e,t,n){return n?"**"+n+"**":""}},{patterns:["i","em"],replacement:function(e,t,n){return n?"_"+n+"_":""}},{patterns:"code",replacement:function(e,n,r){return r?"`"+t.decode(r)+"`":""}},{patterns:"img",type:"void",replacement:function(e,t){var n=t.match(r("src")),a=t.match(r("alt")),c=t.match(r("title"));return n?"!["+(a&&a[1]?a[1]:"")+"]("+n[1]+(c&&c[1]?' "'+c[1]+'"':"")+")":""}}],p=0,l=i.length;l>p;p++)if("string"==typeof i[p].patterns)e=n(e,{tag:i[p].patterns,replacement:i[p].replacement,type:i[p].type});else for(var s=0,u=i[p].patterns.length;u>s;s++)e=n(e,{tag:i[p].patterns[s],replacement:i[p].replacement,type:i[p].type});e=e.replace(/<pre\b[^>]*>`([\s\S]*?)`<\/pre>/gi,function(e,n){var r=t.decode(n);return r=r.replace(/^\t+/g," "),r=r.replace(/\n/g,"\n "),"\n\n "+r+"\n"}),e=e.replace(/^(\s{0,3}\d+)\. /g,"$1\\. ");for(var m=/<(ul|ol)\b[^>]*>(?:(?!<ul|<ol)[\s\S])*?<\/\1>/gi;e.match(m);)e=e.replace(m,function(e){return a(e)});for(var f=/<blockquote\b[^>]*>((?:(?!<blockquote)[\s\S])*?)<\/blockquote>/gi;e.match(f);)e=e.replace(f,function(e){return c(e)});return o(e)},r=function(e,t){"function"==typeof e&&(t=e,e={}),e=Object(e),e.events=e.events||["input","change"],t=t||e.callback||function(){},this.init=function(r){if(this.me=r,this.me.elements&&this.me.elements.length){this.element=this.me.elements[0];var a=function(){t(n(this.element.innerHTML).split("\n").map(function(e){return e.trim()}).join("\n").trim())}.bind(this);e.events.forEach(function(e){this.element.addEventListener(e,a)}.bind(this)),a()}}};e.MeMarkdown=r}(this);
!function(e){if("function"!=typeof MediumEditor)throw new Error("Medium Editor is not loaded on the page.");!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.toMarkdown=e()}}(function(){return function e(n,t,r){function i(a,c){if(!t[a]){if(!n[a]){var l="function"==typeof require&&require;if(!c&&l)return l(a,!0);if(o)return o(a,!0);var u=new Error("Cannot find module '"+a+"'");throw u.code="MODULE_NOT_FOUND",u}var f=t[a]={exports:{}};n[a][0].call(f.exports,function(e){var t=n[a][1][e];return i(t?t:e)},f,f.exports,e,n,t,r)}return t[a].exports}for(var o="function"==typeof require&&require,a=0;a<r.length;a++)i(r[a]);return i}({1:[function(e,n){"use strict";function t(e){return e.replace(/^[ \r\n\t]+|[ \r\n\t]+$/g,"")}function r(e){return-1!==w.indexOf(e.nodeName.toLowerCase())}function i(e){return-1!==C.indexOf(e.nodeName.toLowerCase())}function o(){var e=x.DOMParser,n=!1;try{(new e).parseFromString("","text/html")&&(n=!0)}catch(t){}return n}function a(){var e=function(){};return e.prototype.parseFromString=function(e){var n=v.implementation.createHTMLDocument("");return e.toLowerCase().indexOf("<!doctype")>-1?n.documentElement.innerHTML=e:n.body.innerHTML=e,n},e}function c(e){var n=(new E).parseFromString(e,"text/html");return y(n,r),n}function l(e){for(var n,t,r,i=[e],o=[];i.length>0;)for(n=i.shift(),o.push(n),t=n.childNodes,r=0;r<t.length;r++)1===t[r].nodeType&&i.push(t[r]);return o.shift(),o}function u(e){for(var n="",t=0;t<e.childNodes.length;t++)if(1===e.childNodes[t].nodeType)n+=e.childNodes[t]._replacement;else{if(3!==e.childNodes[t].nodeType)continue;n+=e.childNodes[t].data}return n}function f(e,n){return e.cloneNode(!1).outerHTML.replace("><",">"+n+"<")}function d(e,n){if("string"==typeof n)return n===e.nodeName.toLowerCase();if(Array.isArray(n))return-1!==n.indexOf(e.nodeName.toLowerCase());if("function"==typeof n)return n.call(h,e);throw new TypeError("`filter` needs to be a string, array, or function")}function s(e,n){var t,i,o;return"left"===e?(t=n.previousSibling,i=/ $/):(t=n.nextSibling,i=/^ /),t&&(3===t.nodeType?o=i.test(t.nodeValue):1!==t.nodeType||r(t)||(o=i.test(t.textContent))),o}function p(e){var n="",t="";if(!r(e)){var i=/^[ \r\n\t]/.test(e.innerHTML),o=/[ \r\n\t]$/.test(e.innerHTML);i&&!s("left",e)&&(n=" "),o&&!s("right",e)&&(t=" ")}return{leading:n,trailing:t}}function m(e){for(var n,r=u(e),o=0;o<g.length;o++){var a=g[o];if(d(e,a.filter)){if("function"!=typeof a.replacement)throw new TypeError("`replacement` needs to be a function that returns a string");var c=p(e);(c.leading||c.trailing)&&(r=t(r)),n=c.leading+a.replacement.call(h,r,e)+c.trailing;break}}i(e)||/A/.test(e.nodeName)||!/^\s*$/i.test(r)||(n=""),e._replacement=n}var h,g,v,N=e("./lib/md-converters"),b=e("./lib/gfm-converters"),y=e("collapse-whitespace"),x="undefined"!=typeof window?window:this;v="undefined"==typeof document?e("jsdom").jsdom():document;var w=["address","article","aside","audio","blockquote","body","canvas","center","dd","dir","div","dl","dt","fieldset","figcaption","figure","footer","form","frameset","h1","h2","h3","h4","h5","h6","header","hgroup","hr","html","isindex","li","main","menu","nav","noframes","noscript","ol","output","p","pre","section","table","tbody","td","tfoot","th","thead","tr","ul"],C=["area","base","br","col","command","embed","hr","img","input","keygen","link","meta","param","source","track","wbr"],E=o()?x.DOMParser:a();h=function(e,n){if(n=n||{},"string"!=typeof e)throw new TypeError(e+" is not a string");e=e.replace(/(\d+)\. /g,"$1\\. ");var t,r=c(e).body,i=l(r);g=N.slice(0),n.gfm&&(g=b.concat(g)),n.converters&&(g=n.converters.concat(g));for(var o=i.length-1;o>=0;o--)m(i[o]);return t=u(r),t.replace(/^[\t\r\n]+|[\t\r\n\s]+$/g,"").replace(/\n\s+\n/g,"\n\n").replace(/\n{3,}/g,"\n\n")},h.isBlock=r,h.isVoid=i,h.trim=t,h.outer=f,n.exports=h},{"./lib/gfm-converters":2,"./lib/md-converters":3,"collapse-whitespace":5,jsdom:6}],2:[function(e,n){"use strict";function t(e,n){var t=Array.prototype.indexOf.call(n.parentNode.childNodes,n),r=" ";return 0===t&&(r="| "),r+e+" |"}var r=/highlight highlight-(\S+)/;n.exports=[{filter:"br",replacement:function(){return"\n"}},{filter:["del","s","strike"],replacement:function(e){return"~~"+e+"~~"}},{filter:function(e){return"checkbox"===e.type&&"LI"===e.parentNode.nodeName},replacement:function(e,n){return(n.checked?"[x]":"[ ]")+" "}},{filter:["th","td"],replacement:function(e,n){return t(e,n)}},{filter:"tr",replacement:function(e,n){var r="",i={left:":--",right:"--:",center:":-:"};if("THEAD"===n.parentNode.nodeName)for(var o=0;o<n.childNodes.length;o++){var a=n.childNodes[o].attributes.align,c="---";a&&(c=i[a.value]||c),r+=t(c,n.childNodes[o])}return"\n"+e+(r?"\n"+r:"")}},{filter:"table",replacement:function(e){return"\n\n"+e+"\n\n"}},{filter:["thead","tbody","tfoot"],replacement:function(e){return e}},{filter:function(e){return"PRE"===e.nodeName&&e.firstChild&&"CODE"===e.firstChild.nodeName},replacement:function(e,n){return"\n\n```\n"+n.firstChild.textContent+"\n```\n\n"}},{filter:function(e){return"PRE"===e.nodeName&&"DIV"===e.parentNode.nodeName&&r.test(e.parentNode.className)},replacement:function(e,n){var t=n.parentNode.className.match(r)[1];return"\n\n```"+t+"\n"+n.textContent+"\n```\n\n"}},{filter:function(e){return"DIV"===e.nodeName&&r.test(e.className)},replacement:function(e){return"\n\n"+e+"\n\n"}}]},{}],3:[function(e,n){"use strict";n.exports=[{filter:"p",replacement:function(e){return"\n\n"+e+"\n\n"}},{filter:"br",replacement:function(){return" \n"}},{filter:["h1","h2","h3","h4","h5","h6"],replacement:function(e,n){for(var t=n.nodeName.charAt(1),r="",i=0;t>i;i++)r+="#";return"\n\n"+r+" "+e+"\n\n"}},{filter:"hr",replacement:function(){return"\n\n* * *\n\n"}},{filter:["em","i"],replacement:function(e){return"_"+e+"_"}},{filter:["strong","b"],replacement:function(e){return"**"+e+"**"}},{filter:function(e){var n=e.previousSibling||e.nextSibling,t="PRE"===e.parentNode.nodeName&&!n;return"CODE"===e.nodeName&&!t},replacement:function(e){return"`"+e+"`"}},{filter:function(e){return"A"===e.nodeName&&e.getAttribute("href")},replacement:function(e,n){var t=n.title?' "'+n.title+'"':"";return"["+e+"]("+n.getAttribute("href")+t+")"}},{filter:"img",replacement:function(e,n){var t=n.alt||"",r=n.getAttribute("src")||"",i=n.title||"",o=i?' "'+i+'"':"";return r?"!["+t+"]("+r+o+")":""}},{filter:function(e){return"PRE"===e.nodeName&&"CODE"===e.firstChild.nodeName},replacement:function(e,n){return"\n\n "+n.firstChild.textContent.replace(/\n/g,"\n ")+"\n\n"}},{filter:"blockquote",replacement:function(e){return e=this.trim(e),e=e.replace(/\n{3,}/g,"\n\n"),e=e.replace(/^/gm,"> "),"\n\n"+e+"\n\n"}},{filter:"li",replacement:function(e,n){e=e.replace(/^\s+/,"").replace(/\n/gm,"\n ");var t="* ",r=n.parentNode,i=Array.prototype.indexOf.call(r.children,n)+1;return t=/ol/i.test(r.nodeName)?i+". ":"* ",t+e}},{filter:["ul","ol"],replacement:function(e,n){for(var t=[],r=0;r<n.childNodes.length;r++)t.push(n.childNodes[r]._replacement);return/li/i.test(n.parentNode.nodeName)?"\n"+t.join("\n"):"\n\n"+t.join("\n")+"\n\n"}},{filter:function(e){return this.isBlock(e)},replacement:function(e,n){return"\n\n"+this.outer(n,e)+"\n\n"}},{filter:function(){return!0},replacement:function(e,n){return this.outer(n,e)}}]},{}],4:[function(e,n){n.exports=["address","article","aside","audio","blockquote","canvas","dd","div","dl","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","header","hgroup","hr","noscript","ol","output","p","pre","section","table","tfoot","ul","video"]},{}],5:[function(e,n){"use strict";function t(e){return i(e)&&a.indexOf(e.nodeName)>=0}function r(e){return e&&3===e.nodeType}function i(e){return e&&1===e.nodeType}function o(e,n){function o(t){for(;t&&t!==e;){if(t.nextSibling)return t.nextSibling;t=t.parentNode,f&&n(t)&&(f.data=f.data.replace(/[ \r\n\t]$/,""),f=null)}return null}function a(e){return e.firstChild?e.firstChild:o(e)}function c(e){var n=o(e);return e.parentNode.removeChild(e),n}var l,u,f,d,s,p=/^ /,m=/ $/;if("function"!=typeof n&&(n=t),"PRE"!==e.nodeName){for(e.normalize(),d=a(e);d;)if(u=d.previousSibling,l=d.nextSibling,r(d))s=d.data.replace(/[ \r\n\t]+/g," "),(!f||u&&n(u))&&(s=s.replace(p,"")),l&&n(l)&&(s=s.replace(m,"")),f&&m.test(f.data)&&p.test(s)&&(s=s.substr(1)),s?(d.data=s,f=d,d=o(d)):d=c(d);else if(i(d)){if("PRE"===d.nodeName){d=o(d);continue}f&&n(d)&&(f.data=f.data.replace(m,""),f=null),d=a(d)}else d=c(d);f&&(f.data=f.data.replace(m,""))}}var a=e("block-elements").map(function(e){return e.toUpperCase()});n.exports=o},{"block-elements":4}],6:[function(){},{}]},{},[1])(1)});var n=function(e,n){"function"==typeof e&&(n=e,e={}),e=Object(e),e.events=e.events||["input","change"],n=n||e.callback||function(){},this.init=function(t){if(this.me=t,this.me.elements&&this.me.elements.length){this.element=this.me.elements[0];var r=function(){n(toMarkdown(this.element.innerHTML).split("\n").map(function(e){return e.trim()}).join("\n").trim())}.bind(this);e.events.forEach(function(e){this.element.addEventListener(e,r)}.bind(this)),r()}}};e.MeMarkdown=n}(this);
window.addEventListener("load", function () {
var markDownEl = document.querySelector(".editor > .right > pre");
new MediumEditor(document.querySelector(".editor > .left"), {
extensions: {
buttons: ["bold", "italic", "underline", "orderedlist", "unorderedlist", "anchor", "header1", "header2", "quote"]
, extensions: {
markdown: new MeMarkdown(function (md) {

@@ -6,0 +7,0 @@ markDownEl.innerText = md;

{
"name": "medium-editor-markdown",
"version": "1.1.0",
"version": "1.2.0",
"description": "A Medium Editor extension to add markdown support.",

@@ -18,5 +18,4 @@ "main": "src/medium-editor-md.js",

"dependencies": {
"he": "^0.5.0",
"mustache": "^1.0.0",
"to-markdown": "^0.0.3",
"to-markdown": "1.2.0",
"uglify-js": "2.4.16"

@@ -23,0 +22,0 @@ },

@@ -17,3 +17,3 @@ [![Medium Editor Markdown](http://i.imgur.com/xb6JPkv.png)](http://ionicabizau.github.io/medium-editor-markdown/)

The `*.no-deps.*` scripts contain only the extension code. You will have to include manually [`he.js`](https://github.com/mathiasbynens/he) and [`to-markdown.js`](https://github.com/domchristie/to-markdown) on the page, before including the markdown extension.
The `*.no-deps.*` scripts contain only the extension code. You will have to include manually [`to-markdown.js`](https://github.com/domchristie/to-markdown) on the page, before including the markdown extension.

@@ -50,3 +50,2 @@ The `*.min.*` scripts are minified.

- [**@domchristie**](https://github.com/domchristie/) for creating [to-markdown](https://github.com/domchristie/to-markdown).
- [**@mathiasbynens**](https://github.com/mathiasbynens/), the author of [he.js](https://github.com/mathiasbynens/he).

@@ -53,0 +52,0 @@ ## Building

@@ -6,8 +6,7 @@ (function (root) {

var he = { decode: {{{he.decode}}} }
, toMarkdown = {{{toMarkdown}}}
, MeMarkdown = {{{MeMarkdown}}}
;
{{{toMarkdown}}}
var MeMarkdown = {{{MeMarkdown}}};
root.MeMarkdown = MeMarkdown;
})(this);

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc