New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@plone/blocks-conversion-tool

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@plone/blocks-conversion-tool - npm Package Compare versions

Comparing version

to
0.4.8

@@ -0,1 +1,8 @@

### [0.4.8](https://github.com/plone/blocks-conversion-tool/compare/0.4.7...0.4.8) (2023-07-03)
### Bug Fixes
* Table cell parsing (Fixes [#31](https://github.com/plone/blocks-conversion-tool/issues/31)) ([0500c3d](https://github.com/plone/blocks-conversion-tool/commit/0500c3d29fb9042f7baef79f122dbb5b583d82c5))
### [0.4.7](https://github.com/plone/blocks-conversion-tool/compare/0.4.6...0.4.7) (2023-06-06)

@@ -2,0 +9,0 @@

{
"name": "@plone/blocks-conversion-tool",
"version": "0.4.7",
"version": "0.4.8",
"private": false,

@@ -5,0 +5,0 @@ "type": "module",

@@ -7,2 +7,3 @@ import jsdom from 'jsdom';

groupInlineNodes,
isInline,
isWhitespace,

@@ -93,5 +94,2 @@ isGlobalInline,

const isInline = (n) =>
n.nodeType === TEXT_NODE || isGlobalInline(n.tagName.toLowerCase());
const extractElementsWithConverters = (el, defaultTextBlock, href) => {

@@ -98,0 +96,0 @@ const result = [];

@@ -293,3 +293,8 @@ import { jsx } from 'slate-hyperscript';

const cellValue = deserializeChildren(cell);
cells.push(createCell(cellType, cellValue));
const elements = cellValue.map((element) =>
isInline(element)
? jsx('element', { type: 'span' }, [element])
: element,
);
cells.push(createCell(cellType, elements));
}

@@ -296,0 +301,0 @@ rows.push({ key: getId(), cells });

@@ -643,3 +643,5 @@ import { elementFromString } from '../helpers/dom.js';

expect(rows[0].cells[0].value).toHaveLength(1);
const value = rows[0].cells[0].value[0];
const parentValue = rows[0].cells[0].value[0];
expect(parentValue['type']).toBe('span');
const value = parentValue['children'][0];
expect(value['text']).toBe('A value');

@@ -661,3 +663,6 @@ });

const cell = cells[0];
expect(cell.value).toEqual([{ text: 'A value\n\xa0' }]);
const parentValue = cell.value[0];
expect(parentValue['type']).toBe('span');
const value = parentValue['children'][0];
expect(value).toEqual({ text: 'A value' });
});

@@ -683,3 +688,5 @@ });

expect(rows[0].cells[0].value).toHaveLength(1);
const value = rows[0].cells[0].value[0];
const parentValue = rows[0].cells[0].value[0];
expect(parentValue['type']).toBe('span');
const value = parentValue['children'][0];
expect(value['type']).toBe('link');

@@ -713,10 +720,14 @@ expect(value['data']['url']).toBe('https://plone.org');

const rows = result.table.rows;
let value = rows[0].cells[0].value[0];
const parentValue = rows[0].cells[0].value[0];
expect(parentValue['type']).toBe('span');
const value = parentValue['children'][0];
expect(value['text']).toBe('Plone ');
});
test('second value is the link', () => {
test('second value is the span with the link', () => {
const result = slateTableBlock(elem);
const rows = result.table.rows;
let value = rows[0].cells[0].value[1];
const parentValue = rows[0].cells[0].value[1];
expect(parentValue['type']).toBe('span');
const value = parentValue['children'][0];
expect(value['type']).toBe('link');

@@ -736,9 +747,16 @@ expect(value['data']['url']).toBe('https://plone.org');

const cell = result.table.rows[0].cells[0];
expect(cell.value).toEqual([
{ text: '10' },
{
type: 'sup',
children: [{ text: '2' }],
},
]);
expect(cell.value).toHaveLength(2);
expect(cell.value[0]).toEqual({
type: 'span',
children: [{ text: '10' }],
});
expect(cell.value[1]).toEqual({
type: 'span',
children: [
{
type: 'sup',
children: [{ text: '2' }],
},
],
});
});

@@ -752,9 +770,46 @@ });

test('will remove the div', () => {
test('will replace the div with a paragraph', () => {
const result = slateTableBlock(elem);
const cell = result.table.rows[0].cells[0];
expect(cell.value).toEqual([
{ type: 'strong', children: [{ text: 'text' }] },
{
type: 'span',
children: [{ type: 'strong', children: [{ text: 'text' }] }],
},
]);
});
});
describe('slateTableBlock parsing table with bold text', () => {
const elem = elementFromString(
'<table class="plain">\n<tbody>\n<tr><td><b>Text1</b></td></tr>\n</tbody>\n</table>',
);
test('returns valid result with the correct children', () => {
const block = slateTableBlock(elem);
expect(block['@type']).toEqual('slateTable');
const rows = block['table']['rows'];
expect(rows).toHaveLength(1);
const cells = rows[0]['cells'];
expect(cells).toHaveLength(1);
const value = cells[0]['value'][0];
expect(value['type']).toEqual('span');
expect(value['children'][0]['type']).toEqual('strong');
});
});
describe('slateTableBlock parsing table with line break', () => {
const elem = elementFromString(
'<table class="plain">\n<tbody>\n<tr><td><br/>Text</td></tr>\n</tbody>\n</table>',
);
test('returns valid result with the correct children', () => {
const block = slateTableBlock(elem);
expect(block['@type']).toEqual('slateTable');
const rows = block['table']['rows'];
expect(rows).toHaveLength(1);
const cells = rows[0]['cells'];
expect(cells).toHaveLength(1);
const value = cells[0]['value'][0];
expect(value['type']).toEqual('span');
expect(value['children'][0]['text']).toEqual('\n');
});
});

@@ -6,2 +6,4 @@ import jsdom from 'jsdom';

const TEXT_NODE = 3;
const elementFromString = (value) => {

@@ -55,2 +57,11 @@ const elem = parser.parseFromString(value, 'text/html').body.firstChild;

export { elementFromString, isWhitespace, isGlobalInline, groupInlineNodes };
const isInline = (n) =>
n.nodeType === TEXT_NODE || isGlobalInline(n.tagName.toLowerCase());
export {
elementFromString,
isInline,
isWhitespace,
isGlobalInline,
groupInlineNodes,
};