mirror of
https://github.com/erusev/parsedown.git
synced 2023-08-10 21:13:06 +03:00
Add SlugRegister so IDs are not duplicated
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
<h1 id="foo">foo</h1>
|
||||
<h1 id="foo-bar">foo bar</h1>
|
||||
<h1 id="foobar">foo_bar</h1>
|
||||
<h1 id="foobar">foo+bar</h1>
|
||||
<h1 id="foobar-1">foo+bar-1</h1>
|
||||
<h1 id="foobar-2">foo+bar</h1>
|
||||
<h1 id="2rer0ගම්මැද්ද-v-force-ඉනොවේශන්-නේෂන්-සඳහා-එවූ-නි">2rer*(0👍ගම්මැද්ද V FORCE ඉනොවේශන් නේෂන් සඳහා එවූ නි</h1>
|
||||
<h2 id="foo">foo</h2>
|
||||
<h2 id="foo-bar">foo bar</h2>
|
||||
<h2 id="foobar">foo_bar</h2>
|
||||
<h2 id="foobar">foo+bar</h2>
|
||||
<h2 id="2rer0ගම්මැද්ද-v-force-ඉනොවේශන්-නේෂන්-සඳහා-එවූ-නි">2rer*(0👍ගම්මැද්ද V FORCE ඉනොවේශන් නේෂන් සඳහා එවූ නි</h2>
|
||||
<h2 id="foo-1">foo</h2>
|
||||
<h2 id="foo-bar-1">foo bar</h2>
|
||||
<h2 id="foobar-3">foo_bar</h2>
|
||||
<h2 id="foobar-4">foo+bar</h2>
|
||||
<h2 id="2rer0ගම්මැද්ද-v-force-ඉනොවේශන්-නේෂන්-සඳහා-එවූ-නි-1">2rer*(0👍ගම්මැද්ද V FORCE ඉනොවේශන් නේෂන් සඳහා එවූ නි</h2>
|
||||
@@ -4,6 +4,8 @@
|
||||
|
||||
# foo_bar
|
||||
|
||||
# foo+bar-1
|
||||
|
||||
# foo+bar
|
||||
|
||||
# 2rer*(0👍ගම්මැද්ද V FORCE ඉනොවේශන් නේෂන් සඳහා එවූ නි
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace Erusev\Parsedown\Tests\Configurables;
|
||||
|
||||
use Erusev\Parsedown\Configurables\HeaderSlug;
|
||||
use Erusev\Parsedown\Configurables\SlugRegister;
|
||||
use Erusev\Parsedown\State;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -19,6 +20,7 @@ final class HeaderSlugTest extends TestCase
|
||||
|
||||
$this->assertSame(true, $State->get(HeaderSlug::class)->isEnabled());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
@@ -32,7 +34,27 @@ final class HeaderSlugTest extends TestCase
|
||||
|
||||
$this->assertSame(
|
||||
'foo_bar',
|
||||
$HeaderSlug->transform('foo bar')
|
||||
$HeaderSlug->transform(SlugRegister::initial(), 'foo bar')
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws \PHPUnit\Framework\ExpectationFailedException
|
||||
* @throws \SebastianBergmann\RecursionContext\InvalidArgumentException
|
||||
*/
|
||||
public function testCustomDuplicationCallback()
|
||||
{
|
||||
$HeaderSlug = HeaderSlug::withDuplicationCallback(function (string $t, int $n): string {
|
||||
return $t . '_' . \strval($n-1);
|
||||
});
|
||||
|
||||
$SlugRegister = new SlugRegister;
|
||||
$HeaderSlug->transform($SlugRegister, 'foo bar');
|
||||
|
||||
$this->assertSame(
|
||||
'foo-bar_1',
|
||||
$HeaderSlug->transform($SlugRegister, 'foo bar')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user