From e202e59c2a62db6d8c3480c756a81a316c6dd42b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EB=A5=98=EC=84=A0=EC=9E=84?= Date: Wed, 16 Dec 2020 19:18:06 +0900 Subject: [PATCH] fix: broken cell with html when using org-data-content (#1313) * fix: broken cell with html when using org-data-content * fix: change broken test case * chore: remove unused module import --- plugins/table-merged-cell/src/js/renderer.js | 5 - .../table-merged-cell/src/js/tableRenderer.js | 10 - .../src/js/toMarkRenderer.js | 17 +- .../test/mergedTableParser.spec.js | 326 +++++++++--------- .../test/tableRenderer.spec.js | 8 +- .../test/toMarkRenderer.spec.js | 18 +- 6 files changed, 179 insertions(+), 205 deletions(-) diff --git a/plugins/table-merged-cell/src/js/renderer.js b/plugins/table-merged-cell/src/js/renderer.js index 4c8bb6b9a1..4c388c80df 100644 --- a/plugins/table-merged-cell/src/js/renderer.js +++ b/plugins/table-merged-cell/src/js/renderer.js @@ -1,5 +1,3 @@ -import encodeHTMLEntity from 'tui-code-snippet/string/encodeHTMLEntity'; - export const renderer = { tableRow(node, { entering, origin }) { if (entering) { @@ -48,9 +46,6 @@ export const renderer = { if (entering) { const { attributes = {} } = result; - if (node.orgStringContent) { - attributes['data-org-content'] = encodeHTMLEntity(node.orgStringContent); - } if (node.colspan) { attributes.colspan = node.colspan; } diff --git a/plugins/table-merged-cell/src/js/tableRenderer.js b/plugins/table-merged-cell/src/js/tableRenderer.js index 7e3a559f3d..9b077a55d8 100644 --- a/plugins/table-merged-cell/src/js/tableRenderer.js +++ b/plugins/table-merged-cell/src/js/tableRenderer.js @@ -2,8 +2,6 @@ * @fileoverview Implements tableRenderer * @author NHN FE Development Lab */ -import encodeHTMLEntity from 'tui-code-snippet/string/encodeHTMLEntity'; - import tableDataHandler from './tableDataHandler'; /** @@ -14,24 +12,16 @@ import tableDataHandler from './tableDataHandler'; */ function _createCellHtml(cell) { const { colspan, rowspan, align, nodeName, content } = cell; - let orgContent = ''; let attrs = ''; if (colspan > 1) { attrs = ` colspan="${colspan}"`; - orgContent = `@cols=${colspan}:`; } if (rowspan > 1) { attrs += ` rowspan="${rowspan}"`; - orgContent += `@rows=${rowspan}:`; } attrs += align ? ` align="${align}"` : ''; - if (orgContent) { - orgContent += content; - attrs += ` data-org-content="${encodeHTMLEntity(orgContent)}"`; - } - return `<${nodeName}${attrs}>${content}`; } diff --git a/plugins/table-merged-cell/src/js/toMarkRenderer.js b/plugins/table-merged-cell/src/js/toMarkRenderer.js index cbbe89a23a..1c5220b09d 100644 --- a/plugins/table-merged-cell/src/js/toMarkRenderer.js +++ b/plugins/table-merged-cell/src/js/toMarkRenderer.js @@ -86,19 +86,20 @@ export function _createTheadMarkdown(theadElement, theadContentMarkdown) { * @private */ export function _createTableCellMarkdown(cellElement, cellContentMarkdown) { - const orgContent = cellElement.getAttribute('data-org-content'); + let markdown = ''; - if (orgContent) { - const matched = orgContent.match(/(@(cols|rows)=[0-9]+:)/g); + if (cellElement.hasAttribute('colspan')) { + markdown += `@cols=${cellElement.getAttribute('colspan')}:`; + } - if (matched) { - cellContentMarkdown = matched.join('') + cellContentMarkdown; - } + if (cellElement.hasAttribute('rowspan')) { + markdown += `@rows=${cellElement.getAttribute('rowspan')}:`; } - cellContentMarkdown = cellContentMarkdown.replace(/(\r\n)|(\r)|(\n)/g, ''); + markdown += cellContentMarkdown; + markdown = markdown.replace(/(\r\n)|(\r)|(\n)/g, ''); - return ` ${cellContentMarkdown} |`; + return ` ${markdown} |`; } export function createToMarkRenderer(baseRenderer) { diff --git a/plugins/table-merged-cell/test/mergedTableParser.spec.js b/plugins/table-merged-cell/test/mergedTableParser.spec.js index 3c5e456ead..96fe677a79 100644 --- a/plugins/table-merged-cell/test/mergedTableParser.spec.js +++ b/plugins/table-merged-cell/test/mergedTableParser.spec.js @@ -21,14 +21,14 @@ describe('should render the merged table properly', () => { - - + + - - + +
head1head2head1head2
cell1cell2cell1cell2
@@ -50,16 +50,16 @@ describe('should render the merged table properly', () => { - - + + - - - - + + + +
mergedHead1mergedHead2mergedHead1mergedHead2
cell1cell2cell3cell4cell1cell2cell3cell4
@@ -81,15 +81,15 @@ describe('should render the merged table properly', () => { - - + + - - - + + +
mergedHead1mergedHead2mergedHead1mergedHead2
mergedCell1cell2cell3mergedCell1cell2cell3
@@ -112,17 +112,17 @@ describe('should render the merged table properly', () => { - - + + - - + + - +
head1head2head1head2
cell1-1cell1-2cell1-1cell1-2
cell2-1cell2-1
@@ -151,37 +151,37 @@ describe('should render the merged table properly', () => { - - + + - - - + + + - - - - + + + + - - - + + + - - - + + + - - - - + + + +
mergedHead1mergedHead2mergedHead1mergedHead2
mergedCell1-1cell1-2cell1-3mergedCell1-1cell1-2cell1-3
mergedCell2-1cell2-2cell2-3cell2-4mergedCell2-1cell2-2cell2-3cell2-4
cell3-1cell3-2cell3-3cell3-1cell3-2cell3-3
cell4-1cell4-2cell4-3cell4-1cell4-2cell4-3
cell5-1cell5-2cell5-3cell5-4cell5-1cell5-2cell5-3cell5-4
@@ -202,33 +202,33 @@ describe('should render the merged table properly', () => { - - + + - - - + + + - - - - + + + + - - - + + + - - + + - +
mergedHead1mergedHead2mergedHead1mergedHead2
mergedCell1-1cell1-2cell1-3mergedCell1-1cell1-2cell1-3
mergedCell2-1cell2-2cell2-3cell2-4mergedCell2-1cell2-2cell2-3cell2-4
cell3-1cell3-2cell3-3cell3-1cell3-2cell3-3
cell4-1cell4-2cell4-1cell4-2
cell5-1cell5-1
@@ -250,38 +250,38 @@ describe('should render the merged table properly', () => { - - + + - - - + + + - - - - + + + + - - - + + + - - + + - + - - - + + +
mergedHead1mergedHead2mergedHead1mergedHead2
mergedCell1-1cell1-2cell1-3mergedCell1-1cell1-2cell1-3
mergedCell2-1cell2-2cell2-3cell2-4mergedCell2-1cell2-2cell2-3cell2-4
cell3-1cell3-2cell3-3cell3-1cell3-2cell3-3
cell4-1cell4-2cell4-1cell4-2
cell5-1cell5-1
cell6-1cell6-2cell6-3cell6-1cell6-2cell6-3
@@ -303,54 +303,54 @@ describe('should render the merged table properly', () => { - - + + - - - - - - + + + + + + - - - - - - + + + + + + - - - - - + + + + + - - - - + + + + - - - - + + + + - - - - - + + + + + @@ -372,38 +372,38 @@ describe('should render the merged table properly', () => {
mergedHead1mergedHead2mergedHead1mergedHead2
mergedCell1-1cell1-2cell1-3cell1-4cell1-5cell1-6mergedCell1-1cell1-2cell1-3cell1-4cell1-5cell1-6
mergedCell2-1mergedCell2-2cell2-3cell2-4cell2-5cell2-6mergedCell2-1mergedCell2-2cell2-3cell2-4cell2-5cell2-6
cell3-1cell3-2cell3-3cell3-4cell3-5cell3-1cell3-2cell3-3cell3-4cell3-5
mergedCell4-1cell4-2cell4-3cell4-4mergedCell4-1cell4-2cell4-3cell4-4
mergedCell5-1cell5-2cell5-3cell5-4mergedCell5-1cell5-2cell5-3cell5-4
cell6-1cell6-2cell6-3cell6-4cell6-5cell6-1cell6-2cell6-3cell6-4cell6-5
- - + + - - - - - + + + + + - - - - - + + + + + - - + + - - + + - - + +
mergedHead1mergedHead2mergedHead1mergedHead2
mergedCell1-1cell1-2mergedCell1-3cell1-4cell1-5mergedCell1-1cell1-2mergedCell1-3cell1-4cell1-5
mergedCell2-1mergedCell2-2cell2-3cell2-4cell2-5mergedCell2-1mergedCell2-2cell2-3cell2-4cell2-5
cell3-1cell3-2cell3-1cell3-2
mergedCell4-1cell4-2mergedCell4-1cell4-2
cell5-1cell5-2cell5-1cell5-2
@@ -424,33 +424,33 @@ describe('should render the merged table properly', () => { - - + + - - - + + + - - - + + + - + - - + + - - - + + +
mergedHead1mergedHead2mergedHead1mergedHead2
mergedCell1-1cell1-2mergedCell1-3mergedCell1-1cell1-2mergedCell1-3
mergedCell2-1mergedCell2-2cell2-3mergedCell2-1mergedCell2-2cell2-3
cell3-1cell3-1
cell4-1cell4-2cell4-1cell4-2
cell5-1cell5-2cell5-3cell5-1cell5-2cell5-3
@@ -471,30 +471,30 @@ describe('should render the merged table properly', () => { - - + + - - - + + + - - + + - - + + - - - + + +
mergedHead1mergedHead2mergedHead1mergedHead2
mergedCell1-1mergedCell1-2mergedCell1-3mergedCell1-1mergedCell1-2mergedCell1-3
mergedCell2-1mergedCell2-2mergedCell2-1mergedCell2-2
cell4-1cell4-2cell4-1cell4-2
cell5-1cell5-2cell5-3cell5-1cell5-2cell5-3
@@ -515,33 +515,33 @@ describe('should render the merged table properly', () => { - - + + - - - + + + - - - - + + + + - - - + + + - - + + - +
foo"bar"bazfoo"bar"baz
foo"bar"cell1-2cell1-3foo"bar"cell1-2cell1-3
bazcell2-2cell2-3cell2-4bazcell2-2cell2-3cell2-4
cell3-1cell3-2cell3-3cell3-1cell3-2cell3-3
foo"bar"bazcell4-2foo"bar"bazcell4-2
cell5-1cell5-1
diff --git a/plugins/table-merged-cell/test/tableRenderer.spec.js b/plugins/table-merged-cell/test/tableRenderer.spec.js index 61e693039f..b115e1d1f3 100644 --- a/plugins/table-merged-cell/test/tableRenderer.spec.js +++ b/plugins/table-merged-cell/test/tableRenderer.spec.js @@ -60,11 +60,9 @@ describe('tableRenderer', () => { 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:baz' + expect(tableElement.querySelector('th').outerHTML).toBe('foo"bar"'); + expect(tableElement.querySelector('td').outerHTML).toBe( + 'baz' ); }); }); diff --git a/plugins/table-merged-cell/test/toMarkRenderer.spec.js b/plugins/table-merged-cell/test/toMarkRenderer.spec.js index 034d2f07dc..8cf5bb99f2 100644 --- a/plugins/table-merged-cell/test/toMarkRenderer.spec.js +++ b/plugins/table-merged-cell/test/toMarkRenderer.spec.js @@ -68,7 +68,7 @@ describe('toMarkRendererCreator', () => { describe('_createTableCellMarkdown() should create table cell markdown properly', () => { it('basic cell ', () => { - const cellHtml = 'title1'; + const cellHtml = 'title1'; const [cellElement] = createElement(cellHtml, 'th'); const cellContent = 'title1'; const actual = _createTableCellMarkdown(cellElement, cellContent); @@ -77,7 +77,7 @@ describe('toMarkRendererCreator', () => { }); it('with colspan', () => { - const cellHtml = 'title1'; + const cellHtml = 'title1'; const [cellElement] = createElement(cellHtml, 'th'); const cellContent = 'title1'; const actual = _createTableCellMarkdown(cellElement, cellContent); @@ -86,22 +86,12 @@ describe('toMarkRendererCreator', () => { }); it('with colspan, rowspan', () => { - const cellHtml = 'title1'; + const cellHtml = 'title1'; const [cellElement] = createElement(cellHtml, 'th'); const cellContent = 'title1'; const actual = _createTableCellMarkdown(cellElement, cellContent); - expect(actual).toBe(' @rows=2:@cols=2:title1 |'); - }); - - it('with changed cell content', () => { - const cellHtml = - 'changed-title1'; - const [cellElement] = createElement(cellHtml, 'th'); - const cellContent = 'changed-title1'; - const actual = _createTableCellMarkdown(cellElement, cellContent); - - expect(actual).toBe(' @rows=2:@cols=2:changed-title1 |'); + expect(actual).toBe(' @cols=2:@rows=2:title1 |'); }); }); });