Skip to content

Commit

Permalink
fix: parse xml element
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs committed Apr 12, 2024
1 parent 22db986 commit 1544fda
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/data-types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const YTypePreComponent = ({
showDelta: config.showDelta,
});
if (typeof parsedValue === "string") {
return null;
return <TypeLabel value={value} />;
}
return (
<span>
Expand Down
File renamed without changes.
23 changes: 23 additions & 0 deletions src/y-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ export function isYXmlFragment(value: unknown): value is Y.XmlFragment {
return value instanceof Y.XmlFragment;
}

export function isYXmlText(value: unknown): value is Y.XmlText {
return value instanceof Y.XmlText;
}

export function isYAbstractType(
value: unknown,
): value is Y.AbstractType<unknown> {
Expand Down Expand Up @@ -130,6 +134,25 @@ export function parseYType(
return value.toString();
}

if (isYXmlElement(value)) {
return {
nodeName: value.nodeName,
attributes: value.getAttributes(),
"toString()": value.toString(),
};
}

if (isYXmlFragment(value)) {
return value.toJSON();
}

if (isYXmlText(value)) {
if (showDelta) {
return value.toDelta();
}
return value.toString();
}

return value;
}

Expand Down

0 comments on commit 1544fda

Please sign in to comment.