Skip to content

Commit

Permalink
Merge pull request #6 from Becklyn/headline-classes
Browse files Browse the repository at this point in the history
Add headline classes
  • Loading branch information
Jannik Zschiesche committed Feb 7, 2019
2 parents b38957c + 85ad311 commit 815b777
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Renderer/RenderProcess.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,11 @@ private function render ()
*/
private function renderTextSection (string $tagName, array $markers) : string
{
return "<{$tagName}>" . $this->renderMarkers($markers) . "</{$tagName}>";
$tagAttributes = 0 !== \preg_match("#^h[1-6]$#", $tagName)
? " class=\"{$tagName}\""
: "";

return "<{$tagName}{$tagAttributes}>{$this->renderMarkers($markers)}</{$tagName}>";
}


Expand Down Expand Up @@ -137,7 +141,8 @@ private function renderListSection (string $tagName, array $listElements) : stri
/**
* Renders a card
*
* @param array $cardConfig
* @param int $cardIndex
*
* @return string
*/
private function renderCardSection (int $cardIndex) : string
Expand Down Expand Up @@ -263,6 +268,7 @@ private function renderOpeningMarkup (array $markup) : string

// parse attribute list to a structured array
$attributes = $this->parseFlatAttributes($flatAttributes);
$renderedAttributes = [];

foreach ($this->markupAttributesVisitors as $visitor)
{
Expand Down
25 changes: 25 additions & 0 deletions tests/Renderer/RichTextRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@ public function provideSimpleRendering () : array
],
"<p>oh hai</p>",
],
"headings should receive h*-class" => [
[
"sections" => [
[1, "h1", [
[0, [], 0, "oh hai"],
]],
[1, "h2", [
[0, [], 0, "oh hai"],
]],
[1, "h3", [
[0, [], 0, "oh hai"],
]],
[1, "h4", [
[0, [], 0, "oh hai"],
]],
[1, "h5", [
[0, [], 0, "oh hai"],
]],
[1, "h6", [
[0, [], 0, "oh hai"],
]],
],
],
'<h1 class="h1">oh hai</h1><h2 class="h2">oh hai</h2><h3 class="h3">oh hai</h3><h4 class="h4">oh hai</h4><h5 class="h5">oh hai</h5><h6 class="h6">oh hai</h6>',
],
"single markup" => [
[
"markups" => [
Expand Down

0 comments on commit 815b777

Please sign in to comment.