react-markdown-table-ts 0.5.6 → 0.5.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -63
- package/dist/index.cjs.js +129 -112
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +129 -112
- package/dist/index.esm.js.map +1 -1
- package/dist/types.d.ts +4 -0
- package/dist/utils.d.ts +28 -25
- package/package.json +1 -1
package/README.md
CHANGED
@@ -1,63 +1,65 @@
|
|
1
|
-
# ⚛️ react-markdown-table-ts 🛡️
|
2
|
-
|
3
|
-
[](https://www.npmjs.com/package/react-markdown-table-ts)
|
4
|
-

|
5
|
-
[](https://codecov.io/gh/keithwalsh/react-markdown-table-ts)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
- **
|
14
|
-
- **
|
15
|
-
- **
|
16
|
-
- **
|
17
|
-
- **
|
18
|
-
- **
|
19
|
-
- **
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
['
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
1
|
+
# ⚛️ react-markdown-table-ts 🛡️
|
2
|
+
|
3
|
+
[](https://www.npmjs.com/package/react-markdown-table-ts)
|
4
|
+

|
5
|
+
[](https://codecov.io/gh/keithwalsh/react-markdown-table-ts)
|
6
|
+
[](https://packagequality.com/#?package=react-markdown-table-ts)
|
7
|
+
[](https://codeclimate.com/github/keithwalsh/react-markdown-table-ts)
|
8
|
+
|
9
|
+
A React component that converts structured data into Markdown table syntax and displays it within a `<pre>` tag.
|
10
|
+
|
11
|
+
## ✨ Features
|
12
|
+
|
13
|
+
- **Type Safety:** Built with TypeScript to provide strong type guarantees.
|
14
|
+
- **Easy Integration:** Simple API for converting data arrays into Markdown table strings.
|
15
|
+
- **Customizable Alignments:** Specify column alignments (left, center, right, or none) with ease.
|
16
|
+
- **Compact Mode:** Option to generate compact tables with minimal padding.
|
17
|
+
- **Tab-Separated Columns:** Option to add tabs between columns.
|
18
|
+
- **Newline Handling: Option** to replace newlines in cells with HTML line breaks.
|
19
|
+
- **Raw Markdown Access:** Retrieve the generated Markdown string for further processing or usage.
|
20
|
+
- **Header Options:** Choose whether to include a header row or use default alphabetical headers.
|
21
|
+
- **Flexible Styling:** Apply custom CSS classes for styling the rendered Markdown.
|
22
|
+
|
23
|
+
## 📦 Installation
|
24
|
+
|
25
|
+
Install the package via npm:
|
26
|
+
|
27
|
+
```
|
28
|
+
|
29
|
+
npm install react-markdown-table-ts
|
30
|
+
|
31
|
+
```
|
32
|
+
|
33
|
+
## 🔧 API
|
34
|
+
|
35
|
+
### MarkdownTable Props
|
36
|
+
|
37
|
+
| Prop | Type | Default | Description |
|
38
|
+
| :------------------: | :-------------------------------------------: | :---------: | :-----------------------------------------: |
|
39
|
+
| `data` | `string[][]` | `null` | The table data as a 2D array of strings |
|
40
|
+
| `columnAlignments` | `('left' \| 'center' \| 'right' \| 'none')[]` | `[]` | Alignment for each column |
|
41
|
+
| `isCompact` | `boolean` | `false` | Use minimal column widths |
|
42
|
+
| `className` | `string` | `undefined` | CSS class for the `<pre>` tag |
|
43
|
+
| `hasTabs` | `boolean` | `false` | Add tabs between table columns |
|
44
|
+
| `canReplaceNewlines` | `boolean` | `false` | Replace newlines in cells with `<br>` tags |
|
45
|
+
| `onTableCreate` | `(markdownString: string) => void` | `undefined` | Callback to receive the Markdown string |
|
46
|
+
| `hasHeader` | `boolean` | `true` | Whether the first row of `data` is a header |
|
47
|
+
|
48
|
+
## 🚀 Usage
|
49
|
+
|
50
|
+
```jsx
|
51
|
+
import React from 'react';
|
52
|
+
import {MarkdownTable} from 'markdown-table-component';
|
53
|
+
|
54
|
+
const App = () => {
|
55
|
+
const data = [
|
56
|
+
['Header 1', 'Header 2', 'Header 3'],
|
57
|
+
['Row 1, Col 1', 'Row 1, Col 2', 'Row 1, Col 3'],
|
58
|
+
['Row 2, Col 1', 'Row 2, Col 2', 'Row 2, Col 3'],
|
59
|
+
];
|
60
|
+
|
61
|
+
return <MarkdownTable data={data} />;
|
62
|
+
};
|
63
|
+
|
64
|
+
export default App;
|
65
|
+
```
|
package/dist/index.cjs.js
CHANGED
@@ -4095,6 +4095,17 @@ var MarkdownTableError = /** @class */ (function (_super) {
|
|
4095
4095
|
}(Error));
|
4096
4096
|
|
4097
4097
|
// src/utils.ts
|
4098
|
+
/**
|
4099
|
+
* Adjusts column alignments array to match the required column count
|
4100
|
+
* @param columnAlignments - Original alignment settings
|
4101
|
+
* @param columnCount - Required number of columns
|
4102
|
+
* @returns Adjusted array of column alignments
|
4103
|
+
*/
|
4104
|
+
function getAdjustedAlignments(columnAlignments, columnCount) {
|
4105
|
+
var defaultAlignment = 'left';
|
4106
|
+
return columnAlignments.length < columnCount
|
4107
|
+
? __spreadArray(__spreadArray([], columnAlignments, true), Array(columnCount - columnAlignments.length).fill(defaultAlignment), true) : columnAlignments.slice(0, columnCount);
|
4108
|
+
}
|
4098
4109
|
/**
|
4099
4110
|
* Calculates the maximum width for each column based on the content.
|
4100
4111
|
* @param tableRows - All rows (header and body) of the table.
|
@@ -4114,30 +4125,20 @@ function calculateColumnWidths(tableRows, maxColumnCount) {
|
|
4114
4125
|
}
|
4115
4126
|
/**
|
4116
4127
|
* Formats a single row into a Markdown-formatted string.
|
4117
|
-
* @param
|
4118
|
-
* @param currentRow - The data of the current row.
|
4119
|
-
* @param columnAlignments - Alignment settings for each column.
|
4120
|
-
* @param columnWidths - Widths of each column.
|
4121
|
-
* @param useTabs - Flag to use tabs between columns.
|
4122
|
-
* @param canReplaceNewlines - Flag to replace newlines with <br> tags.
|
4123
|
-
* @param hasPadding - Flag to add padding spaces around cell content.
|
4128
|
+
* @param params - Object containing formatting options and row data.
|
4124
4129
|
* @returns The Markdown string for the row.
|
4125
4130
|
*/
|
4126
|
-
function formatMarkdownRow(
|
4127
|
-
var
|
4128
|
-
|
4129
|
-
|
4130
|
-
if (hasPadding === void 0) { hasPadding = true; }
|
4131
|
-
var defaultAlignment = 'left';
|
4132
|
-
var adjustedAlignments = columnAlignments.length < columnCount
|
4133
|
-
? __spreadArray(__spreadArray([], columnAlignments, true), Array(columnCount - columnAlignments.length).fill(defaultAlignment), true) : columnAlignments;
|
4131
|
+
function formatMarkdownRow(_a) {
|
4132
|
+
var _b, _c;
|
4133
|
+
var columnCount = _a.columnCount, currentRow = _a.currentRow, columnAlignments = _a.columnAlignments, columnWidths = _a.columnWidths, _d = _a.useTabs, useTabs = _d === void 0 ? false : _d, _e = _a.replaceNewlines, replaceNewlines = _e === void 0 ? false : _e, _f = _a.hasPadding, hasPadding = _f === void 0 ? true : _f;
|
4134
|
+
var adjustedAlignments = getAdjustedAlignments(columnAlignments, columnCount);
|
4134
4135
|
var markdownRow = '|';
|
4135
4136
|
for (var i = 0; i < columnCount; i++) {
|
4136
|
-
var cell = (
|
4137
|
-
if (
|
4137
|
+
var cell = (_b = currentRow[i]) !== null && _b !== void 0 ? _b : '';
|
4138
|
+
if (replaceNewlines) {
|
4138
4139
|
cell = replaceNewlinesInCell(cell);
|
4139
4140
|
}
|
4140
|
-
var alignment = (
|
4141
|
+
var alignment = (_c = adjustedAlignments[i]) !== null && _c !== void 0 ? _c : 'left';
|
4141
4142
|
var targetWidth = columnWidths ? columnWidths[i] : cell.length;
|
4142
4143
|
var padding = hasPadding ? ' ' : '';
|
4143
4144
|
if (alignment === 'right') {
|
@@ -4156,72 +4157,70 @@ function formatMarkdownRow(columnCount, currentRow, columnAlignments, columnWidt
|
|
4156
4157
|
}
|
4157
4158
|
return markdownRow;
|
4158
4159
|
}
|
4159
|
-
|
4160
|
-
|
4161
|
-
|
4162
|
-
|
4163
|
-
|
4164
|
-
|
4165
|
-
|
4166
|
-
|
4167
|
-
|
4168
|
-
|
4169
|
-
|
4170
|
-
|
4171
|
-
|
4172
|
-
var
|
4173
|
-
var
|
4174
|
-
|
4175
|
-
|
4176
|
-
|
4177
|
-
var
|
4178
|
-
var
|
4179
|
-
|
4180
|
-
|
4181
|
-
|
4182
|
-
case 'left':
|
4183
|
-
alignIndicator = ":".concat('-'.repeat(targetWidth - 1));
|
4184
|
-
break;
|
4185
|
-
case 'center':
|
4186
|
-
alignIndicator = ":".concat('-'.repeat(targetWidth - 2), ":");
|
4187
|
-
break;
|
4188
|
-
case 'right':
|
4189
|
-
alignIndicator = "".concat('-'.repeat(targetWidth - 1), ":");
|
4190
|
-
break;
|
4191
|
-
default:
|
4192
|
-
alignIndicator = "".concat('-'.repeat(targetWidth));
|
4193
|
-
break;
|
4194
|
-
}
|
4195
|
-
alignmentRow += "".concat(useTabs ? '\t' : padding).concat(alignIndicator).concat(useTabs ? '\t' : padding, "|");
|
4196
|
-
}
|
4197
|
-
return alignmentRow;
|
4160
|
+
function getAlignmentIndicator(_a) {
|
4161
|
+
var _b;
|
4162
|
+
var alignment = _a.alignment, targetWidth = _a.targetWidth;
|
4163
|
+
var indicators = {
|
4164
|
+
left: ":".concat('-'.repeat(targetWidth - 1)),
|
4165
|
+
center: ":".concat('-'.repeat(targetWidth - 2), ":"),
|
4166
|
+
right: "".concat('-'.repeat(targetWidth - 1), ":"),
|
4167
|
+
none: "".concat('-'.repeat(targetWidth)),
|
4168
|
+
};
|
4169
|
+
return (_b = indicators[alignment]) !== null && _b !== void 0 ? _b : indicators.none;
|
4170
|
+
}
|
4171
|
+
function formatAlignmentRow(_a) {
|
4172
|
+
var columnCount = _a.columnCount, columnAlignments = _a.columnAlignments, columnWidths = _a.columnWidths, _b = _a.useTabs, useTabs = _b === void 0 ? false : _b, _c = _a.hasPadding, hasPadding = _c === void 0 ? true : _c;
|
4173
|
+
var adjustedAlignments = getAdjustedAlignments(columnAlignments, columnCount);
|
4174
|
+
var padding = hasPadding ? ' ' : '';
|
4175
|
+
var alignmentCells = Array.from({ length: columnCount }, function (_, i) {
|
4176
|
+
var _a, _b;
|
4177
|
+
var alignment = (_a = adjustedAlignments[i]) !== null && _a !== void 0 ? _a : 'left';
|
4178
|
+
var targetWidth = (_b = columnWidths === null || columnWidths === void 0 ? void 0 : columnWidths[i]) !== null && _b !== void 0 ? _b : 3;
|
4179
|
+
var alignIndicator = getAlignmentIndicator({ alignment: alignment, targetWidth: targetWidth });
|
4180
|
+
return "".concat(useTabs ? '\t' : padding).concat(alignIndicator).concat(useTabs ? '\t' : padding);
|
4181
|
+
});
|
4182
|
+
return "|".concat(alignmentCells.join('|'), "|");
|
4198
4183
|
}
|
4199
4184
|
/**
|
4200
4185
|
* Generates a complete Markdown table string from the provided data.
|
4201
|
-
* @param
|
4202
|
-
* @param columnAlignments - Alignment settings for each column.
|
4203
|
-
* @param canAdjustColumnWidths - Flag to adjust column widths based on content.
|
4204
|
-
* @param useTabs - Flag to use tabs between columns.
|
4205
|
-
* @param replaceNewlines - Flag to replace newlines with <br> tags.
|
4206
|
-
* @param hasPadding - Flag to add padding spaces around cell content.
|
4186
|
+
* @param params - Object containing table data and formatting options.
|
4207
4187
|
* @returns The complete Markdown table string.
|
4208
4188
|
*/
|
4209
|
-
function generateMarkdownTableString(
|
4210
|
-
|
4211
|
-
if (useTabs === void 0) { useTabs = false; }
|
4212
|
-
if (replaceNewlines === void 0) { replaceNewlines = false; }
|
4213
|
-
if (hasPadding === void 0) { hasPadding = true; }
|
4189
|
+
function generateMarkdownTableString(_a) {
|
4190
|
+
var inputData = _a.inputData, columnAlignments = _a.columnAlignments, _b = _a.canAdjustColumnWidths, canAdjustColumnWidths = _b === void 0 ? true : _b, _c = _a.useTabs, useTabs = _c === void 0 ? false : _c, _d = _a.replaceNewlines, replaceNewlines = _d === void 0 ? false : _d, _e = _a.hasPadding, hasPadding = _e === void 0 ? true : _e;
|
4214
4191
|
var headerColumnCount = inputData.inputDataHeader.length;
|
4215
4192
|
var bodyColumnCounts = inputData.inputDataBody.map(function (currentRow) { return currentRow.length; });
|
4216
4193
|
var maxColumnCount = Math.max.apply(Math, __spreadArray([headerColumnCount], bodyColumnCounts, false));
|
4217
4194
|
var columnWidths = canAdjustColumnWidths
|
4218
4195
|
? calculateColumnWidths(__spreadArray([inputData.inputDataHeader], inputData.inputDataBody, true), maxColumnCount)
|
4219
4196
|
: undefined;
|
4220
|
-
var markdownHeaderRow = formatMarkdownRow(
|
4221
|
-
|
4197
|
+
var markdownHeaderRow = formatMarkdownRow({
|
4198
|
+
columnCount: maxColumnCount,
|
4199
|
+
currentRow: inputData.inputDataHeader,
|
4200
|
+
columnAlignments: columnAlignments,
|
4201
|
+
columnWidths: columnWidths,
|
4202
|
+
useTabs: useTabs,
|
4203
|
+
replaceNewlines: replaceNewlines,
|
4204
|
+
hasPadding: hasPadding,
|
4205
|
+
});
|
4206
|
+
var markdownAlignmentRow = formatAlignmentRow({
|
4207
|
+
columnCount: maxColumnCount,
|
4208
|
+
columnAlignments: columnAlignments,
|
4209
|
+
columnWidths: columnWidths,
|
4210
|
+
useTabs: useTabs,
|
4211
|
+
hasPadding: hasPadding,
|
4212
|
+
});
|
4222
4213
|
var markdownBodyRows = inputData.inputDataBody
|
4223
4214
|
.map(function (currentRow) {
|
4224
|
-
return formatMarkdownRow(
|
4215
|
+
return formatMarkdownRow({
|
4216
|
+
columnCount: maxColumnCount,
|
4217
|
+
currentRow: currentRow,
|
4218
|
+
columnAlignments: columnAlignments,
|
4219
|
+
columnWidths: columnWidths,
|
4220
|
+
useTabs: useTabs,
|
4221
|
+
replaceNewlines: replaceNewlines,
|
4222
|
+
hasPadding: hasPadding,
|
4223
|
+
});
|
4225
4224
|
})
|
4226
4225
|
.join('\n');
|
4227
4226
|
return "".concat(markdownHeaderRow, "\n").concat(markdownAlignmentRow, "\n").concat(markdownBodyRows).trimEnd();
|
@@ -18567,59 +18566,40 @@ var LIGHT_THEME_CSS = "\ncode[class*=language-],pre[class*=language-]{color:#000
|
|
18567
18566
|
var DARK_THEME_CSS = "\ncode[class*=language-],pre[class*=language-]{color:#f8f8f2;background:0 0;text-shadow:0 1px rgba(0,0,0,.3);font-family:Consolas,Monaco,'Andale Mono','Ubuntu Mono',monospace;font-size:1em;text-align:left;white-space:pre;word-spacing:normal;word-break:normal;word-wrap:normal;line-height:1.5;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-hyphens:none;-moz-hyphens:none;-ms-hyphens:none;hyphens:none}pre[class*=language-]{padding:1em;margin:.5em 0;overflow:auto;border-radius:.3em}:not(pre)>code[class*=language-],pre[class*=language-]{background:#282a36}:not(pre)>code[class*=language-]{padding:.1em;border-radius:.3em;white-space:normal}pre[class*=language-].line-numbers{position:relative;padding-left:2.4em;counter-reset:linenumber}pre[class*=language-].line-numbers>code{position:relative;white-space:inherit}.line-numbers .line-numbers-rows{position:absolute;pointer-events:none;top:0;font-size:100%;left:-3.8em;width:3em;letter-spacing:-1px;border-right:1px solid #999;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.line-numbers-rows>span{display:block;counter-increment:linenumber}.line-numbers-rows>span:before{content:counter(linenumber);color:#999;display:block;padding-right:.5em;text-align:right}\n";
|
18568
18567
|
var MarkdownTable = function (_a) {
|
18569
18568
|
var _b = _a.inputData, inputData = _b === void 0 ? null : _b, _c = _a.hasHeader, hasHeader = _c === void 0 ? true : _c, _d = _a.columnAlignments, columnAlignments = _d === void 0 ? [] : _d, _e = _a.isCompact, isCompact = _e === void 0 ? false : _e, _f = _a.hasTabs, hasTabs = _f === void 0 ? false : _f, _g = _a.hasPadding, hasPadding = _g === void 0 ? true : _g, _h = _a.canReplaceNewlines, canReplaceNewlines = _h === void 0 ? false : _h, className = _a.className, onTableCreate = _a.onTableCreate, _j = _a.theme, theme = _j === void 0 ? 'light' : _j, preStyle = _a.preStyle, _k = _a.showCopyButton, showCopyButton = _k === void 0 ? false : _k;
|
18570
|
-
var adjustColumnWidths = !isCompact;
|
18571
18569
|
var preElementRef = React.useRef(null);
|
18572
18570
|
var _l = React.useState(false), isCopied = _l[0], setIsCopied = _l[1];
|
18571
|
+
var adjustColumnWidths = !isCompact;
|
18572
|
+
var convertedInputData = React.useMemo(function () {
|
18573
|
+
if (!inputData)
|
18574
|
+
return null;
|
18575
|
+
var header = inputData[0], body = inputData.slice(1);
|
18576
|
+
return { inputDataHeader: header, inputDataBody: body };
|
18577
|
+
}, [inputData]);
|
18573
18578
|
var markdownTableSyntax = React.useMemo(function () {
|
18574
|
-
|
18575
|
-
|
18576
|
-
|
18577
|
-
|
18578
|
-
|
18579
|
-
|
18580
|
-
|
18581
|
-
|
18582
|
-
|
18583
|
-
inputDataHeader: inputData[0],
|
18584
|
-
inputDataBody: inputData.slice(1),
|
18585
|
-
}
|
18586
|
-
: {
|
18587
|
-
inputDataHeader: generateAlphabetHeaders(inputData[0].length),
|
18588
|
-
inputDataBody: inputData,
|
18589
|
-
};
|
18590
|
-
return generateMarkdownTableString(tableData, columnAlignments, adjustColumnWidths, hasTabs, canReplaceNewlines, hasPadding);
|
18591
|
-
}
|
18592
|
-
catch (error) {
|
18593
|
-
if (error instanceof MarkdownTableError) {
|
18594
|
-
return "Error: ".concat(error.message);
|
18595
|
-
}
|
18596
|
-
else {
|
18597
|
-
throw error;
|
18598
|
-
}
|
18599
|
-
}
|
18579
|
+
return generateMarkdownTableSyntax({
|
18580
|
+
inputData: convertedInputData,
|
18581
|
+
hasHeader: hasHeader,
|
18582
|
+
columnAlignments: columnAlignments,
|
18583
|
+
adjustColumnWidths: adjustColumnWidths,
|
18584
|
+
hasTabs: hasTabs,
|
18585
|
+
hasPadding: hasPadding,
|
18586
|
+
canReplaceNewlines: canReplaceNewlines,
|
18587
|
+
});
|
18600
18588
|
}, [
|
18601
|
-
|
18589
|
+
convertedInputData,
|
18602
18590
|
hasHeader,
|
18603
18591
|
columnAlignments,
|
18604
|
-
|
18592
|
+
adjustColumnWidths,
|
18605
18593
|
hasTabs,
|
18606
|
-
canReplaceNewlines,
|
18607
18594
|
hasPadding,
|
18595
|
+
canReplaceNewlines,
|
18608
18596
|
]);
|
18609
18597
|
React.useEffect(function () {
|
18610
18598
|
if (onTableCreate) {
|
18611
18599
|
onTableCreate(markdownTableSyntax);
|
18612
18600
|
}
|
18613
18601
|
}, [markdownTableSyntax, onTableCreate]);
|
18614
|
-
|
18615
|
-
var _a;
|
18616
|
-
var codeElement = (_a = preElementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('code');
|
18617
|
-
if (codeElement && markdownTableSyntax) {
|
18618
|
-
requestAnimationFrame(function () {
|
18619
|
-
Prism$1.highlightElement(codeElement);
|
18620
|
-
});
|
18621
|
-
}
|
18622
|
-
}, [markdownTableSyntax]);
|
18602
|
+
usePrismHighlight(markdownTableSyntax, preElementRef);
|
18623
18603
|
var handleCopy = function () {
|
18624
18604
|
navigator.clipboard.writeText(markdownTableSyntax);
|
18625
18605
|
setIsCopied(true);
|
@@ -18627,14 +18607,51 @@ var MarkdownTable = function (_a) {
|
|
18627
18607
|
};
|
18628
18608
|
return (jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [jsxRuntimeExports.jsx("style", { children: theme === 'light' ? LIGHT_THEME_CSS : DARK_THEME_CSS }), jsxRuntimeExports.jsxs("div", { style: {
|
18629
18609
|
position: 'relative',
|
18630
|
-
isolation: 'isolate'
|
18610
|
+
isolation: 'isolate',
|
18631
18611
|
}, children: [showCopyButton && (jsxRuntimeExports.jsx(Tooltip$1, { title: isCopied ? 'Copied!' : 'Copy markdown table syntax', placement: "left-end", arrow: true, children: jsxRuntimeExports.jsx(IconButton$1, { onClick: handleCopy, sx: {
|
18632
18612
|
position: 'absolute',
|
18633
18613
|
top: '12px',
|
18634
18614
|
right: '8px',
|
18635
|
-
zIndex: 1
|
18615
|
+
zIndex: 1,
|
18636
18616
|
}, "aria-label": "Copy to clipboard", size: "small", children: jsxRuntimeExports.jsx(ContentCopyIcon, { fontSize: "small" }) }) })), jsxRuntimeExports.jsx("pre", { ref: preElementRef, className: "".concat(className, " language-markdown line-numbers ").concat(theme === 'dark' ? 'dark-theme' : ''), style: preStyle, children: jsxRuntimeExports.jsx("code", { className: "language-markdown", role: "code", children: markdownTableSyntax }) })] })] }));
|
18637
18617
|
};
|
18618
|
+
var generateMarkdownTableSyntax = function (_a) {
|
18619
|
+
var inputData = _a.inputData, hasHeader = _a.hasHeader, columnAlignments = _a.columnAlignments, adjustColumnWidths = _a.adjustColumnWidths, hasTabs = _a.hasTabs, hasPadding = _a.hasPadding, canReplaceNewlines = _a.canReplaceNewlines;
|
18620
|
+
if (inputData === null) {
|
18621
|
+
return 'Error: No data provided for the table.';
|
18622
|
+
}
|
18623
|
+
if (!Array.isArray(inputData) || inputData.length === 0) {
|
18624
|
+
throw new MarkdownTableError("The 'inputData' prop must be a non-empty two-dimensional array.");
|
18625
|
+
}
|
18626
|
+
var _b = hasHeader
|
18627
|
+
? {
|
18628
|
+
inputDataHeader: inputData[0],
|
18629
|
+
inputDataBody: inputData.slice(1),
|
18630
|
+
}
|
18631
|
+
: {
|
18632
|
+
inputDataHeader: generateAlphabetHeaders(inputData[0].length),
|
18633
|
+
inputDataBody: inputData,
|
18634
|
+
}, inputDataHeader = _b.inputDataHeader, inputDataBody = _b.inputDataBody;
|
18635
|
+
return generateMarkdownTableString({
|
18636
|
+
inputData: { inputDataHeader: inputDataHeader, inputDataBody: inputDataBody },
|
18637
|
+
columnAlignments: columnAlignments,
|
18638
|
+
canAdjustColumnWidths: adjustColumnWidths,
|
18639
|
+
useTabs: hasTabs,
|
18640
|
+
replaceNewlines: canReplaceNewlines,
|
18641
|
+
hasPadding: hasPadding,
|
18642
|
+
});
|
18643
|
+
};
|
18644
|
+
var usePrismHighlight = function (markdownTableSyntax, preElementRef) {
|
18645
|
+
React.useEffect(function () {
|
18646
|
+
var _a;
|
18647
|
+
var codeElement = (_a = preElementRef.current) === null || _a === void 0 ? void 0 : _a.querySelector('code');
|
18648
|
+
if (codeElement) {
|
18649
|
+
requestAnimationFrame(function () {
|
18650
|
+
Prism$1.highlightElement(codeElement);
|
18651
|
+
});
|
18652
|
+
}
|
18653
|
+
}, [markdownTableSyntax]);
|
18654
|
+
};
|
18638
18655
|
|
18639
18656
|
exports.MarkdownTable = MarkdownTable;
|
18640
18657
|
//# sourceMappingURL=index.cjs.js.map
|