Skip to content
This repository has been archived by the owner on Oct 25, 2022. It is now read-only.

Commit

Permalink
Added span deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiuichim committed Jul 27, 2020
1 parent be30a7c commit 5e61ad9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/editor/config.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
bodyTagDeserializer,
blockTagDeserializer,
preTagDeserializer,
spanDeserializer,
} from './deserialize';

// Registry of available buttons
Expand Down Expand Up @@ -175,7 +176,7 @@ export const htmlTagsToSlate = {
SUP: inlineTagDeserializer({ sup: true }),
STRONG: inlineTagDeserializer({ bold: true }),
U: inlineTagDeserializer({ underline: true }),
// SPAN: inlineTagDeserializer(),
SPAN: spanDeserializer,

// OL: listElementToSlateDeserializer('ol'),
// UL: listElementToSlateDeserializer('ul'),
Expand Down
21 changes: 21 additions & 0 deletions src/editor/deserialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,24 @@ export const inlineTagDeserializer = (attrs) => (editor, el) => {
return jsx('text', attrs, child);
});
};

export const spanDeserializer = (editor, el) => {
const style = el.getAttribute('style') || '';
if (style.indexOf('vertical-align:super') > -1) {
const children = Array.from(el.childNodes)
.map((el) => deserialize(editor, el))
.flat();
const attrs = { sup: true };
return children.map((child) => {
return jsx('text', attrs, child);
});
}
const children = Array.from(el.childNodes)
.map((el) => {
console.log('el', el);
return deserialize(editor, el);
})
.flat();

return children;
};

0 comments on commit 5e61ad9

Please sign in to comment.