Last active
July 1, 2017 13:27
-
-
Save sakamies/ae92ebcc58aadfdf743f to your computer and use it in GitHub Desktop.
Kirbytext combined heading tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Define the tag into a variable, so we can use it in multiple tags at the bottom of this file | |
$tagName = array( | |
'attr' => array( | |
'align', | |
'link', | |
'target', | |
'class' | |
), | |
'html' => function($tag) { | |
if ($tag->attr('h1') != '') { | |
$tagName = 'h1'; | |
} else if ($tag->attr('h2') != '') { | |
$tagName = 'h2'; | |
} else if ($tag->attr('h3') != '') { | |
$tagName = 'h3'; | |
} else if ($tag->attr('h4') != '') { | |
$tagName = 'h4'; | |
} else if ($tag->attr('p') != '') { | |
$tagName = 'p'; | |
} | |
$text = widont($tag->attr($tagName)); | |
$safeText = str::slug(str::short(str::unhtml($tag->attr($tagName)), 35), '-'); | |
//Add text-left/center/right class from align attribute | |
if ($tag->attr('align')) { | |
$align = ' text-' . $tag->attr('align') . ' '; | |
} else { | |
$align = ''; | |
} | |
$tagAttrs = attr(array( | |
'id' => $safeText, | |
'class' => $align . $tag->attr('class') | |
)); | |
if ($tag->attr('link') != '') { | |
$linkAttrs = attr(array( | |
'rel' => $tag->attr('rel'), | |
'href' => $tag->attr('link'), | |
'target' => $tag->attr('target'), | |
)); | |
$a = '<a '.$linkAttrs.'>'.$text.'</a>'; | |
return '<'.$tagName.' '.$tagAttrs.'>'.$a.'</'.$tagName.'>'; | |
} else { | |
return '<'.$tagName.' '.$tagAttrs.'>'.$text.'</'.$tagName.'>'; | |
} | |
} | |
); | |
kirbytext::$tags['h1'] = $tagName; | |
kirbytext::$tags['h2'] = $tagName; | |
kirbytext::$tags['h3'] = $tagName; | |
kirbytext::$tags['h4'] = $tagName; | |
kirbytext::$tags['p'] = $tagName; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment