Socket
Socket
Sign inDemoInstall

tiptap-markdown

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiptap-markdown - npm Package Compare versions

Comparing version 0.8.2 to 0.8.3

dist/tiptap-markdown.es.js

611

dist/tiptap-markdown.umd.js

@@ -1,12 +0,5 @@

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@tiptap/core'), require('prosemirror-markdown'), require('markdown-it'), require('@tiptap/pm/model'), require('markdown-it-task-lists'), require('@tiptap/pm/state')) :
typeof define === 'function' && define.amd ? define(['exports', '@tiptap/core', 'prosemirror-markdown', 'markdown-it', '@tiptap/pm/model', 'markdown-it-task-lists', '@tiptap/pm/state'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global['tiptap-markdown'] = {}, global.core, global.prosemirrorMarkdown, global.markdownit, global.model, global.taskListPlugin, global.state));
}(this, (function (exports, core, prosemirrorMarkdown, markdownit, model, taskListPlugin, state) { 'use strict';
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var markdownit__default = /*#__PURE__*/_interopDefaultLegacy(markdownit);
var taskListPlugin__default = /*#__PURE__*/_interopDefaultLegacy(taskListPlugin);
(function(global, factory) {
typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("@tiptap/core"), require("prosemirror-markdown"), require("markdown-it"), require("@tiptap/pm/model"), require("markdown-it-task-lists"), require("@tiptap/pm/state")) : typeof define === "function" && define.amd ? define(["exports", "@tiptap/core", "prosemirror-markdown", "markdown-it", "@tiptap/pm/model", "markdown-it-task-lists", "@tiptap/pm/state"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global["tiptap-markdown"] = {}, global.core, global.prosemirrorMarkdown, global.markdownit, global.model, global.taskListPlugin, global.state));
})(this, function(exports2, core, prosemirrorMarkdown, markdownit, model, taskListPlugin, state) {
"use strict";
function ownKeys(object, enumerableOnly) {

@@ -16,3 +9,3 @@ var keys = Object.keys(object);

var symbols = Object.getOwnPropertySymbols(object);
enumerableOnly && (symbols = symbols.filter(function (sym) {
enumerableOnly && (symbols = symbols.filter(function(sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;

@@ -26,5 +19,5 @@ })), keys.push.apply(keys, symbols);

var source = null != arguments[i] ? arguments[i] : {};
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
i % 2 ? ownKeys(Object(source), true).forEach(function(key) {
_defineProperty(target, key, source[key]);
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function(key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));

@@ -45,3 +38,4 @@ });

descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
if ("value" in descriptor)
descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);

@@ -51,4 +45,6 @@ }

function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
if (protoProps)
_defineProperties(Constructor.prototype, protoProps);
if (staticProps)
_defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {

@@ -63,3 +59,3 @@ writable: false

Object.defineProperty(obj, key, {
value: value,
value,
enumerable: true,

@@ -88,7 +84,8 @@ configurable: true,

});
if (superClass) _setPrototypeOf(subClass, superClass);
if (superClass)
_setPrototypeOf(subClass, superClass);
}
function _getPrototypeOf(o) {
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) {
return o.__proto__ || Object.getPrototypeOf(o);
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf2(o2) {
return o2.__proto__ || Object.getPrototypeOf(o2);
};

@@ -98,5 +95,5 @@ return _getPrototypeOf(o);

function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf2(o2, p2) {
o2.__proto__ = p2;
return o2;
};

@@ -106,7 +103,11 @@ return _setPrototypeOf(o, p);

function _isNativeReflectConstruct() {
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
if (Reflect.construct.sham) return false;
if (typeof Proxy === "function") return true;
if (typeof Reflect === "undefined" || !Reflect.construct)
return false;
if (Reflect.construct.sham)
return false;
if (typeof Proxy === "function")
return true;
try {
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {}));
Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {
}));
return true;

@@ -117,9 +118,9 @@ } catch (e) {

}
function _assertThisInitialized(self) {
if (self === void 0) {
function _assertThisInitialized(self2) {
if (self2 === void 0) {
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
}
return self;
return self2;
}
function _possibleConstructorReturn(self, call) {
function _possibleConstructorReturn(self2, call) {
if (call && (typeof call === "object" || typeof call === "function")) {

@@ -130,3 +131,3 @@ return call;

}
return _assertThisInitialized(self);
return _assertThisInitialized(self2);
}

@@ -136,4 +137,3 @@ function _createSuper(Derived) {

return function _createSuperInternal() {
var Super = _getPrototypeOf(Derived),
result;
var Super = _getPrototypeOf(Derived), result;
if (hasNativeReflectConstruct) {

@@ -151,3 +151,4 @@ var NewTarget = _getPrototypeOf(this).constructor;

object = _getPrototypeOf(object);
if (object === null) break;
if (object === null)
break;
}

@@ -160,5 +161,6 @@ return object;

} else {
_get = function _get(target, property, receiver) {
_get = function _get2(target, property, receiver) {
var base = _superPropBase(target, property);
if (!base) return;
if (!base)
return;
var desc = Object.getOwnPropertyDescriptor(base, property);

@@ -177,18 +179,27 @@ if (desc.get) {

function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
if (Array.isArray(arr))
return _arrayLikeToArray(arr);
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null)
return Array.from(iter);
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
if (!o)
return;
if (typeof o === "string")
return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
if (n === "Object" && o.constructor)
n = o.constructor.name;
if (n === "Map" || n === "Set")
return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n))
return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
if (len == null || len > arr.length)
len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++)
arr2[i] = arr[i];
return arr2;

@@ -200,7 +211,9 @@ }

function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
if (typeof input !== "object" || input === null)
return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
if (prim !== void 0) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
if (typeof res !== "object")
return res;
throw new TypeError("@@toPrimitive must return a primitive value.");

@@ -214,10 +227,9 @@ }

}
var MarkdownTightLists = core.Extension.create({
name: 'markdownTightLists',
name: "markdownTightLists",
addOptions: function addOptions() {
return {
tight: true,
tightClass: 'tight',
listTypes: ['bulletList', 'orderedList']
tightClass: "tight",
listTypes: ["bulletList", "orderedList"]
};

@@ -233,3 +245,3 @@ },

parseHTML: function parseHTML(element) {
return element.getAttribute('data-tight') === 'true' || !element.querySelector('p');
return element.getAttribute("data-tight") === "true" || !element.querySelector("p");
},

@@ -239,3 +251,3 @@ renderHTML: function renderHTML(attributes) {

"class": attributes.tight ? _this.options.tightClass : null,
'data-tight': attributes.tight ? 'true' : null
"data-tight": attributes.tight ? "true" : null
};

@@ -251,7 +263,6 @@ }

toggleTight: function toggleTight() {
var tight = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
return function (_ref) {
var editor = _ref.editor,
commands = _ref.commands;
function toggleTight(name) {
var tight = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : null;
return function(_ref) {
var editor = _ref.editor, commands = _ref.commands;
function toggleTight2(name) {
if (!editor.isActive(name)) {

@@ -265,4 +276,4 @@ return false;

}
return _this2.options.listTypes.some(function (name) {
return toggleTight(name);
return _this2.options.listTypes.some(function(name) {
return toggleTight2(name);
});

@@ -274,4 +285,3 @@ };

});
var md = markdownit__default['default']();
var md = markdownit();
function scanDelims(text, pos) {

@@ -282,4 +292,4 @@ md.inline.State.prototype.scanDelims.call({

});
var state = new md.inline.State(text, null, null, []);
return state.scanDelims(pos, true);
var state2 = new md.inline.State(text, null, null, []);
return state2.scanDelims(pos, true);
}

@@ -292,4 +302,3 @@ function shiftDelim(text, delim, start, offset) {

function trimStart(text, delim, from, to) {
var pos = from,
res = text;
var pos = from, res = text;
while (pos < to) {

@@ -305,8 +314,7 @@ if (scanDelims(res, pos).can_open) {

from: pos,
to: to
to
};
}
function trimEnd(text, delim, from, to) {
var pos = to,
res = text;
var pos = to, res = text;
while (pos > from) {

@@ -321,3 +329,3 @@ if (scanDelims(res, pos).can_close) {

text: res,
from: from,
from,
to: pos

@@ -327,25 +335,20 @@ };

function trimInline(text, delim, from, to) {
var state = {
text: text,
from: from,
to: to
var state2 = {
text,
from,
to
};
state = trimStart(state.text, delim, state.from, state.to);
state = trimEnd(state.text, delim, state.from, state.to);
if (state.to - state.from < delim.length + 1) {
state.text = state.text.substring(0, state.from) + state.text.substring(state.to + delim.length);
state2 = trimStart(state2.text, delim, state2.from, state2.to);
state2 = trimEnd(state2.text, delim, state2.from, state2.to);
if (state2.to - state2.from < delim.length + 1) {
state2.text = state2.text.substring(0, state2.from) + state2.text.substring(state2.to + delim.length);
}
return state.text;
return state2.text;
}
/**
* Override default MarkdownSerializerState to:
* - handle commonmark delimiters (https://spec.commonmark.org/0.29/#left-flanking-delimiter-run)
*/
var MarkdownSerializerState = /*#__PURE__*/function (_BaseMarkdownSerializ) {
_inherits(MarkdownSerializerState, _BaseMarkdownSerializ);
var _super = _createSuper(MarkdownSerializerState);
function MarkdownSerializerState(nodes, marks, options) {
var MarkdownSerializerState = /* @__PURE__ */ function(_BaseMarkdownSerializ) {
_inherits(MarkdownSerializerState2, _BaseMarkdownSerializ);
var _super = _createSuper(MarkdownSerializerState2);
function MarkdownSerializerState2(nodes, marks, options) {
var _this;
_classCallCheck(this, MarkdownSerializerState);
_classCallCheck(this, MarkdownSerializerState2);
_this = _super.call(this, nodes, marks, options !== null && options !== void 0 ? options : {});

@@ -355,12 +358,9 @@ _this.inlines = [];

}
_createClass(MarkdownSerializerState, [{
_createClass(MarkdownSerializerState2, [{
key: "render",
value: function render(node, parent, index) {
_get(_getPrototypeOf(MarkdownSerializerState.prototype), "render", this).call(this, node, parent, index);
_get(_getPrototypeOf(MarkdownSerializerState2.prototype), "render", this).call(this, node, parent, index);
var top = this.inlines[this.inlines.length - 1];
if (top !== null && top !== void 0 && top.start && top !== null && top !== void 0 && top.end) {
var _this$normalizeInline = this.normalizeInline(top),
delimiter = _this$normalizeInline.delimiter,
start = _this$normalizeInline.start,
end = _this$normalizeInline.end;
var _this$normalizeInline = this.normalizeInline(top), delimiter = _this$normalizeInline.delimiter, start = _this$normalizeInline.start, end = _this$normalizeInline.end;
this.out = trimInline(this.out, delimiter, start, end);

@@ -387,3 +387,3 @@ this.inlines.pop();

}
return _get(_getPrototypeOf(MarkdownSerializerState.prototype), "markString", this).call(this, mark, open, parent, index);
return _get(_getPrototypeOf(MarkdownSerializerState2.prototype), "markString", this).call(this, mark, open, parent, index);
}

@@ -394,3 +394,3 @@ }, {

var start = inline.start;
inline.end;
inline.end;
while (this.out.charAt(start).match(/\s/)) {

@@ -400,11 +400,10 @@ start++;

return _objectSpread2(_objectSpread2({}, inline), {}, {
start: start
start
});
}
}]);
return MarkdownSerializerState;
return MarkdownSerializerState2;
}(prosemirrorMarkdown.MarkdownSerializerState);
var HTMLMark = core.Mark.create({
name: 'markdownHTMLMark',
const HTMLMark = core.Mark.create({
name: "markdownHTMLMark",
/**

@@ -417,16 +416,16 @@ * @return {{markdown: MarkdownMarkSpec}}

serialize: {
open: function open(state, mark) {
open: function open(state2, mark) {
var _getMarkTags$, _getMarkTags;
if (!this.editor.storage.markdown.options.html) {
console.warn("Tiptap Markdown: \"".concat(mark.type.name, "\" mark is only available in html mode"));
return '';
console.warn('Tiptap Markdown: "'.concat(mark.type.name, '" mark is only available in html mode'));
return "";
}
return (_getMarkTags$ = (_getMarkTags = getMarkTags(mark)) === null || _getMarkTags === void 0 ? void 0 : _getMarkTags[0]) !== null && _getMarkTags$ !== void 0 ? _getMarkTags$ : '';
return (_getMarkTags$ = (_getMarkTags = getMarkTags(mark)) === null || _getMarkTags === void 0 ? void 0 : _getMarkTags[0]) !== null && _getMarkTags$ !== void 0 ? _getMarkTags$ : "";
},
close: function close(state, mark) {
close: function close(state2, mark) {
var _getMarkTags$2, _getMarkTags2;
if (!this.editor.storage.markdown.options.html) {
return '';
return "";
}
return (_getMarkTags$2 = (_getMarkTags2 = getMarkTags(mark)) === null || _getMarkTags2 === void 0 ? void 0 : _getMarkTags2[1]) !== null && _getMarkTags$2 !== void 0 ? _getMarkTags$2 : '';
return (_getMarkTags$2 = (_getMarkTags2 = getMarkTags(mark)) === null || _getMarkTags2 === void 0 ? void 0 : _getMarkTags2[1]) !== null && _getMarkTags$2 !== void 0 ? _getMarkTags$2 : "";
}

@@ -443,3 +442,3 @@ },

var schema = mark.type.schema;
var node = schema.text(' ', [mark]);
var node = schema.text(" ", [mark]);
var html = core.getHTMLFromFragment(model.Fragment.from(node), schema);

@@ -449,10 +448,8 @@ var match = html.match(/^(<.*?>) (<\/.*?>)$/);

}
function elementFromString(value) {
// add a wrapper to preserve leading and trailing whitespace
var wrappedValue = "<body>".concat(value, "</body>");
return new window.DOMParser().parseFromString(wrappedValue, 'text/html').body;
return new window.DOMParser().parseFromString(wrappedValue, "text/html").body;
}
function escapeHTML(value) {
return value === null || value === void 0 ? void 0 : value.replace(/</g, '&lt;').replace(/>/g, '&gt;');
return value === null || value === void 0 ? void 0 : value.replace(/</g, "&lt;").replace(/>/g, "&gt;");
}

@@ -480,17 +477,16 @@ function extractElement(node) {

}
var HTMLNode = core.Node.create({
name: 'markdownHTMLNode',
const HTMLNode = core.Node.create({
name: "markdownHTMLNode",
addStorage: function addStorage() {
return {
markdown: {
serialize: function serialize(state, node, parent) {
serialize: function serialize(state2, node, parent) {
if (this.editor.storage.markdown.options.html) {
state.write(serializeHTML(node, parent));
state2.write(serializeHTML(node, parent));
} else {
console.warn("Tiptap Markdown: \"".concat(node.type.name, "\" node is only available in html mode"));
state.write("[".concat(node.type.name, "]"));
console.warn('Tiptap Markdown: "'.concat(node.type.name, '" node is only available in html mode'));
state2.write("[".concat(node.type.name, "]"));
}
if (node.isBlock) {
state.closeBlock(node);
state2.closeBlock(node);
}

@@ -508,3 +504,3 @@ },

var html = core.getHTMLFromFragment(model.Fragment.from(node), schema);
if (node.isBlock && parent.type.name === schema.topNodeType.name) {
if (node.isBlock && (parent instanceof model.Fragment || parent.type.name === schema.topNodeType.name)) {
return formatBlock(html);

@@ -514,6 +510,2 @@ }

}
/**
* format html block as per the commonmark spec
*/
function formatBlock(html) {

@@ -525,7 +517,6 @@ var dom = elementFromString(html);

}
var Blockquote = core.Node.create({
name: 'blockquote'
name: "blockquote"
});
var Blockquote$1 = Blockquote.extend({
const Blockquote$1 = Blockquote.extend({
/**

@@ -545,7 +536,6 @@ * @return {{markdown: MarkdownNodeSpec}}

});
var BulletList = core.Node.create({
name: 'bulletList'
name: "bulletList"
});
var BulletList$1 = BulletList.extend({
const BulletList$1 = BulletList.extend({
/**

@@ -557,5 +547,5 @@ * @return {{markdown: MarkdownNodeSpec}}

markdown: {
serialize: function serialize(state, node) {
serialize: function serialize(state2, node) {
var _this = this;
return state.renderList(node, " ", function () {
return state2.renderList(node, " ", function() {
return (_this.editor.storage.markdown.options.bulletListMarker || "-") + " ";

@@ -571,7 +561,6 @@ });

});
var CodeBlock = core.Node.create({
name: 'codeBlock'
name: "codeBlock"
});
var CodeBlock$1 = CodeBlock.extend({
const CodeBlock$1 = CodeBlock.extend({
/**

@@ -583,18 +572,18 @@ * @return {{markdown: MarkdownNodeSpec}}

markdown: {
serialize: function serialize(state, node) {
state.write("```" + (node.attrs.language || "") + "\n");
state.text(node.textContent, false);
state.ensureNewLine();
state.write("```");
state.closeBlock(node);
serialize: function serialize(state2, node) {
state2.write("```" + (node.attrs.language || "") + "\n");
state2.text(node.textContent, false);
state2.ensureNewLine();
state2.write("```");
state2.closeBlock(node);
},
parse: {
setup: function setup(markdownit) {
setup: function setup(markdownit2) {
var _this$options$languag;
markdownit.set({
langPrefix: (_this$options$languag = this.options.languageClassPrefix) !== null && _this$options$languag !== void 0 ? _this$options$languag : 'language-'
markdownit2.set({
langPrefix: (_this$options$languag = this.options.languageClassPrefix) !== null && _this$options$languag !== void 0 ? _this$options$languag : "language-"
});
},
updateDOM: function updateDOM(element) {
element.innerHTML = element.innerHTML.replace(/\n<\/code><\/pre>/g, '</code></pre>');
element.innerHTML = element.innerHTML.replace(/\n<\/code><\/pre>/g, "</code></pre>");
}

@@ -606,7 +595,6 @@ }

});
var HardBreak = core.Node.create({
name: 'hardBreak'
name: "hardBreak"
});
var HardBreak$1 = HardBreak.extend({
const HardBreak$1 = HardBreak.extend({
/**

@@ -626,7 +614,6 @@ * @return {{markdown: MarkdownNodeSpec}}

});
var Heading = core.Node.create({
name: 'heading'
name: "heading"
});
var Heading$1 = Heading.extend({
const Heading$1 = Heading.extend({
/**

@@ -646,7 +633,6 @@ * @return {{markdown: MarkdownNodeSpec}}

});
var HorizontalRule = core.Node.create({
name: 'horizontalRule'
name: "horizontalRule"
});
var HorizontalRule$1 = HorizontalRule.extend({
const HorizontalRule$1 = HorizontalRule.extend({
/**

@@ -666,7 +652,6 @@ * @return {{markdown: MarkdownNodeSpec}}

});
var Image = core.Node.create({
name: 'image'
name: "image"
});
var Image$1 = Image.extend({
const Image$1 = Image.extend({
/**

@@ -686,7 +671,6 @@ * @return {{markdown: MarkdownNodeSpec}}

});
var ListItem = core.Node.create({
name: 'listItem'
name: "listItem"
});
var ListItem$1 = ListItem.extend({
const ListItem$1 = ListItem.extend({
/**

@@ -706,7 +690,6 @@ * @return {{markdown: MarkdownNodeSpec}}

});
var OrderedList = core.Node.create({
name: 'orderedList'
name: "orderedList"
});
var OrderedList$1 = OrderedList.extend({
const OrderedList$1 = OrderedList.extend({
/**

@@ -726,7 +709,6 @@ * @return {{markdown: MarkdownNodeSpec}}

});
var Paragraph = core.Node.create({
name: 'paragraph'
name: "paragraph"
});
var Paragraph$1 = Paragraph.extend({
const Paragraph$1 = Paragraph.extend({
/**

@@ -746,3 +728,2 @@ * @return {{markdown: MarkdownNodeSpec}}

});
function childNodes(node) {

@@ -752,7 +733,6 @@ var _node$content$content, _node$content;

}
var Table = core.Node.create({
name: 'table'
name: "table"
});
var Table$1 = Table.extend({
const Table$1 = Table.extend({
/**

@@ -764,31 +744,31 @@ * @return {{markdown: MarkdownNodeSpec}}

markdown: {
serialize: function serialize(state, node, parent) {
serialize: function serialize(state2, node, parent) {
if (!isMarkdownSerializable(node)) {
HTMLNode.storage.markdown.serialize.call(this, state, node, parent);
HTMLNode.storage.markdown.serialize.call(this, state2, node, parent);
return;
}
node.forEach(function (row, p, i) {
state.write('| ');
row.forEach(function (col, p, j) {
node.forEach(function(row, p, i) {
state2.write("| ");
row.forEach(function(col, p2, j) {
if (j) {
state.write(' | ');
state2.write(" | ");
}
var cellContent = col.firstChild;
if (cellContent.textContent.trim()) {
state.renderInline(cellContent);
state2.renderInline(cellContent);
}
});
state.write(' |');
state.ensureNewLine();
state2.write(" |");
state2.ensureNewLine();
if (!i) {
var delimiterRow = Array.from({
length: row.childCount
}).map(function () {
return '---';
}).join(' | ');
state.write("| ".concat(delimiterRow, " |"));
state.ensureNewLine();
}).map(function() {
return "---";
}).join(" | ");
state2.write("| ".concat(delimiterRow, " |"));
state2.ensureNewLine();
}
});
state.closeBlock(node);
state2.closeBlock(node);
},

@@ -809,10 +789,10 @@ parse: {

var bodyRows = rows.slice(1);
if (childNodes(firstRow).some(function (cell) {
return cell.type.name !== 'tableHeader' || hasSpan(cell);
if (childNodes(firstRow).some(function(cell) {
return cell.type.name !== "tableHeader" || hasSpan(cell) || cell.childCount > 1;
})) {
return false;
}
if (bodyRows.some(function (row) {
return childNodes(row).some(function (cell) {
return cell.type.name === 'tableHeader' || hasSpan(cell);
if (bodyRows.some(function(row) {
return childNodes(row).some(function(cell) {
return cell.type.name === "tableHeader" || hasSpan(cell) || cell.childCount > 1;
});

@@ -824,7 +804,6 @@ })) {

}
var TaskItem = core.Node.create({
name: 'taskItem'
name: "taskItem"
});
var TaskItem$1 = TaskItem.extend({
const TaskItem$1 = TaskItem.extend({
/**

@@ -836,14 +815,14 @@ * @return {{markdown: MarkdownNodeSpec}}

markdown: {
serialize: function serialize(state, node) {
var check = node.attrs.checked ? '[x]' : '[ ]';
state.write("".concat(check, " "));
state.renderContent(node);
serialize: function serialize(state2, node) {
var check = node.attrs.checked ? "[x]" : "[ ]";
state2.write("".concat(check, " "));
state2.renderContent(node);
},
parse: {
updateDOM: function updateDOM(element) {
_toConsumableArray(element.querySelectorAll('.task-list-item')).forEach(function (item) {
var input = item.querySelector('input');
item.setAttribute('data-type', 'taskItem');
_toConsumableArray(element.querySelectorAll(".task-list-item")).forEach(function(item) {
var input = item.querySelector("input");
item.setAttribute("data-type", "taskItem");
if (input) {
item.setAttribute('data-checked', input.checked);
item.setAttribute("data-checked", input.checked);
input.remove();

@@ -858,7 +837,6 @@ }

});
var TaskList = core.Node.create({
name: 'taskList'
name: "taskList"
});
var TaskList$1 = TaskList.extend({
const TaskList$1 = TaskList.extend({
/**

@@ -872,8 +850,8 @@ * @return {{markdown: MarkdownNodeSpec}}

parse: {
setup: function setup(markdownit) {
markdownit.use(taskListPlugin__default['default']);
setup: function setup(markdownit2) {
markdownit2.use(taskListPlugin);
},
updateDOM: function updateDOM(element) {
_toConsumableArray(element.querySelectorAll('.contains-task-list')).forEach(function (list) {
list.setAttribute('data-type', 'taskList');
_toConsumableArray(element.querySelectorAll(".contains-task-list")).forEach(function(list) {
list.setAttribute("data-type", "taskList");
});

@@ -886,7 +864,6 @@ }

});
var Text = core.Node.create({
name: 'text'
name: "text"
});
var Text$1 = Text.extend({
const Text$1 = Text.extend({
/**

@@ -898,4 +875,4 @@ * @return {{markdown: MarkdownNodeSpec}}

markdown: {
serialize: function serialize(state, node) {
state.text(escapeHTML(node.text));
serialize: function serialize(state2, node) {
state2.text(escapeHTML(node.text));
},

@@ -909,7 +886,6 @@ parse: {

});
var Bold = core.Mark.create({
name: 'bold'
name: "bold"
});
var Bold$1 = Bold.extend({
const Bold$1 = Bold.extend({
/**

@@ -929,7 +905,6 @@ * @return {{markdown: MarkdownMarkSpec}}

});
var Code = core.Mark.create({
name: 'code'
name: "code"
});
var Code$1 = Code.extend({
const Code$1 = Code.extend({
/**

@@ -949,7 +924,6 @@ * @return {{markdown: MarkdownMarkSpec}}

});
var Italic = core.Mark.create({
name: 'italic'
name: "italic"
});
var Italic$1 = Italic.extend({
const Italic$1 = Italic.extend({
/**

@@ -969,7 +943,6 @@ * @return {{markdown: MarkdownMarkSpec}}

});
var Link = core.Mark.create({
name: 'link'
name: "link"
});
var Link$1 = Link.extend({
const Link$1 = Link.extend({
/**

@@ -989,7 +962,6 @@ * @return {{markdown: MarkdownMarkSpec}}

});
var Strike = core.Mark.create({
name: 'strike'
name: "strike"
});
var Strike$1 = Strike.extend({
const Strike$1 = Strike.extend({
/**

@@ -1002,4 +974,4 @@ * @return {{markdown: MarkdownMarkSpec}}

serialize: {
open: '~~',
close: '~~',
open: "~~",
close: "~~",
expelEnclosingWhitespace: true

@@ -1014,9 +986,7 @@ },

});
var markdownExtensions = [Blockquote$1, BulletList$1, CodeBlock$1, HardBreak$1, Heading$1, HorizontalRule$1, HTMLNode, Image$1, ListItem$1, OrderedList$1, Paragraph$1, Table$1, TaskItem$1, TaskList$1, Text$1, Bold$1, Code$1, HTMLMark, Italic$1, Link$1, Strike$1];
const markdownExtensions = [Blockquote$1, BulletList$1, CodeBlock$1, HardBreak$1, Heading$1, HorizontalRule$1, HTMLNode, Image$1, ListItem$1, OrderedList$1, Paragraph$1, Table$1, TaskItem$1, TaskList$1, Text$1, Bold$1, Code$1, HTMLMark, Italic$1, Link$1, Strike$1];
function getMarkdownSpec(extension) {
var _extension$storage, _markdownExtensions$f;
var markdownSpec = (_extension$storage = extension.storage) === null || _extension$storage === void 0 ? void 0 : _extension$storage.markdown;
var defaultMarkdownSpec = (_markdownExtensions$f = markdownExtensions.find(function (e) {
var defaultMarkdownSpec = (_markdownExtensions$f = markdownExtensions.find(function(e) {
return e.name === extension.name;

@@ -1029,21 +999,16 @@ })) === null || _markdownExtensions$f === void 0 ? void 0 : _markdownExtensions$f.storage.markdown;

}
var MarkdownSerializer = /*#__PURE__*/function () {
/**
* @type {import('@tiptap/core').Editor}
*/
function MarkdownSerializer(editor) {
_classCallCheck(this, MarkdownSerializer);
var MarkdownSerializer = /* @__PURE__ */ function() {
function MarkdownSerializer2(editor) {
_classCallCheck(this, MarkdownSerializer2);
_defineProperty(this, "editor", null);
this.editor = editor;
}
_createClass(MarkdownSerializer, [{
_createClass(MarkdownSerializer2, [{
key: "serialize",
value: function serialize(content) {
var state = new MarkdownSerializerState(this.nodes, this.marks, {
var state2 = new MarkdownSerializerState(this.nodes, this.marks, {
hardBreakNodeName: HardBreak$1.name
});
state.renderContent(content);
return state.out;
state2.renderContent(content);
return state2.out;
}

@@ -1053,9 +1018,8 @@ }, {

get: function get() {
var _this = this,
_this$editor$extensio;
return _objectSpread2(_objectSpread2({}, Object.fromEntries(Object.keys(this.editor.schema.nodes).map(function (name) {
var _this = this, _this$editor$extensio;
return _objectSpread2(_objectSpread2({}, Object.fromEntries(Object.keys(this.editor.schema.nodes).map(function(name) {
return [name, _this.serializeNode(HTMLNode)];
}))), Object.fromEntries((_this$editor$extensio = this.editor.extensionManager.extensions.filter(function (extension) {
return extension.type === 'node' && _this.serializeNode(extension);
}).map(function (extension) {
}))), Object.fromEntries((_this$editor$extensio = this.editor.extensionManager.extensions.filter(function(extension) {
return extension.type === "node" && _this.serializeNode(extension);
}).map(function(extension) {
return [extension.name, _this.serializeNode(extension)];

@@ -1067,9 +1031,8 @@ })) !== null && _this$editor$extensio !== void 0 ? _this$editor$extensio : []));

get: function get() {
var _this2 = this,
_this$editor$extensio2;
return _objectSpread2(_objectSpread2({}, Object.fromEntries(Object.keys(this.editor.schema.marks).map(function (name) {
var _this2 = this, _this$editor$extensio2;
return _objectSpread2(_objectSpread2({}, Object.fromEntries(Object.keys(this.editor.schema.marks).map(function(name) {
return [name, _this2.serializeMark(HTMLMark)];
}))), Object.fromEntries((_this$editor$extensio2 = this.editor.extensionManager.extensions.filter(function (extension) {
return extension.type === 'mark' && _this2.serializeMark(extension);
}).map(function (extension) {
}))), Object.fromEntries((_this$editor$extensio2 = this.editor.extensionManager.extensions.filter(function(extension) {
return extension.type === "mark" && _this2.serializeMark(extension);
}).map(function(extension) {
return [extension.name, _this2.serializeMark(extension)];

@@ -1093,7 +1056,7 @@ })) !== null && _this$editor$extensio2 !== void 0 ? _this$editor$extensio2 : []));

return serialize ? _objectSpread2(_objectSpread2({}, serialize), {}, {
open: typeof serialize.open === 'function' ? serialize.open.bind({
open: typeof serialize.open === "function" ? serialize.open.bind({
editor: this.editor,
options: mark.options
}) : serialize.open,
close: typeof serialize.close === 'function' ? serialize.close.bind({
close: typeof serialize.close === "function" ? serialize.close.bind({
editor: this.editor,

@@ -1105,37 +1068,25 @@ options: mark.options

}]);
return MarkdownSerializer;
return MarkdownSerializer2;
}();
var MarkdownParser = /*#__PURE__*/function () {
/**
* @type {import('@tiptap/core').Editor}
*/
/**
* @type {markdownit}
*/
function MarkdownParser(editor, _ref) {
var html = _ref.html,
linkify = _ref.linkify,
breaks = _ref.breaks;
_classCallCheck(this, MarkdownParser);
var MarkdownParser = /* @__PURE__ */ function() {
function MarkdownParser2(editor, _ref) {
var html = _ref.html, linkify = _ref.linkify, breaks = _ref.breaks;
_classCallCheck(this, MarkdownParser2);
_defineProperty(this, "editor", null);
_defineProperty(this, "md", null);
this.editor = editor;
this.md = markdownit__default['default']({
html: html,
linkify: linkify,
breaks: breaks
this.md = markdownit({
html,
linkify,
breaks
});
}
_createClass(MarkdownParser, [{
_createClass(MarkdownParser2, [{
key: "parse",
value: function parse(content) {
var _this = this;
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
inline = _ref2.inline;
if (typeof content === 'string') {
var _ref2 = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, inline = _ref2.inline;
if (typeof content === "string") {
var renderer = this.md;
this.editor.extensionManager.extensions.forEach(function (extension) {
this.editor.extensionManager.extensions.forEach(function(extension) {
var _getMarkdownSpec, _getMarkdownSpec$pars, _getMarkdownSpec$pars2;

@@ -1149,3 +1100,3 @@ return (_getMarkdownSpec = getMarkdownSpec(extension)) === null || _getMarkdownSpec === void 0 ? void 0 : (_getMarkdownSpec$pars = _getMarkdownSpec.parse) === null || _getMarkdownSpec$pars === void 0 ? void 0 : (_getMarkdownSpec$pars2 = _getMarkdownSpec$pars.setup) === null || _getMarkdownSpec$pars2 === void 0 ? void 0 : _getMarkdownSpec$pars2.call({

var element = elementFromString(renderedHTML);
this.editor.extensionManager.extensions.forEach(function (extension) {
this.editor.extensionManager.extensions.forEach(function(extension) {
var _getMarkdownSpec2, _getMarkdownSpec2$par, _getMarkdownSpec2$par2;

@@ -1158,4 +1109,4 @@ return (_getMarkdownSpec2 = getMarkdownSpec(extension)) === null || _getMarkdownSpec2 === void 0 ? void 0 : (_getMarkdownSpec2$par = _getMarkdownSpec2.parse) === null || _getMarkdownSpec2$par === void 0 ? void 0 : (_getMarkdownSpec2$par2 = _getMarkdownSpec2$par.updateDOM) === null || _getMarkdownSpec2$par2 === void 0 ? void 0 : _getMarkdownSpec2$par2.call({

this.normalizeDOM(element, {
inline: inline,
content: content
inline,
content
});

@@ -1168,7 +1119,11 @@ return element.innerHTML;

key: "normalizeDOM",
value: function normalizeDOM(node) {
var _ref3 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
inline = _ref3.inline,
content = _ref3.content;
value: function normalizeDOM(node, _ref3) {
var inline = _ref3.inline, content = _ref3.content;
this.normalizeBlocks(node);
node.querySelectorAll("*").forEach(function(el) {
var _el$nextSibling;
if (((_el$nextSibling = el.nextSibling) === null || _el$nextSibling === void 0 ? void 0 : _el$nextSibling.nodeType) === Node.TEXT_NODE && !el.closest("pre")) {
el.nextSibling.textContent = el.nextSibling.textContent.replace(/^\n/, "");
}
});
if (inline) {

@@ -1182,16 +1137,16 @@ this.normalizeInline(node, content);

value: function normalizeBlocks(node) {
var blocks = Object.values(this.editor.schema.nodes).filter(function (node) {
return node.isBlock;
var blocks = Object.values(this.editor.schema.nodes).filter(function(node2) {
return node2.isBlock;
});
var selector = blocks.map(function (block) {
var selector = blocks.map(function(block) {
var _block$spec$parseDOM;
return (_block$spec$parseDOM = block.spec.parseDOM) === null || _block$spec$parseDOM === void 0 ? void 0 : _block$spec$parseDOM.map(function (spec) {
return (_block$spec$parseDOM = block.spec.parseDOM) === null || _block$spec$parseDOM === void 0 ? void 0 : _block$spec$parseDOM.map(function(spec) {
return spec.tag;
});
}).flat().filter(Boolean).join(',');
}).flat().filter(Boolean).join(",");
if (!selector) {
return;
}
_toConsumableArray(node.querySelectorAll(selector)).forEach(function (el) {
if (el.parentElement.matches('p')) {
_toConsumableArray(node.querySelectorAll(selector)).forEach(function(el) {
if (el.parentElement.matches("p")) {
extractElement(el);

@@ -1205,12 +1160,9 @@ }

var _node$firstElementChi;
if ((_node$firstElementChi = node.firstElementChild) !== null && _node$firstElementChi !== void 0 && _node$firstElementChi.matches('p')) {
if ((_node$firstElementChi = node.firstElementChild) !== null && _node$firstElementChi !== void 0 && _node$firstElementChi.matches("p")) {
var _content$match$, _content$match, _content$match$2, _content$match2;
var firstParagraph = node.firstElementChild;
var nextSibling = firstParagraph.nextSibling,
nextElementSibling = firstParagraph.nextElementSibling;
var startSpaces = (_content$match$ = (_content$match = content.match(/^\s+/)) === null || _content$match === void 0 ? void 0 : _content$match[0]) !== null && _content$match$ !== void 0 ? _content$match$ : '';
var endSpaces = !nextElementSibling ? (_content$match$2 = (_content$match2 = content.match(/\s+$/)) === null || _content$match2 === void 0 ? void 0 : _content$match2[0]) !== null && _content$match$2 !== void 0 ? _content$match$2 : '' : '';
if ((nextSibling === null || nextSibling === void 0 ? void 0 : nextSibling.nodeType) === Node.TEXT_NODE) {
nextSibling.textContent = nextSibling.textContent.replace(/^\n/, '');
}
firstParagraph.nextSibling;
var nextElementSibling = firstParagraph.nextElementSibling;
var startSpaces = (_content$match$ = (_content$match = content.match(/^\s+/)) === null || _content$match === void 0 ? void 0 : _content$match[0]) !== null && _content$match$ !== void 0 ? _content$match$ : "";
var endSpaces = !nextElementSibling ? (_content$match$2 = (_content$match2 = content.match(/\s+$/)) === null || _content$match2 === void 0 ? void 0 : _content$match2[0]) !== null && _content$match$2 !== void 0 ? _content$match$2 : "" : "";
if (content.match(/^\n\n/)) {

@@ -1225,7 +1177,6 @@ firstParagraph.innerHTML = "".concat(firstParagraph.innerHTML).concat(endSpaces);

}]);
return MarkdownParser;
return MarkdownParser2;
}();
var MarkdownClipboard = core.Extension.create({
name: 'markdownClipboard',
name: "markdownClipboard",
addOptions: function addOptions() {

@@ -1240,9 +1191,8 @@ return {

return [new state.Plugin({
key: new state.PluginKey('markdownClipboard'),
key: new state.PluginKey("markdownClipboard"),
props: {
clipboardTextParser: function clipboardTextParser(text, context, plainText) {
if (plainText || !_this.options.transformPastedText) {
return null; // pasting with shift key prevents formatting
return null;
}
var parsed = _this.editor.storage.markdown.parser.parse(text, {

@@ -1252,3 +1202,4 @@ inline: true

return model.DOMParser.fromSchema(_this.editor.schema).parseSlice(elementFromString(parsed), {
preserveWhitespace: true
preserveWhitespace: true,
context
});

@@ -1269,5 +1220,4 @@ },

});
var Markdown = core.Extension.create({
name: 'markdown',
name: "markdown",
priority: 50,

@@ -1278,4 +1228,4 @@ addOptions: function addOptions() {

tightLists: true,
tightListClass: 'tight',
bulletListMarker: '-',
tightListClass: "tight",
bulletListMarker: "-",
linkify: false,

@@ -1291,3 +1241,3 @@ breaks: false,

setContent: function setContent(content, emitUpdate, parseOptions) {
return function (props) {
return function(props) {
return commands.setContent(props.editor.storage.markdown.parser.parse(content), emitUpdate, parseOptions)(props);

@@ -1297,3 +1247,3 @@ };

insertContentAt: function insertContentAt(range, content, options) {
return function (props) {
return function(props) {
return commands.insertContentAt(range, props.editor.storage.markdown.parser.parse(content, {

@@ -1338,8 +1288,5 @@ inline: true

});
exports.Markdown = Markdown;
Object.defineProperty(exports, '__esModule', { value: true });
})));
exports2.Markdown = Markdown;
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
});
//# sourceMappingURL=tiptap-markdown.umd.js.map
{
"name": "tiptap-markdown",
"version": "0.8.2",
"version": "0.8.3",
"description": "Edit markdown content in tiptap editor.",
"scripts": {
"test": "jest",
"build": "rollup -c",
"watch": "rollup -c -w",
"test": "vitest",
"dev": "vite example",
"build": "vite build",
"build:example": "vite build example",
"preversion": "npm run build",
"update:tiptap": "update-by-scope @tiptap"
},
"main": "dist/tiptap-markdown.cjs.js",
"umd": "dist/tiptap-markdown.umd.js",
"module": "dist/tiptap-markdown.esm.js",
"workspaces": [
"example"
],
"main": "dist/tiptap-markdown.umd.js",
"module": "dist/tiptap-markdown.es.js",
"exports": {
".": {
"import": "./dist/tiptap-markdown.es.js",
"require": "./dist/tiptap-markdown.umd.js"
}
},
"files": [

@@ -43,5 +52,2 @@ "src",

"@rollup/plugin-babel": "^5.3.0",
"@rollup/plugin-commonjs": "^19.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.0",
"@tiptap/core": "^2.0.3",

@@ -61,8 +67,9 @@ "@tiptap/extension-highlight": "^2.0.3",

"@types/jest": "^28.1.7",
"babel-jest": "^27.0.2",
"jest": "^27.0.4",
"jest-serializer-html": "^7.1.0",
"rollup": "^2.51.1",
"update-by-scope": "^1.1.3"
"jsdom": "^22.1.0",
"terser": "^5.24.0",
"update-by-scope": "^1.1.3",
"vite": "^4.5.0",
"vitest": "^0.34.6"
}
}

@@ -6,3 +6,3 @@ # Tiptap markdown

> **Warning**
> Since v0.7.0, `createMarkdownEditor` as been dropped in favor of a more friendly `Markdown` Tiptap extension. See the [migration guide](docs/migration.md).
> Since v0.7.0, `createMarkdownEditor` as been dropped in favor of a more friendly `Markdown` Tiptap extension. See the [migration guide](https://github.com/aguingand/tiptap-markdown/blob/main/docs/migration.md).

@@ -9,0 +9,0 @@ ## Installation

@@ -34,3 +34,3 @@ import { Fragment } from "@tiptap/pm/model";

if(node.isBlock && parent.type.name === schema.topNodeType.name) {
if(node.isBlock && (parent instanceof Fragment || parent.type.name === schema.topNodeType.name)) {
return formatBlock(html);

@@ -37,0 +37,0 @@ }

@@ -60,3 +60,3 @@ import { Node } from "@tiptap/core";

if(childNodes(firstRow).some(cell => cell.type.name !== 'tableHeader' || hasSpan(cell))) {
if(childNodes(firstRow).some(cell => cell.type.name !== 'tableHeader' || hasSpan(cell) || cell.childCount > 1)) {
return false;

@@ -66,3 +66,3 @@ }

if(bodyRows.some(row =>
childNodes(row).some(cell => cell.type.name === 'tableHeader' || hasSpan(cell))
childNodes(row).some(cell => cell.type.name === 'tableHeader' || hasSpan(cell) || cell.childCount > 1)
)) {

@@ -69,0 +69,0 @@ return false;

@@ -25,3 +25,6 @@ import { Extension } from "@tiptap/core";

return DOMParser.fromSchema(this.editor.schema)
.parseSlice(elementFromString(parsed), { preserveWhitespace: true });
.parseSlice(elementFromString(parsed), {
preserveWhitespace: true,
context,
});
},

@@ -28,0 +31,0 @@ /**

@@ -48,5 +48,12 @@ import markdownit from "markdown-it";

normalizeDOM(node, { inline, content } = {}) {
normalizeDOM(node, { inline, content }) {
this.normalizeBlocks(node);
// remove all \n appended by markdown-it
node.querySelectorAll('*').forEach(el => {
if(el.nextSibling?.nodeType === Node.TEXT_NODE && !el.closest('pre')) {
el.nextSibling.textContent = el.nextSibling.textContent.replace(/^\n/, '');
}
});
if(inline) {

@@ -89,6 +96,2 @@ this.normalizeInline(node, content);

if(nextSibling?.nodeType === Node.TEXT_NODE) {
nextSibling.textContent = nextSibling.textContent.replace(/^\n/, '');
}
if(content.match(/^\n\n/)) {

@@ -95,0 +98,0 @@ firstParagraph.innerHTML = `${firstParagraph.innerHTML}${endSpaces}`;

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