-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix rte source mode #5083
Fix rte source mode #5083
Changes from 4 commits
f83d73d
38c683e
c8c5be5
48b0068
8dd1fdb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,37 @@ | ||||||||||||
import { Extension } from '@tiptap/core'; | ||||||||||||
export const GlobalAttributes = Extension.create({ | ||||||||||||
addGlobalAttributes() { | ||||||||||||
return [ | ||||||||||||
{ | ||||||||||||
// Extend the following extensions | ||||||||||||
types: ['table'], | ||||||||||||
// … with those attributes | ||||||||||||
attributes: { | ||||||||||||
border: { | ||||||||||||
parseHTML: (element) => element.getAttribute('border'), | ||||||||||||
}, | ||||||||||||
|
||||||||||||
cellSpacing: { | ||||||||||||
parseHTML: (element) => element.getAttribute('cellspacing'), | ||||||||||||
}, | ||||||||||||
cellPadding: { | ||||||||||||
parseHTML: (element) => element.getAttribute('cellpadding'), | ||||||||||||
}, | ||||||||||||
width: { | ||||||||||||
default: null, | ||||||||||||
parseHTML: (element) => { | ||||||||||||
const width = | ||||||||||||
element.style.width || element.getAttribute('width') || null; | ||||||||||||
return width; | ||||||||||||
Comment on lines
+23
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code-quality): Inline variable that is immediately returned (
Suggested change
ExplanationSomething that we often see in people's code is assigning to a result variableand then immediately returning it. Returning the result directly shortens the code and removes an unnecessary Where intermediate variables can be useful is if they then get used as a |
||||||||||||
}, | ||||||||||||
renderHTML: (attributes) => { | ||||||||||||
return { | ||||||||||||
width: attributes.width, | ||||||||||||
}; | ||||||||||||
}, | ||||||||||||
}, | ||||||||||||
}, | ||||||||||||
}, | ||||||||||||
]; | ||||||||||||
}, | ||||||||||||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ export const enum ImageDisplay { | |
INLINE = 'inline', | ||
BREAK_TEXT = 'block', | ||
FLOAT_LEFT = 'left', | ||
FLOAT_RIGHT = 'right' | ||
FLOAT_RIGHT = 'right', | ||
} | ||
|
||
export interface IImageOptions { | ||
|
@@ -34,37 +34,40 @@ export const ImageResize = Image.extend<IImageOptions>({ | |
...this.parent?.(), | ||
width: { | ||
default: null, | ||
parseHTML: element => { | ||
parseHTML: (element) => { | ||
const width = | ||
element.style.width || element.getAttribute('width') || null; | ||
return width; | ||
}, | ||
renderHTML: attributes => { | ||
renderHTML: (attributes) => { | ||
return { | ||
width: attributes.width | ||
width: attributes.width, | ||
}; | ||
} | ||
}, | ||
}, | ||
height: { | ||
default: null, | ||
parseHTML: element => { | ||
parseHTML: (element) => { | ||
const height = | ||
element.style.height || element.getAttribute('height') || null; | ||
return height; | ||
}, | ||
renderHTML: attributes => { | ||
renderHTML: (attributes) => { | ||
return { | ||
height: attributes.height | ||
height: attributes.height, | ||
}; | ||
} | ||
} | ||
}, | ||
}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (code_refinement): Ensure consistency in handling 'style' attribute across all extensions. The addition of 'style' attribute handling in the Image extension is a good improvement. Ensure similar attributes are consistently handled across all relevant extensions for uniformity. |
||
style: { | ||
parseHTML: (element) => element.getAttribute('style'), | ||
}, | ||
}; | ||
}, | ||
parseHTML() { | ||
return [ | ||
{ | ||
tag: 'img[src]' | ||
} | ||
tag: 'img[src]', | ||
}, | ||
]; | ||
} | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import TiptapCell from '@tiptap/extension-table-cell'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Consider adding tests for Cell extension. Testing the Cell extension is essential to verify that it correctly extends the default table cell behavior, especially regarding the parsing and rendering of style attributes. |
||
|
||
export const Cell = TiptapCell.extend({ | ||
addAttributes() { | ||
return { | ||
...this.parent?.(), | ||
style: { | ||
parseHTML: (element) => element.getAttribute('style'), | ||
}, | ||
}; | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Cell } from './Cell'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import TiptapHeader from '@tiptap/extension-table-header'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Consider adding tests for Header extension. Testing the Header extension is important to confirm that it correctly extends the default table header behavior, with a focus on the parsing and rendering of style attributes. |
||
export const Header = TiptapHeader.extend({ | ||
addAttributes() { | ||
return { | ||
...this.parent?.(), | ||
style: { | ||
parseHTML: (element) => element.getAttribute('style'), | ||
}, | ||
}; | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Header } from './Header'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import TiptapRow from '@tiptap/extension-table-row'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (testing): Consider adding tests for Row extension. It's crucial to ensure that the Row extension behaves as expected, particularly in terms of handling style attributes. Tests could focus on verifying the correct parsing and rendering of these attributes. |
||
|
||
export const Row = TiptapRow.extend({ | ||
addAttributes() { | ||
return { | ||
...this.parent?.(), | ||
style: { | ||
parseHTML: (element) => element.getAttribute('style'), | ||
}, | ||
}; | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { Row } from './Row'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { TableImproved } from './TableImproved'; | ||
export { Cell } from './Cell'; | ||
export { Row } from './Row'; | ||
export { Header } from './Header'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (testing): Consider adding tests for GlobalAttributes extension.
It's important to ensure that the GlobalAttributes extension correctly parses and renders HTML attributes as expected. This could include testing various HTML elements with different attributes to verify that they are handled correctly.