Skip to content

Commit 026d1a3

Browse files
authored
Merge pull request #63 from weaverryan/fix/duplicate-id-in-titles
Fix/duplicate id in titles
2 parents 325c7e9 + f2a263d commit 026d1a3

File tree

12 files changed

+451
-334
lines changed

12 files changed

+451
-334
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
/var/
55
/docs.phar
66
/.env
7+
/.phpunit.result.cache

src/Generator/HtmlForPdfGenerator.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,10 @@ static function ($matches) use ($uid) {
139139
);
140140
}
141141

142-
private function cleanupContent($content)
142+
private function cleanupContent(string $content): string
143143
{
144144
// remove internal anchors
145-
$content = preg_replace('#<a class="headerlink"([^>]+)></a>#', '', $content);
145+
$content = preg_replace('#<a class="headerlink"([^>]+)>(.*)</a>#', '$2', $content);
146146

147147
// convert links to footnote
148148
$content = preg_replace_callback(

src/Generator/JsonGenerator.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\DomCrawler\Crawler;
2121
use Symfony\Component\Filesystem\Filesystem;
2222
use SymfonyDocsBuilder\BuildContext;
23+
use function Symfony\Component\String\u;
2324

2425
class JsonGenerator
2526
{
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<div class="section">

tests/IntegrationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public function testIntegration(string $folder)
9595
str_replace(" \n", "\n", $indenter->indent($crawler->filter('body')->html())),
9696
str_replace(" \n", "\n", $indenter->indent($jsonData['body']))
9797
);
98-
$this->assertSame($crawler->filter('h1')->first()->text(), $jsonData['title'].'');
98+
$this->assertSame($crawler->filter('h1')->first()->text(), $jsonData['title']);
9999
}
100100
}
101101

tests/fixtures/expected/build-pdf/book.html

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,36 +3,27 @@
33
<body>
44
<div id="book-index">
55
<div class="section">
6-
<h1 id="book-index-book"><a class="headerlink" href="#book" title="Permalink to this headline">Book</a></h1>
6+
<h1 id="book-index-book">Book</h1>
77
<img src="_images/symfony-logo.png">
88
<p>Here is a link to the <a href="#index" class="reference internal">main index</a></p>
99
<div class="toctree-wrapper compound">
1010
<ul>
1111
<li><a href="https://symfony.com/doc/4.0/book/first-page.html#first-page">First page</a></li>
1212
<li><a href="https://symfony.com/doc/4.0/book/second-page.html#second-page">Second page</a></li>
13-
1413
</ul>
1514
</div>
1615
</div>
1716

1817
</div>
1918
<div id="book-first-page">
2019
<div class="section">
21-
<h1 id="book-first-page-first-page">
22-
<a class="headerlink" href="#first-page" title="Permalink to this headline">First page</a>
23-
</h1>
24-
20+
<h1 id="book-first-page-first-page">First page</h1>
2521
</div>
26-
2722
</div>
2823
<div id="book-second-page">
2924
<div class="section">
30-
<h1 id="book-second-page-second-page">
31-
<a class="headerlink" href="#second-page" title="Permalink to this headline">Second page</a>
32-
</h1>
33-
25+
<h1 id="book-second-page-second-page">Second page</h1>
3426
</div>
35-
3627
</div>
3728
</body>
38-
</html>
29+
</html>

tests/fixtures/expected/main/datetime.html

Lines changed: 420 additions & 308 deletions
Large diffs are not rendered by default.

tests/fixtures/expected/main/form/form_type.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
<meta charset="utf-8" />
55
</head>
66
<body>
7-
<div class="section" id="formtype-documentation">
8-
<h1>FormType Documentation<a class="headerlink" href="#formtype-documentation" title="Permalink to this headline"></a></h1>
7+
<div class="section">
8+
<h1 id="formtype-documentation">
9+
<a class="headerlink" href="#formtype-documentation" title="Permalink to this headline">FormType Documentation</a>
10+
</h1>
911
<span id="internal-reference"></span>
1012
<img src="../_images/symfony-logo.png" />
1113
</div>

tests/fixtures/expected/main/index.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
<meta charset="utf-8" />
55
</head>
66
<body>
7-
<div class="section" id="some-test-docs">
8-
<h1>Some Test Docs!<a class="headerlink" href="#some-test-docs" title="Permalink to this headline"></a></h1>
7+
<div class="section">
8+
<h1 id="some-test-docs">
9+
<a class="headerlink" href="#some-test-docs" title="Permalink to this headline">Some Test Docs!</a>
10+
</h1>
911
<img src="_images/symfony-logo.png" />
1012
<div class="toctree-wrapper compound">
1113
<ul>
@@ -21,10 +23,12 @@ <h1>Some Test Docs!<a class="headerlink" href="#some-test-docs" title="Permalink
2123
</ul>
2224
</div>
2325
<span id="reference-forms-type-date-format"></span>
24-
<div class="section" id="a-header">
25-
<h2>A header<a class="headerlink" href="#a-header" title="Permalink to this headline"></a></h2>
26+
<div class="section">
27+
<h2 id="a-header">
28+
<a class="headerlink" href="#a-header" title="Permalink to this headline">A header</a>
29+
</h2>
2630
<p>Some info...</p>
2731
</div>
2832
</div>
2933
</body>
30-
</html>
34+
</html>

tests/fixtures/expected/ref-reference/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<meta charset="utf-8" />
55
</head>
66
<body>
7-
<div class="section" >
7+
<div class="section">
88
<h1 id="a-test-for-reference">
99
<a class="headerlink" href="#a-test-for-reference" title="Permalink to this headline">A test for reference</a>
1010
</h1>

0 commit comments

Comments
 (0)