Skip to content

Commit 467f808

Browse files
committed
Tweak Helper/Html
1 parent 898fa0b commit 467f808

File tree

1 file changed

+46
-42
lines changed

1 file changed

+46
-42
lines changed

src/PhpSpreadsheet/Helper/Html.php

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
class Html
1515
{
16-
private const COLOUR_MAP = [
16+
protected const COLOUR_MAP = [
1717
'aliceblue' => 'f0f8ff',
1818
'antiquewhite' => 'faebd7',
1919
'antiquewhite1' => 'ffefdb',
@@ -552,48 +552,10 @@ class Html
552552
private bool $strikethrough = false;
553553

554554
/** @var callable[] */
555-
private array $startTagCallbacks;
555+
protected array $startTagCallbacks;
556556

557557
/** @var callable[] */
558-
private array $endTagCallbacks;
559-
560-
public function __construct()
561-
{
562-
$this->startTagCallbacks = [
563-
'font' => $this->startFontTag(...),
564-
'b' => $this->startBoldTag(...),
565-
'strong' => $this->startBoldTag(...),
566-
'i' => $this->startItalicTag(...),
567-
'em' => $this->startItalicTag(...),
568-
'u' => $this->startUnderlineTag(...),
569-
'ins' => $this->startUnderlineTag(...),
570-
'del' => $this->startStrikethruTag(...),
571-
's' => $this->startStrikethruTag(...),
572-
'sup' => $this->startSuperscriptTag(...),
573-
'sub' => $this->startSubscriptTag(...),
574-
];
575-
$this->endTagCallbacks = [
576-
'font' => $this->endFontTag(...),
577-
'b' => $this->endBoldTag(...),
578-
'strong' => $this->endBoldTag(...),
579-
'i' => $this->endItalicTag(...),
580-
'em' => $this->endItalicTag(...),
581-
'u' => $this->endUnderlineTag(...),
582-
'ins' => $this->endUnderlineTag(...),
583-
'del' => $this->endStrikethruTag(...),
584-
's' => $this->endStrikethruTag(...),
585-
'sup' => $this->endSuperscriptTag(...),
586-
'sub' => $this->endSubscriptTag(...),
587-
'br' => $this->breakTag(...),
588-
'p' => $this->breakTag(...),
589-
'h1' => $this->breakTag(...),
590-
'h2' => $this->breakTag(...),
591-
'h3' => $this->breakTag(...),
592-
'h4' => $this->breakTag(...),
593-
'h5' => $this->breakTag(...),
594-
'h6' => $this->breakTag(...),
595-
];
596-
}
558+
protected array $endTagCallbacks;
597559

598560
private array $stack = [];
599561

@@ -603,6 +565,48 @@ public function __construct()
603565

604566
private bool $preserveWhiteSpace = false;
605567

568+
public function __construct()
569+
{
570+
if (!isset($this->startTagCallbacks)) {
571+
$this->startTagCallbacks = [
572+
'font' => $this->startFontTag(...),
573+
'b' => $this->startBoldTag(...),
574+
'strong' => $this->startBoldTag(...),
575+
'i' => $this->startItalicTag(...),
576+
'em' => $this->startItalicTag(...),
577+
'u' => $this->startUnderlineTag(...),
578+
'ins' => $this->startUnderlineTag(...),
579+
'del' => $this->startStrikethruTag(...),
580+
's' => $this->startStrikethruTag(...),
581+
'sup' => $this->startSuperscriptTag(...),
582+
'sub' => $this->startSubscriptTag(...),
583+
];
584+
}
585+
if (!isset($this->endTagCallbacks)) {
586+
$this->endTagCallbacks = [
587+
'font' => $this->endFontTag(...),
588+
'b' => $this->endBoldTag(...),
589+
'strong' => $this->endBoldTag(...),
590+
'i' => $this->endItalicTag(...),
591+
'em' => $this->endItalicTag(...),
592+
'u' => $this->endUnderlineTag(...),
593+
'ins' => $this->endUnderlineTag(...),
594+
'del' => $this->endStrikethruTag(...),
595+
's' => $this->endStrikethruTag(...),
596+
'sup' => $this->endSuperscriptTag(...),
597+
'sub' => $this->endSubscriptTag(...),
598+
'br' => $this->breakTag(...),
599+
'p' => $this->breakTag(...),
600+
'h1' => $this->breakTag(...),
601+
'h2' => $this->breakTag(...),
602+
'h3' => $this->breakTag(...),
603+
'h4' => $this->breakTag(...),
604+
'h5' => $this->breakTag(...),
605+
'h6' => $this->breakTag(...),
606+
];
607+
}
608+
}
609+
606610
private function initialise(): void
607611
{
608612
$this->face = $this->size = $this->color = null;
@@ -707,7 +711,7 @@ private function rgbToColour(string $rgbValue): string
707711

708712
public static function colourNameLookup(string $colorName): string
709713
{
710-
return self::COLOUR_MAP[$colorName] ?? '';
714+
return static::COLOUR_MAP[$colorName] ?? '';
711715
}
712716

713717
protected function startFontTag(DOMElement $tag): void

0 commit comments

Comments
 (0)