mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
When truncating, consider hypens, apostrophes and HTML entities.
This commit is contained in:
parent
d30ffcf52f
commit
9d0804de7a
10 changed files with 95 additions and 24 deletions
|
|
@ -90,7 +90,7 @@
|
|||
<div class="section" id="testing-another-case">
|
||||
<h2>Testing another case</h2>
|
||||
<p>This will now have a line number in 'custom' since it's the default in
|
||||
pelican.conf, it ...</p></div>
|
||||
pelican.conf, it will ...</p></div>
|
||||
<a class="readmore" href="/unbelievable.html">read more</a>
|
||||
</div><!-- /.entry-content -->
|
||||
</article></li>
|
||||
|
|
|
|||
|
|
@ -227,7 +227,7 @@ YEAH !</p>
|
|||
<div class="section" id="testing-another-case">
|
||||
<h2>Testing another case</h2>
|
||||
<p>This will now have a line number in 'custom' since it's the default in
|
||||
pelican.conf, it ...</p></div>
|
||||
pelican.conf, it will ...</p></div>
|
||||
<a class="readmore" href="/unbelievable.html">read more</a>
|
||||
</div><!-- /.entry-content -->
|
||||
</article></li>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
<div class="section" id="testing-another-case">
|
||||
<h2>Testing another case</h2>
|
||||
<p>This will now have a line number in 'custom' since it's the default in
|
||||
pelican.conf, it ...</p></div>
|
||||
pelican.conf, it will ...</p></div>
|
||||
<a class="readmore" href="../unbelievable.html">read more</a>
|
||||
<p>There are <a href="../unbelievable.html#disqus_thread">comments</a>.</p> </div><!-- /.entry-content -->
|
||||
</article></li>
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@
|
|||
<div class="section" id="testing-another-case">
|
||||
<h2>Testing another case</h2>
|
||||
<p>This will now have a line number in 'custom' since it's the default in
|
||||
pelican.conf, it ...</p></div>
|
||||
pelican.conf, it will ...</p></div>
|
||||
<a class="readmore" href="../unbelievable.html">read more</a>
|
||||
<p>There are <a href="../unbelievable.html#disqus_thread">comments</a>.</p> </div><!-- /.entry-content -->
|
||||
</article></li>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
<div class="section" id="testing-another-case">
|
||||
<h2>Testing another case</h2>
|
||||
<p>This will now have a line number in 'custom' since it's the default in
|
||||
pelican.conf, it ...</p></div>
|
||||
pelican.conf, it will ...</p></div>
|
||||
<a class="readmore" href="./unbelievable.html">read more</a>
|
||||
<p>There are <a href="./unbelievable.html#disqus_thread">comments</a>.</p> </div><!-- /.entry-content -->
|
||||
</article></li>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
<div class="section" id="testing-another-case">
|
||||
<h2>Testing another case</h2>
|
||||
<p>This will now have a line number in 'custom' since it's the default in
|
||||
pelican.conf, it ...</p></div>
|
||||
pelican.conf, it will ...</p></div>
|
||||
<a class="readmore" href="../posts/2010/octobre/15/unbelievable/">read more</a>
|
||||
<p>There are <a href="../posts/2010/octobre/15/unbelievable/#disqus_thread">comments</a>.</p> </div><!-- /.entry-content -->
|
||||
</article></li>
|
||||
|
|
@ -135,4 +135,4 @@ pelican.conf, it ...</p></div>
|
|||
}());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -103,7 +103,7 @@
|
|||
<div class="section" id="testing-another-case">
|
||||
<h2>Testing another case</h2>
|
||||
<p>This will now have a line number in 'custom' since it's the default in
|
||||
pelican.conf, it ...</p></div>
|
||||
pelican.conf, it will ...</p></div>
|
||||
<a class="readmore" href="../posts/2010/octobre/15/unbelievable/">read more</a>
|
||||
<p>There are <a href="../posts/2010/octobre/15/unbelievable/#disqus_thread">comments</a>.</p> </div><!-- /.entry-content -->
|
||||
</article></li>
|
||||
|
|
@ -175,4 +175,4 @@ pelican.conf, it ...</p></div>
|
|||
}());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@
|
|||
<div class="section" id="testing-another-case">
|
||||
<h2>Testing another case</h2>
|
||||
<p>This will now have a line number in 'custom' since it's the default in
|
||||
pelican.conf, it ...</p></div>
|
||||
pelican.conf, it will ...</p></div>
|
||||
<a class="readmore" href="./posts/2010/octobre/15/unbelievable/">read more</a>
|
||||
<p>There are <a href="./posts/2010/octobre/15/unbelievable/#disqus_thread">comments</a>.</p> </div><!-- /.entry-content -->
|
||||
</article></li>
|
||||
|
|
@ -135,4 +135,4 @@ pelican.conf, it ...</p></div>
|
|||
}());
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -146,31 +146,51 @@ class TestUtils(LoggedTestCase):
|
|||
self.assertEqual(utils.get_relative_path(value), expected)
|
||||
|
||||
def test_truncate_html_words(self):
|
||||
# Plain text.
|
||||
self.assertEqual(
|
||||
utils.truncate_html_words('short string', 20),
|
||||
'short string')
|
||||
|
||||
self.assertEqual(
|
||||
utils.truncate_html_words('word ' * 100, 20),
|
||||
'word ' * 20 + '...')
|
||||
|
||||
# Words enclosed or intervaled by HTML tags.
|
||||
self.assertEqual(
|
||||
utils.truncate_html_words('<p>' + 'word ' * 100 + '</p>', 20),
|
||||
'<p>' + 'word ' * 20 + '...</p>')
|
||||
|
||||
self.assertEqual(
|
||||
utils.truncate_html_words(
|
||||
'<span\nstyle="\n...\n">' + 'word ' * 100 + '</span>', 20),
|
||||
'<span\nstyle="\n...\n">' + 'word ' * 20 + '...</span>')
|
||||
|
||||
self.assertEqual(
|
||||
utils.truncate_html_words('<br>' + 'word ' * 100, 20),
|
||||
'<br>' + 'word ' * 20 + '...')
|
||||
|
||||
self.assertEqual(
|
||||
utils.truncate_html_words('<!-- comment -->' + 'word ' * 100, 20),
|
||||
'<!-- comment -->' + 'word ' * 20 + '...')
|
||||
|
||||
# Words with hypens and apostrophes.
|
||||
self.assertEqual(
|
||||
utils.truncate_html_words("a-b " * 100, 20),
|
||||
"a-b " * 20 + '...')
|
||||
self.assertEqual(
|
||||
utils.truncate_html_words("it's " * 100, 20),
|
||||
"it's " * 20 + '...')
|
||||
|
||||
# Words with HTML entity references.
|
||||
self.assertEqual(
|
||||
utils.truncate_html_words("é " * 100, 20),
|
||||
"é " * 20 + '...')
|
||||
self.assertEqual(
|
||||
utils.truncate_html_words("café " * 100, 20),
|
||||
"café " * 20 + '...')
|
||||
self.assertEqual(
|
||||
utils.truncate_html_words("èlite " * 100, 20),
|
||||
"èlite " * 20 + '...')
|
||||
self.assertEqual(
|
||||
utils.truncate_html_words("cafetiére " * 100, 20),
|
||||
"cafetiére " * 20 + '...')
|
||||
|
||||
def test_process_translations(self):
|
||||
# create a bunch of articles
|
||||
# 1: no translation metadata
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue