Skip to content

Commit

Permalink
Merge pull request #376 from titoBouzout/immatable
Browse files Browse the repository at this point in the history
add `caption` to table HTML validation
  • Loading branch information
ryansolid authored Oct 28, 2024
2 parents 4b11871 + 163d5fb commit a1d24a1
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions packages/babel-plugin-jsx-dom-expressions/src/shared/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,29 @@ export function isInvalidMarkup(html) {

// fix escaping, so doesnt mess up the validation
// `<script>a();</script>` -> `<script>a();</script>`
.replace(/<([^>]+)>/gi, "<$1>")

// edge cases (safe to assume they will use the partial in the right place)
// fix tables rows
.replace(/^<tr>/i, "<table><tbody><tr>")
.replace(/<\/tr>$/i, "</tr></tbody></table>")
// fix tables cells
.replace(/^<td>/i, "<table><tbody><tr><td>")
.replace(/<\/td>$/i, "</td></tr></tbody></table>")
.replace(/^<th>/i, "<table><thead><tr><th>")
.replace(/<\/th>$/i, "</th></tr></thead></table>")
// col/colgroup
.replace(/^<col>/i, "<table><colgroup><col>")
.replace(/<\/col>$/i, "</col></colgroup></table>")
.replace(/^<colgroup>/i, "<table><colgroup>")
.replace(/<\/colgroup>$/i, "</colgroup></table>")

// fix table components
.replace(/^<thead>/i, "<table><thead>")
.replace(/<\/thead>$/i, "</thead></table>")
.replace(/^<tbody>/i, "<table><tbody>")
.replace(/<\/tbody>$/i, "</tbody></table>")
.replace(/^<tfoot>/i, "<table><tfoot>")
.replace(/<\/tfoot>$/i, "</tfoot></table>");
.replace(/&lt;([^>]+)>/gi, "&lt;$1&gt;");

// edge cases (safe to assume they will use the partial in the right place)

// table cells
if (/^<(td|th)>/.test(html)) {
html = `<table><tbody><tr>${html}</tr></tbody></table>`;
}

// table rows
if (/^<tr>/.test(html)) {
html = `<table><tbody>${html}</tbody></table>`;
}

// table misc
if (/^<col>/.test(html)) {
html = `<table><colgroup>${html}</colgroup></table>`;
}

// table components
if (/^<(thead|tbody|tfoot|colgroup|caption)>/.test(html)) {
html = `<table>${html}</table>`;
}

// skip when equal to:
switch (html) {
Expand Down

0 comments on commit a1d24a1

Please sign in to comment.