Skip to content

Commit

Permalink
va-table: Parse html to plain string before setting it to CSS content (
Browse files Browse the repository at this point in the history
…#1431)

* va-table: Parse html to plain string before setting it to css content

* fix test state
  • Loading branch information
ataker authored Dec 11, 2024
1 parent a8f21ae commit a5cc080
Showing 1 changed file with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,18 @@ export class VaTableInner {
}
}

/**
* escapes html entities and returns a string
* ex: 'Hall & Oates' returns 'Hall & Oates'
* @param innerHTML string of html
* @returns parsed string escaped of html entities
*/
parseHTMLToString (innerHTML:string) {
let parser = new DOMParser();

return parser.parseFromString(innerHTML, 'text/html').documentElement.textContent;
}

/**
* Generate the markup for a table row where row is the zero-indexed row number
*/
Expand All @@ -141,9 +153,9 @@ export class VaTableInner {
{Array.from({ length: this.cols }).map((_, i) => {
const slotName = `va-table-slot-${row * this.cols + i}`;
const slot = <slot name={slotName}></slot>;
const header = this.el.querySelector(
const header = this.parseHTMLToString(this.el.querySelector(
`[slot="va-table-slot-${i}"]`,
).innerHTML;
).innerHTML);
const dataSortActive = row > 0 && this.sortindex === i ? true : false;
return i === 0 || row === 0 ? (
<th
Expand Down

0 comments on commit a5cc080

Please sign in to comment.