Skip to content

Commit

Permalink
Fixing table markdown formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewshaver committed Nov 8, 2024
1 parent fdca973 commit b387279
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
12 changes: 12 additions & 0 deletions website/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"gray-matter": "^4.0.3",
"hast-util-is-element": "^1.1.0",
"js-yaml": "^4.1.0",
"markdown-to-jsx": "^7.5.0",
"mobx": "^6.3.9",
"node-polyfill-webpack-plugin": "^1.1.4",
"papaparse": "^5.3.2",
Expand Down
4 changes: 2 additions & 2 deletions website/snippets/_enterprise-permissions-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ Account roles enable you to manage the dbt Cloud account and manage the account
{`
| Account-level permission| Account Admin | Billing admin | Manage marketplace apps | Project creator | Security admin | Viewer |
|:-----------------------:|:-------------:|:--------------:|:------------------------:|:---------------:|:--------------:|:-------:|
| Account settings | W | - | - | R | R | R |
| [Account settings](https://www.youtube.com) | **W** | - | - | _R_ | R | R |

Check warning on line 22 in website/snippets/_enterprise-permissions-table.md

View workflow job for this annotation

GitHub Actions / vale

[vale] website/snippets/_enterprise-permissions-table.md#L22

[custom.UIElements] UI elements like 'Account settings' should be bold.
Raw output
{"message": "[custom.UIElements] UI elements like 'Account settings' should be bold.", "location": {"path": "website/snippets/_enterprise-permissions-table.md", "range": {"start": {"line": 22, "column": 4}}}, "severity": "WARNING"}
| Audit logs | R | - | - | - | R | R |
| Auth provider | W | - | - | - | W | R |
| Billing | W | W | - | - | - | R |
| Connections | W | - | - | W | - | - |
| Groups | W | - | - | R | W | R |
| Invitations | W | - | - | W | W | R |
| IP restrictions | W | - | - | - | W | R |
| [IP restrictions](https://www.youtube.com) | W | - | - | - | W | R |
| Licenses | W | - | - | W | W | R |
| Marketplace app | - | - | W | - | - | - |
| Members | W | - | - | W | W | R |
Expand Down
17 changes: 13 additions & 4 deletions website/src/components/sortableTable/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import React, { useState } from 'react';
import Markdown from 'markdown-to-jsx';

const stripMarkdown = (text) => {
// Remove link syntax: [text](url) -> text
let strippedText = text.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1');
// Remove other Markdown characters like *, _, ~, ` (for bold, italics, etc.)
strippedText = strippedText.replace(/[_*`~]/g, '');
return strippedText;
};

const parseMarkdownTable = (markdown) => {
const rows = markdown.trim().split('\n');
Expand All @@ -17,7 +26,6 @@ const parseMarkdownTable = (markdown) => {
}
});

// Get the table data
const data = rows.slice(2).map(row => row.split('|').map(cell => cell.trim()).filter(Boolean));

return { headers, data, columnAlignments };
Expand All @@ -34,8 +42,9 @@ const SortableTable = ({ children }) => {
setSortConfig({ key: keyIndex, direction: newDirection });

const sortedData = [...data].sort((a, b) => {
const aVal = a[keyIndex];
const bVal = b[keyIndex];

const aVal = stripMarkdown(a[keyIndex]);
const bVal = stripMarkdown(b[keyIndex]);
if (aVal < bVal) return newDirection === 'asc' ? -1 : 1;
if (aVal > bVal) return newDirection === 'asc' ? 1 : -1;
return 0;
Expand Down Expand Up @@ -92,7 +101,7 @@ const SortableTable = ({ children }) => {
padding: '8px'
}}
>
{cell || '\u00A0'}
<Markdown>{cell || '\u00A0'}</Markdown>
</td>
))}
</tr>
Expand Down

0 comments on commit b387279

Please sign in to comment.