Support inline SVGs (don't break on title in inline SVG).

This commit is contained in:
Stuart Axon 2019-10-11 00:29:00 +01:00
commit eaccca52dd
5 changed files with 30 additions and 1 deletions

3
RELEASE.md Normal file
View file

@ -0,0 +1,3 @@
Release type: patch
Support inline SVGs, don't treat titles in SVGs as HTML titles. Fixes #2561.

View file

@ -407,7 +407,7 @@ class HTMLReader(BaseReader):
if self._in_head:
self._in_head = False
self._in_top_level = True
elif tag == 'title':
elif self._in_head and tag == 'title':
self._in_title = False
self.metadata['title'] = self._data_buffer
elif tag == 'body':

View file

@ -0,0 +1,17 @@
<html>
<head>
<title>Article with an inline SVG</title>
</head>
<body>
Ensure that the title attribute in an inline svg is not handled as an HTML title.
<svg xmlns="http://www.w3.org/2000/svg" width="210mm" height="297mm" viewBox="0 0 210 297">
<path fill="#b2b2ff" stroke="#000" stroke-width="2.646" d="M88.698 89.869l-8.899 15.63a38.894 38.894 0 00-16.474 31.722 38.894 38.894 0 0038.894 38.894 38.894 38.894 0 0038.894-38.894 38.894 38.894 0 00-9-24.83l-2.38-16.886-14.828 4.994a38.894 38.894 0 00-12.13-2.144z">
<title>A different title inside the inline SVG</title>
</path>
<ellipse cx="100.806" cy="125.285" rx="3.704" ry="10.583"/>
<ellipse cx="82.021" cy="125.285" rx="3.704" ry="10.583"/>
<ellipse cx="-111.432" cy="146.563" rx="3.704" ry="10.583" transform="rotate(-64.822)"/>
<ellipse cx="-118.245" cy="91.308" rx="6.18" ry="8.62" transform="matrix(.063 -.99801 .96163 .27436 0 0)"/>
</svg>
</body>
</html>

View file

@ -262,6 +262,7 @@ class TestArticlesGenerator(unittest.TestCase):
['This is a super article !', 'published', 'yeah', 'article'],
['This is a super article !', 'published', 'yeah', 'article'],
['This is a super article !', 'published', 'Default', 'article'],
['Article with an inline SVG', 'published', 'Default', 'article'],
['This is an article with category !', 'published', 'yeah',
'article'],
['This is an article with multiple authors!', 'published',
@ -554,6 +555,7 @@ class TestArticlesGenerator(unittest.TestCase):
'An Article With Code Block To Test Typogrify Ignore',
'Article title',
'Article with Nonconformant HTML meta tags',
'Article with an inline SVG',
'Article with markdown and summary metadata multi',
'Article with markdown and summary metadata single',
'Article with markdown containing footnotes',

View file

@ -764,3 +764,10 @@ class HTMLReaderTest(ReaderTest):
}
self.assertDictHasSubset(page.metadata, expected)
def test_article_with_inline_svg(self):
page = self.read_file(path='article_with_inline_svg.html')
expected = {
'title': 'Article with an inline SVG',
}
self.assertDictHasSubset(page.metadata, expected)