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

Comparing version 0.8.4 to 0.8.8

66

dist/tiptap-markdown.es.js

@@ -436,2 +436,11 @@ var __defProp = Object.defineProperty;

});
function findIndexOfAdjacentNode(node, parent, index) {
let i = 0;
for (; index - i > 0; i++) {
if (parent.child(index - i - 1).type.name !== node.type.name) {
break;
}
}
return i;
}
const OrderedList$1 = OrderedList.extend({

@@ -444,3 +453,13 @@ /**

markdown: {
serialize: defaultMarkdownSerializer.nodes.ordered_list,
serialize(state, node, parent, index) {
const start = node.attrs.start || 1;
const maxW = String(start + node.childCount - 1).length;
const space = state.repeat(" ", maxW + 2);
const adjacentIndex = findIndexOfAdjacentNode(node, parent, index);
const separator = adjacentIndex % 2 ? ") " : ". ";
state.renderList(node, space, (i) => {
const nStr = String(start + i);
return state.repeat(" ", maxW - nStr.length) + nStr + separator;
});
},
parse: {

@@ -473,3 +492,3 @@ // handled by markdown-it

var _node$content$content, _node$content;
return (_node$content$content = node === null || node === void 0 ? void 0 : (_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.content) !== null && _node$content$content !== void 0 ? _node$content$content : [];
return (_node$content$content = node === null || node === void 0 || (_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.content) !== null && _node$content$content !== void 0 ? _node$content$content : [];
}

@@ -749,4 +768,4 @@ const Table = Node$1.create({

serializeNode(node) {
var _getMarkdownSpec, _getMarkdownSpec$seri;
return (_getMarkdownSpec = getMarkdownSpec(node)) === null || _getMarkdownSpec === void 0 ? void 0 : (_getMarkdownSpec$seri = _getMarkdownSpec.serialize) === null || _getMarkdownSpec$seri === void 0 ? void 0 : _getMarkdownSpec$seri.bind({
var _getMarkdownSpec;
return (_getMarkdownSpec = getMarkdownSpec(node)) === null || _getMarkdownSpec === void 0 || (_getMarkdownSpec = _getMarkdownSpec.serialize) === null || _getMarkdownSpec === void 0 ? void 0 : _getMarkdownSpec.bind({
editor: this.editor,

@@ -788,7 +807,7 @@ options: node.options

this.editor = editor;
this.md = markdownit({
this.md = this.withPatchedRenderer(markdownit({
html,
linkify,
breaks
});
}));
}

@@ -800,15 +819,14 @@ parse(content) {

if (typeof content === "string") {
const renderer = this.md;
this.editor.extensionManager.extensions.forEach((extension) => {
var _getMarkdownSpec, _getMarkdownSpec$pars, _getMarkdownSpec$pars2;
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 _getMarkdownSpec;
return (_getMarkdownSpec = getMarkdownSpec(extension)) === null || _getMarkdownSpec === void 0 || (_getMarkdownSpec = _getMarkdownSpec.parse) === null || _getMarkdownSpec === void 0 || (_getMarkdownSpec = _getMarkdownSpec.setup) === null || _getMarkdownSpec === void 0 ? void 0 : _getMarkdownSpec.call({
editor: this.editor,
options: extension.options
}, renderer);
}, this.md);
});
const renderedHTML = renderer.render(content);
const renderedHTML = this.md.render(content);
const element = elementFromString(renderedHTML);
this.editor.extensionManager.extensions.forEach((extension) => {
var _getMarkdownSpec2, _getMarkdownSpec2$par, _getMarkdownSpec2$par2;
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({
var _getMarkdownSpec2;
return (_getMarkdownSpec2 = getMarkdownSpec(extension)) === null || _getMarkdownSpec2 === void 0 || (_getMarkdownSpec2 = _getMarkdownSpec2.parse) === null || _getMarkdownSpec2 === void 0 || (_getMarkdownSpec2 = _getMarkdownSpec2.updateDOM) === null || _getMarkdownSpec2 === void 0 ? void 0 : _getMarkdownSpec2.call({
editor: this.editor,

@@ -864,3 +882,2 @@ options: extension.options

const {
nextSibling,
nextElementSibling

@@ -878,2 +895,23 @@ } = firstParagraph;

}
/**
* @param {markdownit} md
*/
withPatchedRenderer(md2) {
const withoutNewLine = (renderer) => function() {
const rendered = renderer(...arguments);
if (rendered === "\n") {
return rendered;
}
if (rendered[rendered.length - 1] === "\n") {
return rendered.slice(0, -1);
}
return rendered;
};
md2.renderer.rules.hardbreak = withoutNewLine(md2.renderer.rules.hardbreak);
md2.renderer.rules.softbreak = withoutNewLine(md2.renderer.rules.softbreak);
md2.renderer.rules.fence = withoutNewLine(md2.renderer.rules.fence);
md2.renderer.rules.code_block = withoutNewLine(md2.renderer.rules.code_block);
md2.renderer.renderToken = withoutNewLine(md2.renderer.renderToken.bind(md2.renderer));
return md2;
}
}

@@ -880,0 +918,0 @@ const MarkdownClipboard = Extension.create({

@@ -434,2 +434,11 @@ (function(global, factory) {

});
function findIndexOfAdjacentNode(node, parent, index) {
let i = 0;
for (; index - i > 0; i++) {
if (parent.child(index - i - 1).type.name !== node.type.name) {
break;
}
}
return i;
}
const OrderedList$1 = OrderedList.extend({

@@ -442,3 +451,13 @@ /**

markdown: {
serialize: prosemirrorMarkdown.defaultMarkdownSerializer.nodes.ordered_list,
serialize(state2, node, parent, index) {
const start = node.attrs.start || 1;
const maxW = String(start + node.childCount - 1).length;
const space = state2.repeat(" ", maxW + 2);
const adjacentIndex = findIndexOfAdjacentNode(node, parent, index);
const separator = adjacentIndex % 2 ? ") " : ". ";
state2.renderList(node, space, (i) => {
const nStr = String(start + i);
return state2.repeat(" ", maxW - nStr.length) + nStr + separator;
});
},
parse: {

@@ -471,3 +490,3 @@ // handled by markdown-it

var _node$content$content, _node$content;
return (_node$content$content = node === null || node === void 0 ? void 0 : (_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.content) !== null && _node$content$content !== void 0 ? _node$content$content : [];
return (_node$content$content = node === null || node === void 0 || (_node$content = node.content) === null || _node$content === void 0 ? void 0 : _node$content.content) !== null && _node$content$content !== void 0 ? _node$content$content : [];
}

@@ -747,4 +766,4 @@ const Table = core.Node.create({

serializeNode(node) {
var _getMarkdownSpec, _getMarkdownSpec$seri;
return (_getMarkdownSpec = getMarkdownSpec(node)) === null || _getMarkdownSpec === void 0 ? void 0 : (_getMarkdownSpec$seri = _getMarkdownSpec.serialize) === null || _getMarkdownSpec$seri === void 0 ? void 0 : _getMarkdownSpec$seri.bind({
var _getMarkdownSpec;
return (_getMarkdownSpec = getMarkdownSpec(node)) === null || _getMarkdownSpec === void 0 || (_getMarkdownSpec = _getMarkdownSpec.serialize) === null || _getMarkdownSpec === void 0 ? void 0 : _getMarkdownSpec.bind({
editor: this.editor,

@@ -786,7 +805,7 @@ options: node.options

this.editor = editor;
this.md = markdownit({
this.md = this.withPatchedRenderer(markdownit({
html,
linkify,
breaks
});
}));
}

@@ -798,15 +817,14 @@ parse(content) {

if (typeof content === "string") {
const renderer = this.md;
this.editor.extensionManager.extensions.forEach((extension) => {
var _getMarkdownSpec, _getMarkdownSpec$pars, _getMarkdownSpec$pars2;
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 _getMarkdownSpec;
return (_getMarkdownSpec = getMarkdownSpec(extension)) === null || _getMarkdownSpec === void 0 || (_getMarkdownSpec = _getMarkdownSpec.parse) === null || _getMarkdownSpec === void 0 || (_getMarkdownSpec = _getMarkdownSpec.setup) === null || _getMarkdownSpec === void 0 ? void 0 : _getMarkdownSpec.call({
editor: this.editor,
options: extension.options
}, renderer);
}, this.md);
});
const renderedHTML = renderer.render(content);
const renderedHTML = this.md.render(content);
const element = elementFromString(renderedHTML);
this.editor.extensionManager.extensions.forEach((extension) => {
var _getMarkdownSpec2, _getMarkdownSpec2$par, _getMarkdownSpec2$par2;
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({
var _getMarkdownSpec2;
return (_getMarkdownSpec2 = getMarkdownSpec(extension)) === null || _getMarkdownSpec2 === void 0 || (_getMarkdownSpec2 = _getMarkdownSpec2.parse) === null || _getMarkdownSpec2 === void 0 || (_getMarkdownSpec2 = _getMarkdownSpec2.updateDOM) === null || _getMarkdownSpec2 === void 0 ? void 0 : _getMarkdownSpec2.call({
editor: this.editor,

@@ -862,3 +880,2 @@ options: extension.options

const {
nextSibling,
nextElementSibling

@@ -876,2 +893,23 @@ } = firstParagraph;

}
/**
* @param {markdownit} md
*/
withPatchedRenderer(md2) {
const withoutNewLine = (renderer) => function() {
const rendered = renderer(...arguments);
if (rendered === "\n") {
return rendered;
}
if (rendered[rendered.length - 1] === "\n") {
return rendered.slice(0, -1);
}
return rendered;
};
md2.renderer.rules.hardbreak = withoutNewLine(md2.renderer.rules.hardbreak);
md2.renderer.rules.softbreak = withoutNewLine(md2.renderer.rules.softbreak);
md2.renderer.rules.fence = withoutNewLine(md2.renderer.rules.fence);
md2.renderer.rules.code_block = withoutNewLine(md2.renderer.rules.code_block);
md2.renderer.renderToken = withoutNewLine(md2.renderer.renderToken.bind(md2.renderer));
return md2;
}
}

@@ -878,0 +916,0 @@ const MarkdownClipboard = core.Extension.create({

{
"name": "tiptap-markdown",
"version": "0.8.4",
"version": "0.8.8",
"description": "Edit markdown content in tiptap editor.",

@@ -24,3 +24,4 @@ "scripts": {

"import": "./dist/tiptap-markdown.es.js",
"require": "./dist/tiptap-markdown.umd.js"
"require": "./dist/tiptap-markdown.umd.js",
"types": "./index.d.ts"
}

@@ -39,3 +40,3 @@ },

"type": "git",
"url": "https://github.com/aguingand/tiptap-markdown.git"
"url": "git+https://github.com/aguingand/tiptap-markdown.git"
},

@@ -59,4 +60,2 @@ "bugs": {

"@babel/core": "^7.23.2",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.18.6",
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@babel/preset-env": "^7.23.2",

@@ -63,0 +62,0 @@ "@rollup/plugin-babel": "^5.3.1",

@@ -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](https://github.com/aguingand/tiptap-markdown/blob/main/docs/migration.md).
> Since v0.7.0, `createMarkdownEditor` has 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

import { Node } from "@tiptap/core";
import { defaultMarkdownSerializer } from "prosemirror-markdown";

@@ -9,2 +8,12 @@

function findIndexOfAdjacentNode(node, parent, index) {
let i = 0;
for (; index - i > 0; i++) {
if (parent.child(index - i - 1).type.name !== node.type.name) {
break;
}
}
return i;
}
export default OrderedList.extend({

@@ -17,3 +26,13 @@ /**

markdown: {
serialize: defaultMarkdownSerializer.nodes.ordered_list,
serialize(state, node, parent, index) {
const start = node.attrs.start || 1
const maxW = String(start + node.childCount - 1).length
const space = state.repeat(" ", maxW + 2)
const adjacentIndex = findIndexOfAdjacentNode(node, parent, index);
const separator = adjacentIndex % 2 ? ') ' : '. ';
state.renderList(node, space, i => {
const nStr = String(start + i)
return state.repeat(" ", maxW - nStr.length) + nStr + separator;
})
},
parse: {

@@ -20,0 +39,0 @@ // handled by markdown-it

@@ -5,3 +5,2 @@ import markdownit from "markdown-it";

export class MarkdownParser {

@@ -19,7 +18,7 @@ /**

this.editor = editor;
this.md = markdownit({
this.md = this.withPatchedRenderer(markdownit({
html,
linkify,
breaks,
});
}));
}

@@ -29,9 +28,7 @@

if(typeof content === 'string') {
const renderer = this.md;
this.editor.extensionManager.extensions.forEach(extension =>
getMarkdownSpec(extension)?.parse?.setup?.call({ editor:this.editor, options:extension.options }, renderer)
getMarkdownSpec(extension)?.parse?.setup?.call({ editor:this.editor, options:extension.options }, this.md)
);
const renderedHTML = renderer.render(content);
const renderedHTML = this.md.render(content);
const element = elementFromString(renderedHTML);

@@ -92,3 +89,3 @@

const firstParagraph = node.firstElementChild;
const { nextSibling, nextElementSibling } = firstParagraph;
const { nextElementSibling } = firstParagraph;
const startSpaces = content.match(/^\s+/)?.[0] ?? '';

@@ -109,3 +106,27 @@ const endSpaces = !nextElementSibling

}
/**
* @param {markdownit} md
*/
withPatchedRenderer(md) {
const withoutNewLine = (renderer) => (...args) => {
const rendered = renderer(...args);
if(rendered === '\n') {
return rendered; // keep soft breaks
}
if(rendered[rendered.length - 1] === '\n') {
return rendered.slice(0, -1);
}
return rendered;
}
md.renderer.rules.hardbreak = withoutNewLine(md.renderer.rules.hardbreak);
md.renderer.rules.softbreak = withoutNewLine(md.renderer.rules.softbreak);
md.renderer.rules.fence = withoutNewLine(md.renderer.rules.fence);
md.renderer.rules.code_block = withoutNewLine(md.renderer.rules.code_block);
md.renderer.renderToken = withoutNewLine(md.renderer.renderToken.bind(md.renderer));
return md;
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc