Skip to content

Commit

Permalink
Merge pull request #345 from helsingborg-stad/fix/typography-headings
Browse files Browse the repository at this point in the history
fix: Typography settings
  • Loading branch information
NiclasNorin authored Oct 24, 2023
2 parents 9c27000 + fe1be55 commit 476de38
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions source/php/Component/Typography/Typography.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ public function init() {

//Set default
$this->data['isPromotedHeading'] = false;

if (substr($element, 0, 1) == 'h') {
$this->data['element'] = $this->setMaxHeading($element);
}

//If this is the first heading of the page, promote it to h1
if (substr($element, 0, 2) == 'h1') {
if (!self::$hasSeenH1 && substr($this->data['element'], 0, 2) == 'h1') {
self::$hasSeenH1 = true;
}

if (substr($element, 0, 1) == 'h') {
$this->data['element'] = $this->setMaxHeading($element);
}

if ($autopromote === true && !self::$hasSeenH1) {
if (in_array($element, ['h1', 'h2', 'h3'])) {
$this->data['isPromotedHeading'] = true;
$this->data['element'] = 'h1';
self::$hasSeenH1 = true;
self::$headingsContext = 1;
}
}

Expand All @@ -38,11 +39,14 @@ public function init() {
private function setMaxHeading($element) {
$headingsLevel = intval(substr($element, 1, 2));
if (self::$headingsContext === null) {
if ($element !== 'h2' && $element !== 'h1') {
if ($element !== 'h1') {
$headingsLevel = 2;
self::$headingsContext = 2;
return 'h2';
}
} else {
self::$headingsContext = 1;
self::$hasSeenH1 = true;
}
} else {
if (self::$headingsContext == $headingsLevel && $headingsLevel != 1) {
self::$headingsContext = $headingsLevel;
Expand Down

0 comments on commit 476de38

Please sign in to comment.