diff --git a/CHANGELOG.md b/CHANGELOG.md index d228adf..fad05b3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ # ChangeLog - PHP TableOfContents (TOC) All notable changes to this project are documented in this file. +## [2.0.1] - 2019-06-26 +### Fixed +- Duplicate headings are identified correctly ([#7](https://github.com/caseyamcl/toc/issues/7)) +- `composer:check-style` and `composer:fix-style` commands now work (fixed missing codesniffer library) + ## [2.0] - 2018-11-09 ### Changed - BREAKING: `TocGenerator::getMenu()` returns an empty menu item instead of an empty array when no diff --git a/src/TocGenerator.php b/src/TocGenerator.php index e35debf..feba514 100644 --- a/src/TocGenerator.php +++ b/src/TocGenerator.php @@ -20,6 +20,7 @@ use Knp\Menu\ItemInterface; use Knp\Menu\Matcher\Matcher; use Knp\Menu\MenuFactory; +use Knp\Menu\MenuItem; use Knp\Menu\Renderer\ListRenderer; use Knp\Menu\Renderer\RendererInterface; use Masterminds\HTML5; @@ -94,6 +95,7 @@ public function getMenu($markup, $topLevel = 1, $depth = 6) $level = array_search(strtolower($tagName), $tagsToMatch) + 1; // Determine parent item which to add child + /** @var MenuItem $parent */ if ($level == 1) { $parent = $menu; } elseif ($level == $lastElem->getLevel()) { @@ -111,8 +113,11 @@ public function getMenu($markup, $topLevel = 1, $depth = 6) } $lastElem = $parent->addChild( - $node->getAttribute('title') ?: $node->textContent, - ['uri' => '#' . $node->getAttribute('id')] + $node->getAttribute('id'), + [ + 'label' => $node->getAttribute('title') ?: $node->textContent, + 'uri' => '#' . $node->getAttribute('id') + ] ); } diff --git a/src/UniqueSluggifier.php b/src/UniqueSluggifier.php index fba70e6..cc035be 100644 --- a/src/UniqueSluggifier.php +++ b/src/UniqueSluggifier.php @@ -28,7 +28,7 @@ class UniqueSluggifier { /** - * @var \Cocur\Slugify\Slugify + * @var Slugify */ private $slugify; @@ -40,7 +40,7 @@ class UniqueSluggifier /** * Constructor * - * @param \Cocur\Slugify\Slugify $slugify + * @param Slugify $slugify */ public function __construct(Slugify $slugify = null) { diff --git a/tests/TocGeneratorTest.php b/tests/TocGeneratorTest.php index 6a0160d..d938d56 100644 --- a/tests/TocGeneratorTest.php +++ b/tests/TocGeneratorTest.php @@ -37,8 +37,8 @@ public function testDuplicateHeadingsAreEnumerated() { $obj = new TocGenerator(); - $html = "

A-Header

A-Header

"; - var_dump($obj->getHtmlMenu($html)); + $html = "

A-Header

A-Header

"; + $this->assertSame(2, count($obj->getMenu($html))); } public function testGetMenuTraversesLevelsCorrectly() @@ -62,7 +62,7 @@ public function testGetMenuTraversesLevelsCorrectly() $this->assertEquals($fixture, $actual); } - public function testGetMenuMatchesOnlyElementsWithIDs() + public function testGetMenuGeneratesIdsForElementsWithoutIDs() { $html = "

A-Header

Foobar

diff --git a/tests/TocTwigExtensionTest.php b/tests/TocTwigExtensionTest.php index 7fd36e0..0e12366 100644 --- a/tests/TocTwigExtensionTest.php +++ b/tests/TocTwigExtensionTest.php @@ -33,7 +33,6 @@ class TocTwigExtensionTest extends PHPUnit_Framework_TestCase public function testInstantiateSucceeds() { $obj = new TocTwigExtension(); - $this->assertInstanceOf('\TOC\TocTwigExtension', $obj); }