Fix the TOC for unicode characters, fixes #423
This commit is contained in:
parent
f821b71977
commit
83fde0ceaf
@ -106,7 +106,7 @@ class Processor implements DocumentProcessorInterface
|
||||
}
|
||||
}
|
||||
|
||||
$text = 'page_' . DauxHelper::slug(trim($text));
|
||||
$text = 'page_' . urlencode(trim($text));
|
||||
|
||||
// TODO :: check for uniqueness
|
||||
$node->data['attributes']['id'] = $text;
|
||||
|
49
tests/Format/HTML/TableOfContentsTest.php
Normal file
49
tests/Format/HTML/TableOfContentsTest.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php namespace Todaymade\Daux\Format\HTML;
|
||||
|
||||
use Todaymade\Daux\Config as MainConfig;
|
||||
use \Todaymade\Daux\Format\HTML\ContentTypes\Markdown\CommonMarkConverter;
|
||||
|
||||
class TableOfContentsTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
function testNoTOCByDefault() {
|
||||
$converter = new CommonMarkConverter(['daux' => new MainConfig]);
|
||||
|
||||
$this->assertEquals("<h1 id=\"page_Test\">Test</h1>\n", $converter->convertToHtml('# Test'));
|
||||
}
|
||||
|
||||
function testTOCToken() {
|
||||
$converter = new CommonMarkConverter(['daux' => new MainConfig]);
|
||||
|
||||
$source = "[TOC]\n# Title";
|
||||
$expected = <<<EXPECTED
|
||||
<ul class="TableOfContents">
|
||||
<li>
|
||||
<p><a href="#page_Title">Title</a></p>
|
||||
</li>
|
||||
</ul>
|
||||
<h1 id="page_Title">Title</h1>
|
||||
|
||||
EXPECTED;
|
||||
|
||||
$this->assertEquals($expected, $converter->convertToHtml($source));
|
||||
}
|
||||
|
||||
function testUnicodeTOC() {
|
||||
$converter = new CommonMarkConverter(['daux' => new MainConfig]);
|
||||
|
||||
$source = "[TOC]\n# 基础操作";
|
||||
$expected = <<<EXPECTED
|
||||
<ul class="TableOfContents">
|
||||
<li>
|
||||
<p><a href="#page_%E5%9F%BA%E7%A1%80%E6%93%8D%E4%BD%9C">基础操作</a></p>
|
||||
</li>
|
||||
</ul>
|
||||
<h1 id="page_%E5%9F%BA%E7%A1%80%E6%93%8D%E4%BD%9C">基础操作</h1>
|
||||
|
||||
EXPECTED;
|
||||
|
||||
$this->assertEquals($expected, $converter->convertToHtml($source));
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user