-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR allows for nested selectors. You can for example only target p-tags inside a list: ```php 'li p' => 'my-css-class', ``` This wasn't possible before.
- Loading branch information
Jonas Siewertsen
authored
Aug 19, 2021
1 parent
242481f
commit 0a1a634
Showing
5 changed files
with
219 additions
and
47 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
namespace VV\Markdown\Markdown; | ||
|
||
class Tag | ||
{ | ||
/* | ||
* Contains the parent tag, which might be the only or last tag defined in the config. | ||
* From a list like `ul li p` it would fx be `p`. | ||
*/ | ||
public string $tag; | ||
|
||
/* | ||
* If multiple tags have been defined, those are the tags before the parent tag. | ||
* From a list like `ul li p` it would fx be `ul li`. | ||
*/ | ||
public array $before; | ||
|
||
/* | ||
* Contains the class list as defined in the config. | ||
*/ | ||
public string $classes; | ||
|
||
/* | ||
* Defines the number of tags, including the parent tag. | ||
*/ | ||
public int $count; | ||
|
||
public function __construct(string $tags, string $classes) | ||
{ | ||
$tags = $this->convertTagsToArray($tags); | ||
$this->count = count($tags); | ||
$this->classes = $classes; | ||
$this->setTags($tags); | ||
} | ||
|
||
/* | ||
* It's easier to handle tags as an array, so we'll convert them. | ||
*/ | ||
private function convertTagsToArray(string $tags): array | ||
{ | ||
return explode(' ', $tags); | ||
} | ||
|
||
/* | ||
* Set the parent tag and save all other tags in the before attribute. | ||
*/ | ||
private function setTags(array $tags): void | ||
{ | ||
$this->tag = $this->setParentTagAndRemoveFromOriginalArray($tags); | ||
$this->before = $tags; | ||
} | ||
|
||
/* | ||
* Get the key from the last array and splice / remove it. | ||
*/ | ||
private function setParentTagAndRemoveFromOriginalArray(array &$tags) | ||
{ | ||
return array_splice($tags, array_key_last($tags))[0]; | ||
} | ||
} |
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