tiptap-markdown
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -688,9 +688,9 @@ 'use strict'; | ||
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
inline = _ref.inline; | ||
inline = _ref.inline, | ||
content = _ref.content; | ||
normalizeBlocks(schema, node); | ||
normalizeNewLines(node); | ||
if (inline && node.firstElementChild.matches('p')) { | ||
unwrapElement(node.firstElementChild); | ||
if (inline) { | ||
normalizeInline(node, content); | ||
} | ||
@@ -724,21 +724,24 @@ | ||
function normalizeNewLines(node) { | ||
_toConsumableArray(node.querySelectorAll('*')).filter(function (node) { | ||
if (node.closest('pre') && !node.matches('pre')) { | ||
return false; | ||
} | ||
function normalizeInline(node, content) { | ||
if (node.firstElementChild.matches('p')) { | ||
var _content$match$, _content$match, _content$match$2, _content$match2; | ||
return true; | ||
}).forEach(function (node) { | ||
var previousSibling = node.previousSibling, | ||
nextSibling = node.nextSibling; | ||
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 ((previousSibling === null || previousSibling === void 0 ? void 0 : previousSibling.nodeType) === Node.TEXT_NODE) { | ||
previousSibling.textContent = previousSibling.textContent.replace(/\n$/, ''); | ||
} | ||
if ((nextSibling === null || nextSibling === void 0 ? void 0 : nextSibling.nodeType) === Node.TEXT_NODE) { | ||
nextSibling.textContent = nextSibling.textContent.replace(/^\n/, ''); | ||
} | ||
}); | ||
if (content.match(/^\n\n/)) { | ||
firstParagraph.innerHTML = "".concat(firstParagraph.innerHTML).concat(endSpaces); | ||
return; | ||
} | ||
unwrapElement(firstParagraph); | ||
node.innerHTML = "".concat(startSpaces).concat(node.innerHTML).concat(endSpaces); | ||
} | ||
} | ||
@@ -780,3 +783,4 @@ | ||
normalizeDOM(schema, element, { | ||
inline: inline | ||
inline: inline, | ||
content: content | ||
}); | ||
@@ -783,0 +787,0 @@ return element.innerHTML; |
@@ -678,9 +678,9 @@ import { MarkdownSerializerState as MarkdownSerializerState$1, defaultMarkdownSerializer } from 'prosemirror-markdown'; | ||
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
inline = _ref.inline; | ||
inline = _ref.inline, | ||
content = _ref.content; | ||
normalizeBlocks(schema, node); | ||
normalizeNewLines(node); | ||
if (inline && node.firstElementChild.matches('p')) { | ||
unwrapElement(node.firstElementChild); | ||
if (inline) { | ||
normalizeInline(node, content); | ||
} | ||
@@ -714,21 +714,24 @@ | ||
function normalizeNewLines(node) { | ||
_toConsumableArray(node.querySelectorAll('*')).filter(function (node) { | ||
if (node.closest('pre') && !node.matches('pre')) { | ||
return false; | ||
} | ||
function normalizeInline(node, content) { | ||
if (node.firstElementChild.matches('p')) { | ||
var _content$match$, _content$match, _content$match$2, _content$match2; | ||
return true; | ||
}).forEach(function (node) { | ||
var previousSibling = node.previousSibling, | ||
nextSibling = node.nextSibling; | ||
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 ((previousSibling === null || previousSibling === void 0 ? void 0 : previousSibling.nodeType) === Node.TEXT_NODE) { | ||
previousSibling.textContent = previousSibling.textContent.replace(/\n$/, ''); | ||
} | ||
if ((nextSibling === null || nextSibling === void 0 ? void 0 : nextSibling.nodeType) === Node.TEXT_NODE) { | ||
nextSibling.textContent = nextSibling.textContent.replace(/^\n/, ''); | ||
} | ||
}); | ||
if (content.match(/^\n\n/)) { | ||
firstParagraph.innerHTML = "".concat(firstParagraph.innerHTML).concat(endSpaces); | ||
return; | ||
} | ||
unwrapElement(firstParagraph); | ||
node.innerHTML = "".concat(startSpaces).concat(node.innerHTML).concat(endSpaces); | ||
} | ||
} | ||
@@ -770,3 +773,4 @@ | ||
normalizeDOM(schema, element, { | ||
inline: inline | ||
inline: inline, | ||
content: content | ||
}); | ||
@@ -773,0 +777,0 @@ return element.innerHTML; |
@@ -683,9 +683,9 @@ (function (global, factory) { | ||
var _ref = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {}, | ||
inline = _ref.inline; | ||
inline = _ref.inline, | ||
content = _ref.content; | ||
normalizeBlocks(schema, node); | ||
normalizeNewLines(node); | ||
if (inline && node.firstElementChild.matches('p')) { | ||
unwrapElement(node.firstElementChild); | ||
if (inline) { | ||
normalizeInline(node, content); | ||
} | ||
@@ -719,21 +719,24 @@ | ||
function normalizeNewLines(node) { | ||
_toConsumableArray(node.querySelectorAll('*')).filter(function (node) { | ||
if (node.closest('pre') && !node.matches('pre')) { | ||
return false; | ||
} | ||
function normalizeInline(node, content) { | ||
if (node.firstElementChild.matches('p')) { | ||
var _content$match$, _content$match, _content$match$2, _content$match2; | ||
return true; | ||
}).forEach(function (node) { | ||
var previousSibling = node.previousSibling, | ||
nextSibling = node.nextSibling; | ||
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 ((previousSibling === null || previousSibling === void 0 ? void 0 : previousSibling.nodeType) === Node.TEXT_NODE) { | ||
previousSibling.textContent = previousSibling.textContent.replace(/\n$/, ''); | ||
} | ||
if ((nextSibling === null || nextSibling === void 0 ? void 0 : nextSibling.nodeType) === Node.TEXT_NODE) { | ||
nextSibling.textContent = nextSibling.textContent.replace(/^\n/, ''); | ||
} | ||
}); | ||
if (content.match(/^\n\n/)) { | ||
firstParagraph.innerHTML = "".concat(firstParagraph.innerHTML).concat(endSpaces); | ||
return; | ||
} | ||
unwrapElement(firstParagraph); | ||
node.innerHTML = "".concat(startSpaces).concat(node.innerHTML).concat(endSpaces); | ||
} | ||
} | ||
@@ -775,3 +778,4 @@ | ||
normalizeDOM(schema, element, { | ||
inline: inline | ||
inline: inline, | ||
content: content | ||
}); | ||
@@ -778,0 +782,0 @@ return element.innerHTML; |
{ | ||
"name": "tiptap-markdown", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Edit markdown content in tiptap editor.", | ||
@@ -5,0 +5,0 @@ "scripts": { |
import { extractElement, unwrapElement } from "../util/dom"; | ||
export function normalizeDOM(schema, node, { inline } = {}) { | ||
export function normalizeDOM(schema, node, { inline, content } = {}) { | ||
normalizeBlocks(schema, node); | ||
normalizeNewLines(node); | ||
if(inline && node.firstElementChild.matches('p')) { | ||
unwrapElement(node.firstElementChild); | ||
if(inline) { | ||
normalizeInline(node, content); | ||
} | ||
@@ -35,19 +34,24 @@ | ||
function normalizeNewLines(node) { | ||
[...node.querySelectorAll('*')] | ||
.filter(node => { | ||
if(node.closest('pre') && !node.matches('pre')) { | ||
return false; | ||
} | ||
return true; | ||
}) | ||
.forEach(node => { | ||
const { previousSibling, nextSibling } = node; | ||
if(previousSibling?.nodeType === Node.TEXT_NODE) { | ||
previousSibling.textContent = previousSibling.textContent.replace(/\n$/, ''); | ||
} | ||
if(nextSibling?.nodeType === Node.TEXT_NODE) { | ||
nextSibling.textContent = nextSibling.textContent.replace(/^\n/, ''); | ||
} | ||
}); | ||
function normalizeInline(node, content) { | ||
if(node.firstElementChild.matches('p')) { | ||
const firstParagraph = node.firstElementChild; | ||
const { nextSibling, nextElementSibling } = firstParagraph; | ||
const startSpaces = content.match(/^\s+/)?.[0] ?? ''; | ||
const endSpaces = !nextElementSibling | ||
? content.match(/\s+$/)?.[0] ?? '' | ||
: ''; | ||
if(nextSibling?.nodeType === Node.TEXT_NODE) { | ||
nextSibling.textContent = nextSibling.textContent.replace(/^\n/, ''); | ||
} | ||
if(content.match(/^\n\n/)) { | ||
firstParagraph.innerHTML = `${firstParagraph.innerHTML}${endSpaces}`; | ||
return; | ||
} | ||
unwrapElement(firstParagraph); | ||
node.innerHTML = `${startSpaces}${node.innerHTML}${endSpaces}`; | ||
} | ||
} |
@@ -26,3 +26,3 @@ import markdownit from "markdown-it"; | ||
normalizeDOM(schema, element, { inline }); | ||
normalizeDOM(schema, element, { inline, content }); | ||
@@ -29,0 +29,0 @@ return element.innerHTML; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
296716
3695