Skip to content

Commit

Permalink
Merge pull request #8 from storyblok/hotfix/undefined-anchor
Browse files Browse the repository at this point in the history
Fix to anchor and add improvements
  • Loading branch information
ademarCardoso authored Jul 15, 2020
2 parents adfcc21 + 6519c55 commit 5d9addd
Show file tree
Hide file tree
Showing 4 changed files with 594 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"phpunit/phpunit": "^8"
},
"scripts": {
"test": "./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/"
"test": "./vendor/bin/phpunit -d error_reporting=6143 --bootstrap vendor/autoload.php tests/"
},
"authors": [
{
Expand Down
22 changes: 14 additions & 8 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,28 @@ public function getNodes()
private function get_link($tagName)
{
return function ($node) use ($tagName) {
if (strlen($node['attrs']['anchor']) == 0 || $node['attrs']['anchor'] == null) {
unset($node['attrs']['anchor']);
}
$attrs = $node['attrs'];
$linktype = Utils::get($attrs, 'linktype', 'url');

if (array_key_exists('anchor', $attrs)) {
$anchor = $attrs['anchor'];

if (strlen($anchor) !== 0 && !is_null($anchor)) {
$attrs['href'] = $attrs['href'] . "#" . $anchor;
}

if ($node['attrs']['anchor']) {
$attrs = $node['attrs'];
$attrs['href'] = $attrs['href'] . "#" . $attrs['anchor'];
unset($attrs['anchor']);
$node['attrs'] = $attrs;
}

if ($linktype === 'email') {
$attrs['href'] = "mailto:" . $attrs['href'];
}

return [
"tag" => [
[
"tag" => $tagName,
"attrs" => $node['attrs']
"attrs" => $attrs
]
]
];
Expand Down
6 changes: 5 additions & 1 deletion src/Utils/Render.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ public static function renderTag($tags, $ending)
$attrs = $tag['attrs'];

foreach (array_keys($attrs) as $key) {
$h .= " " . $key . '="' . $attrs[$key] . '"';
$value = $attrs[$key];

if (!is_null($value)) {
$h .= " " . $key . '="' . $value . '"';
}
}
}

Expand Down
Loading

0 comments on commit 5d9addd

Please sign in to comment.