Skip to content

Commit

Permalink
Make permalinks more like GitHub's #288
Browse files Browse the repository at this point in the history
  • Loading branch information
onigoetz committed Jan 28, 2022
1 parent c3863e1 commit 306e06f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion libs/ContentTypes/Markdown/TextNormalization.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function setConfiguration(ConfigurationInterface $configuration): void
public function normalize(string $text, $context = null): string
{
// Add any requested prefix
$slug = 'page_' . ($context['prefix'] ?? '') . $text;
$slug = ($context['prefix'] ?? '') . $text;

// Normalize
$slug = DauxHelper::linkSlug($slug);
Expand Down
2 changes: 1 addition & 1 deletion libs/DauxHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public static function linkSlug($slug)
{
$slug = static::slugBase($slug);

$separator = '_';
$separator = '-';

// Replace characters other than letters, numbers, and marks with a separator.
$slug = \preg_replace('/[^\p{L}\p{Nd}\p{Nl}\p{M}\s_-]+/u', $separator, $slug) ?? $slug;
Expand Down
42 changes: 21 additions & 21 deletions tests/Format/HTML/TableOfContentsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function testNoTOCByDefault()
{
$converter = new CommonMarkConverter($this->getConfig());

$this->assertEquals("<h1><a id=\"page_test\" href=\"#page_test\" class=\"Permalink\" aria-hidden=\"true\" title=\"Permalink\">#</a>Test</h1>\n", $converter->convertToHtml('# Test')->getContent());
$this->assertEquals("<h1><a id=\"test\" href=\"#test\" class=\"Permalink\" aria-hidden=\"true\" title=\"Permalink\">#</a>Test</h1>\n", $converter->convertToHtml('# Test')->getContent());
}

public function testShouldAddTOCWhenAutoTOCisOn()
Expand All @@ -47,10 +47,10 @@ public function testShouldAddTOCWhenAutoTOCisOn()
$expected = <<<'EXPECTED'
<ul class="TableOfContents">
<li>
<a href="#page_title">Title</a>
<a href="#title">Title</a>
</li>
</ul>
<h1><a id="page_title" href="#page_title" class="Permalink" aria-hidden="true" title="Permalink">#</a>Title</h1>
<h1><a id="title" href="#title" class="Permalink" aria-hidden="true" title="Permalink">#</a>Title</h1>

EXPECTED;

Expand All @@ -68,10 +68,10 @@ public function testShouldNotAddTOCWhenAutoTOCisOnAndTOCisPresent()
<p>Some Content</p>
<ul class="TableOfContents">
<li>
<a href="#page_title">Title</a>
<a href="#title">Title</a>
</li>
</ul>
<h1><a id="page_title" href="#page_title" class="Permalink" aria-hidden="true" title="Permalink">#</a>Title</h1>
<h1><a id="title" href="#title" class="Permalink" aria-hidden="true" title="Permalink">#</a>Title</h1>

EXPECTED;

Expand All @@ -86,10 +86,10 @@ public function testTOCToken()
$expected = <<<'EXPECTED'
<ul class="TableOfContents">
<li>
<a href="#page_title">Title</a>
<a href="#title">Title</a>
</li>
</ul>
<h1><a id="page_title" href="#page_title" class="Permalink" aria-hidden="true" title="Permalink">#</a>Title</h1>
<h1><a id="title" href="#title" class="Permalink" aria-hidden="true" title="Permalink">#</a>Title</h1>

EXPECTED;

Expand All @@ -104,14 +104,14 @@ public function testUnicodeTOC()
$expected = <<<'EXPECTED'
<ul class="TableOfContents">
<li>
<a href="#page_ji_chu_cao_zuo">基础操作</a>
<a href="#ji-chu-cao-zuo">基础操作</a>
</li>
<li>
<a href="#page_cao_zuo_ji_chu">操作基础</a>
<a href="#cao-zuo-ji-chu">操作基础</a>
</li>
</ul>
<h1><a id="page_ji_chu_cao_zuo" href="#page_ji_chu_cao_zuo" class="Permalink" aria-hidden="true" title="Permalink">#</a>基础操作</h1>
<h1><a id="page_cao_zuo_ji_chu" href="#page_cao_zuo_ji_chu" class="Permalink" aria-hidden="true" title="Permalink">#</a>操作基础</h1>
<h1><a id="ji-chu-cao-zuo" href="#ji-chu-cao-zuo" class="Permalink" aria-hidden="true" title="Permalink">#</a>基础操作</h1>
<h1><a id="cao-zuo-ji-chu" href="#cao-zuo-ji-chu" class="Permalink" aria-hidden="true" title="Permalink">#</a>操作基础</h1>

EXPECTED;

Expand All @@ -126,18 +126,18 @@ public function testDuplicatedTOC()
$expected = <<<'EXPECTED'
<ul class="TableOfContents">
<li>
<a href="#page_test">Test</a>
<a href="#test">Test</a>
</li>
<li>
<a href="#page_test-1">Test</a>
<a href="#test-1">Test</a>
</li>
<li>
<a href="#page_test-2">Test</a>
<a href="#test-2">Test</a>
</li>
</ul>
<h1><a id="page_test" href="#page_test" class="Permalink" aria-hidden="true" title="Permalink">#</a>Test</h1>
<h1><a id="page_test-1" href="#page_test-1" class="Permalink" aria-hidden="true" title="Permalink">#</a>Test</h1>
<h1><a id="page_test-2" href="#page_test-2" class="Permalink" aria-hidden="true" title="Permalink">#</a>Test</h1>
<h1><a id="test" href="#test" class="Permalink" aria-hidden="true" title="Permalink">#</a>Test</h1>
<h1><a id="test-1" href="#test-1" class="Permalink" aria-hidden="true" title="Permalink">#</a>Test</h1>
<h1><a id="test-2" href="#test-2" class="Permalink" aria-hidden="true" title="Permalink">#</a>Test</h1>

EXPECTED;

Expand All @@ -152,10 +152,10 @@ public function testEscapedTOC()
$expected = <<<'EXPECTED'
<ul class="TableOfContents">
<li>
<a href="#page_test_test">TEST : Test</a>
<a href="#test-test">TEST : Test</a>
</li>
</ul>
<h1><a id="page_test_test" href="#page_test_test" class="Permalink" aria-hidden="true" title="Permalink">#</a>TEST : Test</h1>
<h1><a id="test-test" href="#test-test" class="Permalink" aria-hidden="true" title="Permalink">#</a>TEST : Test</h1>

EXPECTED;

Expand All @@ -170,10 +170,10 @@ public function testQuotesWorkCorrectly()
$expected = <<<'EXPECTED'
<ul class="TableOfContents">
<li>
<a href="#page_daux_s_bug">Daux’s bug</a>
<a href="#daux-s-bug">Daux’s bug</a>
</li>
</ul>
<h1><a id="page_daux_s_bug" href="#page_daux_s_bug" class="Permalink" aria-hidden="true" title="Permalink">#</a>Daux’s bug</h1>
<h1><a id="daux-s-bug" href="#daux-s-bug" class="Permalink" aria-hidden="true" title="Permalink">#</a>Daux’s bug</h1>

EXPECTED;

Expand Down

0 comments on commit 306e06f

Please sign in to comment.