Skip to content

Commit 032616f

Browse files
authored
Update predbat-table-card.js
Fixes for bold prices not showing
1 parent a526be2 commit 032616f

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

predbat-table-card.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -584,19 +584,31 @@ class PredbatTableCard extends HTMLElement {
584584

585585
if(column === "pv-column" || column === "load-column" || column === 'import-column' || column === 'export-column'){
586586

587+
const hasBoldTags = /<b>.*?<\/b>/.test(theItem.value);
588+
587589
//check for HTML Debug values
588590
if(newContent.includes("(") && newContent.includes(")")){
589591
const match = theItem.value.match(/(\d+(?:\.\d+)?)\s*\((\d+(?:\.\d+)?)\)/);
590-
591-
let newVals = parseFloat(match[1]).toFixed(2) + " (" + parseFloat(match[2]).toFixed(2) + ")";
592-
newContent = newVals;
592+
if(hasBoldTags)
593+
newContent = "<b>" + parseFloat(match[1]).toFixed(2) + " (" + parseFloat(match[2]).toFixed(2) + ")</b>";
594+
else
595+
newContent = parseFloat(match[1]).toFixed(2) + " (" + parseFloat(match[2]).toFixed(2) + ")";
593596
}
594597

595598
if(this.config.debug_columns !== undefined) {// there are debug columns in the YAML
596599
if(this.config.debug_columns.indexOf(column) < 0)
597-
newContent = parseFloat(newContent).toFixed(2);
600+
if(hasBoldTags){
601+
let contentWithoutTags = theItem.value.replace(/<b>(.*?)<\/b>/g, '$1');
602+
newContent = `<b>` + parseFloat(contentWithoutTags).toFixed(2) + `</b>`;
603+
} else
604+
newContent = parseFloat(newContent).toFixed(2);
605+
598606
} else {
599-
newContent = parseFloat(newContent).toFixed(2);
607+
if(hasBoldTags){
608+
let contentWithoutTags = theItem.value.replace(/<b>(.*?)<\/b>/g, '$1');
609+
newContent = `<b>` + parseFloat(contentWithoutTags).toFixed(2) + `</b>`;
610+
} else
611+
newContent = parseFloat(newContent).toFixed(2);
600612
}
601613
}
602614

0 commit comments

Comments
 (0)