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

Improve markdown transformers #3886

Merged
merged 4 commits into from
Mar 21, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix linter errors
  • Loading branch information
Godefroy committed Feb 19, 2023
commit 5a223c375f15ea1c56eca463cb477d0eae539162
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ import {
TableNode,
TableRowNode,
} from '@lexical/table';
import {$createTextNode, $isParagraphNode, $isTextNode,LexicalNode} from 'lexical';
import {
$createTextNode,
$isParagraphNode,
$isTextNode,
LexicalNode,
} from 'lexical';

import {
$createEquationNode,
Expand Down Expand Up @@ -159,7 +164,9 @@ export const TABLE: ElementTransformer = {

for (const row of node.getChildren()) {
const rowOutput = [];
if (!$isTableRowNode(row)) continue;
if (!$isTableRowNode(row)) {
continue;
}

let isHeaderRow = false;
for (const cell of row.getChildren()) {
Expand All @@ -185,15 +192,21 @@ export const TABLE: ElementTransformer = {
// Header row
if (TABLE_ROW_DIVIDER_REG_EXP.test(match[0])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zurfyx will this be a problem for the tables works you're currently doing? I doubt it, but wanted to check.

const table = parentNode.getPreviousSibling();
if (!table || !$isTableNode(table)) return;
if (!table || !$isTableNode(table)) {
return;
}

const rows = table.getChildren();
const lastRow = rows[rows.length - 1];
if (!lastRow || !$isTableRowNode(lastRow)) return;
if (!lastRow || !$isTableRowNode(lastRow)) {
return;
}

// Add header state to row cells
lastRow.getChildren().forEach((cell) => {
if (!$isTableCellNode(cell)) return;
if (!$isTableCellNode(cell)) {
return;
}
cell.toggleHeaderStyle(TableCellHeaderStates.ROW);
});

Expand Down Expand Up @@ -281,7 +294,9 @@ const createTableCell = (textContent: string): TableCellNode => {

const mapToTableCells = (textContent: string): Array<TableCellNode> | null => {
const match = textContent.match(TABLE_ROW_REG_EXP);
if (!match || !match[1]) return null;
if (!match || !match[1]) {
return null;
}
return match[1].split('|').map((text) => createTableCell(text));
};

Expand Down