Výchozí nastavení nadpisů v Texy je následující
<?php
declare(strict_types=1);
namespace App\Presenters;
use Nette;
final class HomepagePresenter extends Nette\Application\UI\Presenter
{
public function renderDefault(){
$texy = new \Texy;
$text = "
#######Vygeneruje nadpis H1 (všimněte si, že # je zde 7)
######Vygeneruje nadpis H2
#####Vygeneruje nadpis H3
####Vygeneruje nadpis H4
###Vygeneruje nadpis H5
##Vygeneruje nadpis H6
";
$this->template->html = $texy->process($text);
}
}
V texy je ale chyták! Pokud použijete pouze jeden nadpis – například
##### – nedočkáte se nadpisu H3. Texy ho ve výchozím nastavení převede
na H1.
To může být na obtíž, pokud nadpis H1 vypisujete z jiné hodnoty než z textu, který formátujete přes Texy.
Řešením je změnit hodnotu property $texy->headingModule->balancing na konstantu FIXED. Ta zajistí, že ##### vygeneruje nadpis H3, i když to bude jediný nadpis v textu.
<?php
declare(strict_types=1);
namespace App\Presenters;
use Nette;
final class HomepagePresenter extends Nette\Application\UI\Presenter
{
public function renderDefault(){
$texy = new \Texy;
//zabrání přečíslování nadpisů
$texy->headingModule->balancing = $texy->headingModule::FIXED;
$text = "
#####Vygeneruje nadpis H3
";
$this->template->html = $texy->process($text);
}
}
Ve výchozím nastavení Texy také více # znamená vyšší nadpis. To jde
změnit proměnnou $texy->headingModule->moreMeansHigher
= false
<?php
declare(strict_types=1);
namespace App\Presenters;
use Nette;
final class HomepagePresenter extends Nette\Application\UI\Presenter
{
public function renderDefault(){
$texy = new \Texy;
//méně # znamená vyšší nadpis
$texy->headingModule->moreMeansHigher = false;
//zabrání přečíslování nadpisů
$texy->headingModule->balancing = $texy->headingModule::FIXED;
$text = "
##Vygeneruje nadpis H1
###Vygeneruje nadpis H2
####Vygeneruje nadpis H3
#####Vygeneruje nadpis H4
######Vygeneruje nadpis H5
#######Vygeneruje nadpis H6
";
$this->template->html = $texy->process($text);
}
}