13
13
14
14
class Html
15
15
{
16
- private const COLOUR_MAP = [
16
+ protected const COLOUR_MAP = [
17
17
'aliceblue ' => 'f0f8ff ' ,
18
18
'antiquewhite ' => 'faebd7 ' ,
19
19
'antiquewhite1 ' => 'ffefdb ' ,
@@ -552,48 +552,10 @@ class Html
552
552
private bool $ strikethrough = false ;
553
553
554
554
/** @var callable[] */
555
- private array $ startTagCallbacks ;
555
+ protected array $ startTagCallbacks ;
556
556
557
557
/** @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 ;
597
559
598
560
private array $ stack = [];
599
561
@@ -603,6 +565,48 @@ public function __construct()
603
565
604
566
private bool $ preserveWhiteSpace = false ;
605
567
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
+
606
610
private function initialise (): void
607
611
{
608
612
$ this ->face = $ this ->size = $ this ->color = null ;
@@ -707,7 +711,7 @@ private function rgbToColour(string $rgbValue): string
707
711
708
712
public static function colourNameLookup (string $ colorName ): string
709
713
{
710
- return self ::COLOUR_MAP [$ colorName ] ?? '' ;
714
+ return static ::COLOUR_MAP [$ colorName ] ?? '' ;
711
715
}
712
716
713
717
protected function startFontTag (DOMElement $ tag ): void
0 commit comments