MCPcopy Create free account
hub / github.com/handsontable/handsontable / _dataToHTML

Function _dataToHTML

handsontable/src/utils/parseTable.ts:112–153  ·  view source on GitHub ↗
(input: unknown[][])

Source from the content-addressed store, hash-verified

110 */
111// eslint-disable-next-line no-restricted-globals
112export function _dataToHTML(input: unknown[][]): string {
113 const inputLen = input.length;
114 const result = ['<table>'];
115
116 for (let row = 0; row < inputLen; row += 1) {
117 const rowData = input[row];
118 const columnsLen = rowData.length;
119 const columnsResult = [];
120
121 if (row === 0) {
122 result.push('<tbody>');
123 }
124
125 for (let column = 0; column < columnsLen; column += 1) {
126 const cellData = rowData[column];
127 const parsedCellData = isEmpty(cellData) ?
128 '' :
129 (cellData as { toString(): string }).toString()
130 .replaceAll('&', '&amp;')
131 .replaceAll('<', '&lt;')
132 .replaceAll('>', '&gt;')
133 .replace(/(<br(\s*|\/)>(\r\n|\n)?|\r\n|\n)/g, '<br>\r\n')
134 .replace(/\x20{2,}/gi, (substring: string) => {
135 // The way how Excel serializes data with at least two spaces.
136 return `<span style="mso-spacerun: yes">${'&nbsp;'.repeat(substring.length - 1)} </span>`;
137 })
138 .replace(/\t/gi, '&#9;');
139
140 columnsResult.push(`<td>${parsedCellData}</td>`);
141 }
142
143 result.push('<tr>', ...columnsResult, '</tr>');
144
145 if (row + 1 === inputLen) {
146 result.push('</tbody>');
147 }
148 }
149
150 result.push('</table>');
151
152 return result.join('');
153}
154
155const TD_OPEN = /<td\b[^>]*>/i;
156const TD_CLOSE = /<\/\s*td\s*>/i;

Callers 2

parseTable.unit.tsFile · 0.90
#setClipboardDataMethod · 0.90

Calls 3

isEmptyFunction · 0.90
replaceMethod · 0.80
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…