Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Jul 5, 2024
1 parent 05b9ae3 commit 46e0391
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 21 deletions.
45 changes: 25 additions & 20 deletions src/converters/fromDraftjs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -455,37 +455,42 @@ describe('convertFromDraftJS parsing draftjs blockquote', () => {
// const draftjs = {
// blocks: [
// {
// key: 'jrnb',
// text: 'Trasporto delle persone con difficoltà motorie ai seggi\nIl Comune di Cavriago, in collaborazione con l’Associazione “NOI CON VOI”, organizza il trasporto delle persone disabili mediante il pulmino adibito appositamente a tale servizio.\nIl servizio verrà effettuato nei seguenti orari:\nSABATO 8 GIUGNO dalle 15.00 alle 17.00\nDOMENICA 9 GIUGNO dalle 10.00 alle 12.00.\nIl trasporto dovrà essere prenotato direttamente all’associazione al numero 333 5383663 (Ines).\n',
// type: 'callout',
// data: {},
// depth: 0,
// inlineStyleRanges: [
// {
// offset: 0,
// length: 56,
// style: 'BOLD',
// },
// entityRanges: [
// {
// offset: 116,
// length: 13,
// style: 'BOLD',
// key: 0,
// length: 5,
// offset: 18,
// },
// ],
// inlineStyleRanges: [
// {
// offset: 285,
// length: 81,
// length: 5,
// offset: 6,
// style: 'BOLD',
// },
// {
// offset: 443,
// length: 11,
// style: 'BOLD',
// length: 5,
// offset: 12,
// style: 'TEXT_LARGER',
// },
// ],
// entityRanges: [],
// data: {},
// key: 'i5b8',
// text: 'Testo testo testo testo ',
// type: 'unstyled',
// },
// ],
// entityMap: {},
// entityMap: {
// 0: {
// data: {
// dataElement: '',
// url: 'http://www.google.it',
// },
// mutability: 'MUTABLE',
// type: 'LINK',
// },
// },
// };
// describe('with html converter', () => {
// const result = converFromDraftJS(draftjs);
Expand Down
7 changes: 6 additions & 1 deletion src/converters/slate.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const bTagDeserializer = (el) => {

const spanTagDeserializer = (el) => {
const style = (el.getAttribute('style') || '').replace(/\s/g, '');
const className = el.getAttribute('class');
let children = el.childNodes;
if (children.length === 1) {
const child = children[0];
Expand Down Expand Up @@ -95,7 +96,11 @@ const spanTagDeserializer = (el) => {
// Handle Google Docs' <sup> formatting
children = jsx('element', { type: 'sup' }, children);
}
return jsx('fragment', {}, children);
const data = jsx('fragment', {}, children);
if (className === 'text-larger') {
data[0]['style-text-larger'] = true;
}
return data;
}
};

Expand Down
13 changes: 13 additions & 0 deletions src/converters/slate.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,19 @@ describe('slateTextBlock processing a paragraph', () => {
});
});

describe('slateTextBlock processing a simple span block', () => {
const elem = elementFromString('<span class="text-larger">large text</span>');

test('will have a formated block', () => {
const result = slateTextBlock(elem);
const valueElement = result.value[0];
expect(valueElement).toEqual({
'style-text-larger': true,
text: 'large text',
});
});
});

describe('slateTextBlock processing a simple pre block', () => {
const elem = elementFromString(
'<pre>Plone Foundation: https://plone.org/</pre>',
Expand Down

0 comments on commit 46e0391

Please sign in to comment.