Skip to content

Commit

Permalink
fix: broken cell with html when using org-data-content (#1313)
Browse files Browse the repository at this point in the history
* fix: broken cell with html when using org-data-content

* fix: change broken test case

* chore: remove unused module import
  • Loading branch information
seonim-ryu authored Dec 16, 2020
1 parent a54a552 commit e202e59
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 205 deletions.
5 changes: 0 additions & 5 deletions plugins/table-merged-cell/src/js/renderer.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import encodeHTMLEntity from 'tui-code-snippet/string/encodeHTMLEntity';

export const renderer = {
tableRow(node, { entering, origin }) {
if (entering) {
Expand Down Expand Up @@ -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;
}
Expand Down
10 changes: 0 additions & 10 deletions plugins/table-merged-cell/src/js/tableRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
* @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 @@ -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}</${nodeName}>`;
}

Expand Down
17 changes: 9 additions & 8 deletions plugins/table-merged-cell/src/js/toMarkRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit e202e59

Please sign in to comment.