Skip to content

Commit

Permalink
chore: remove all hardBreaks
Browse files Browse the repository at this point in the history
  • Loading branch information
zensh committed Oct 10, 2023
1 parent 0339b7c commit 3201687
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 22 deletions.
13 changes: 3 additions & 10 deletions dist/tiptap.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ export class JSONDocumentAmender {
node.type = 'invalid';
return node;
}
if (node.type === 'paragraph' && !node.content?.length) {
if (node.type === 'paragraph' &&
(!node.content?.length ||
(node.content.length == 1 && node.content[0].type === 'hardBreak'))) {
node.type = 'invalid';
return node;
}
Expand All @@ -147,16 +149,7 @@ export class JSONDocumentAmender {
}
// content: Node[]
if (node.content != null) {
let prevHardBreak = false;
for (const child of node.content) {
const isHardBreak = child.type === 'paragraph' &&
child.content?.length === 1 &&
child.content[0].type === 'hardBreak';
if (prevHardBreak && isHardBreak) {
// 清理连续的 hardBreak
child.type = 'invalid';
}
prevHardBreak = isHardBreak;
this.amendNode(child);
}
node.content = node.content.filter((child) => child.type !== 'invalid');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webscraper",
"version": "1.1.4",
"version": "1.1.5",
"description": "",
"private": true,
"main": "dist/main.js",
Expand Down
16 changes: 5 additions & 11 deletions src/tiptap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ export class JSONDocumentAmender {
return node
}

if (node.type === 'paragraph' && !node.content?.length) {
if (
node.type === 'paragraph' &&
(!node.content?.length ||
(node.content.length == 1 && node.content[0].type === 'hardBreak'))
) {
node.type = 'invalid'
return node
}
Expand Down Expand Up @@ -171,17 +175,7 @@ export class JSONDocumentAmender {

// content: Node[]
if (node.content != null) {
let prevHardBreak = false
for (const child of node.content) {
const isHardBreak =
child.type === 'paragraph' &&
child.content?.length === 1 &&
child.content[0].type === 'hardBreak'
if (prevHardBreak && isHardBreak) {
// 清理连续的 hardBreak
child.type = 'invalid'
}
prevHardBreak = isHardBreak
this.amendNode(child)
}

Expand Down

0 comments on commit 3201687

Please sign in to comment.