-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Extract inline fragments from HTML markup #1801
base: next
Are you sure you want to change the base?
Conversation
* @private | ||
*/ | ||
public insertInlineFragments(data: Pick<SavedData, 'data'>, fragmentsDict: InlineFragmentsDict): Pick<SavedData, 'data'> { | ||
const insertToString = (str: string, fragments: InlineFragment[]): string => { |
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.
It could be moved to the utility method
startOffset = fragment.range[0] - offset; | ||
} | ||
|
||
if (!endNode && offset + node.textContent.length >= fragment.range[1]) { |
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.
duplicated code fragment, could be moved to the function
return template.innerHTML; | ||
}; | ||
|
||
const insert = (dataToProcess: Record<string, unknown>, fragments: InlineFragmentsDict): Pick<SavedData, 'data'> => { |
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.
It could be moved to the utility method
return; | ||
} | ||
|
||
if (typeof value === 'object') { |
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.
use our internal isObject
method
if (typeof value === 'string') { | ||
dataToProcess[key] = insertToString(value, fragments[key] as InlineFragment[]); | ||
} | ||
}); |
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.
what if value is another type? number, function, promise etc?
src/components/modules/saver.ts
Outdated
return Tools.blockTools.get(name).sanitizeConfig; | ||
}); | ||
const withFragments = sanitizedData.map(savedData => { |
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.
comment needed. Maybe could be moved to the separate method
case Node.ELEMENT_NODE: { | ||
const length = node.textContent.length; | ||
const fragment: InlineFragment = { | ||
range: [offset, offset + length], |
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.
comment needed
* @private | ||
*/ | ||
private extractInlineFragments(data: Pick<SavedData, 'data'>): InlineFragmentsDict { | ||
const extractFromString = (str: string): InlineFragment[] => { |
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.
utility?
attributes: Object.fromEntries(Array.from((node as HTMLElement).attributes).map(attr => ([attr.nodeName, attr.nodeValue]))), | ||
}; | ||
|
||
fragments.push(fragment); |
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.
what if a fragment contains its own children with fragments?
@@ -0,0 +1,9 @@ | |||
export interface InlineFragment { |
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.
descriptions missed
…lean-inline-fragments
…lean-inline-fragments
…lean-inline-fragments
Todo list:
|
…lean-inline-fragments
No description provided.