Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: broken cell redering with span tag using table-merged-cell plugin (fix #1059) #1060

Merged
merged 4 commits into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion plugins/table-merged-cell/src/js/renderer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import encodeHTMLEntity from 'tui-code-snippet/string/encodeHTMLEntity';

export const renderer = {
tableRow(node, { entering, origin }) {
if (entering) {
Expand Down Expand Up @@ -47,7 +49,7 @@ export const renderer = {
const { attributes = {} } = result;

if (node.orgStringContent) {
attributes['data-org-content'] = node.orgStringContent;
attributes['data-org-content'] = encodeHTMLEntity(node.orgStringContent);
}
if (node.colspan) {
attributes.colspan = node.colspan;
Expand Down
4 changes: 3 additions & 1 deletion plugins/table-merged-cell/src/js/tableRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
* @fileoverview Implements tableRenderer
* @author NHN FE Development Lab <dl_javascript@nhn.com>
*/
import encodeHTMLEntity from 'tui-code-snippet/string/encodeHTMLEntity';

import tableDataHandler from './tableDataHandler';

/**
Expand All @@ -27,7 +29,7 @@ function _createCellHtml(cell) {

if (orgContent) {
orgContent += content;
attrs += ` data-org-content="${orgContent}"`;
attrs += ` data-org-content="${encodeHTMLEntity(orgContent)}"`;
}

return `<${nodeName}${attrs}>${content}</${nodeName}>`;
Expand Down
31 changes: 31 additions & 0 deletions plugins/table-merged-cell/test/tableRenderer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ import $ from 'jquery';
import tableDataHandler from '@/tableDataHandler';
import tableRenderer from '@/tableRenderer';

function createElement(html) {
const container = document.createElement('div');

container.innerHTML = html;

return container;
}

describe('tableRenderer', () => {
describe('createTableHtml()', () => {
it('when correct contents in table tag', () => {
Expand Down Expand Up @@ -35,5 +43,28 @@ describe('tableRenderer', () => {

expect(result).toBe('<table></table>');
});

it('if the html entities (", <, >) are included in the cell data, the table is created correctly', () => {
const tableHtml = [
'<table>',
'<thead>',
'<tr><th colspan="2">foo"bar"</th></tr>',
'</thead>',
'<tbody>',
'<tr><td colspan="2"><span style="color:red;">baz</span></td></tr>',
'</tbody>',
'</table>'
].join('');
seonim-ryu marked this conversation as resolved.
Show resolved Hide resolved
const renderData = tableDataHandler.createTableData(createElement(tableHtml));
const result = tableRenderer.createTableHtml(renderData);
const tableElement = createElement(result);

expect(tableElement.querySelector('th').getAttribute('data-org-content')).toBe(
'@cols=2:foo"bar"'
);
expect(tableElement.querySelector('td').getAttribute('data-org-content')).toBe(
'@cols=2:<span style="color:red;">baz</span>'
);
});
});
});