def test_escape_html_attribute_values(self): self.assert_equals( """\ <article class="h-entry"> <span class="p-uid"></span> <span class="p-author h-card"> <span class="p-name">a " b ' c</span> <img class="u-photo" src="img" alt="" /> </span> <div class="e-content p-name"> <p> <img class="thumbnail" src="img" alt="d & e" /> <span class="name">d & e</span> </p> </div> </article>""", microformats2.object_to_html({ 'author': { 'image': { 'url': 'img' }, 'displayName': 'a " b \' c' }, 'attachments': [{ 'image': { 'url': 'img' }, 'displayName': 'd & e' }], }))
def test_escape_html_attribute_values(self): obj = { 'author': { 'image': {'url': 'author-img'}, 'displayName': 'a " b \' c', }, 'attachments': [{ 'objectType': 'image', 'image': {'url': 'att-img'}, 'displayName': 'd & e'}], } # TODO: test that img alt gets displayName 'd & e' once mf2py handles that. # https://github.com/tommorris/mf2py/issues/83 self.assert_multiline_equals("""\ <article class="h-entry"> <span class="p-uid"></span> <span class="p-author h-card"> <span class="p-name">a " b ' c</span> <img class="u-photo" src="author-img" alt="" /> </span> <span class="p-name"></span> <div class=""> </div> <img class="u-photo" src="att-img" alt="" /> </article>""", microformats2.object_to_html(obj), ignore_blanks=True) content = microformats2.render_content(obj, render_attachments=True) self.assert_multiline_equals("""\ <p> <img class="u-photo" src="att-img" alt="d & e" /> <span class="name">d & e</span> </p>""", content, ignore_blanks=True)
def test_attachments_to_children(self): obj = { 'attachments': [ { 'objectType': 'note', 'url': 'http://p', 'displayName': 'p' }, { 'objectType': 'x', 'url': 'http://x' }, { 'objectType': 'article', 'url': 'http://a' }, ] } self.assert_equals([{ 'type': ['u-quotation-of', 'h-cite'], 'properties': { 'url': ['http://p'], 'name': ['p'] }, }, { 'type': ['u-quotation-of', 'h-cite'], 'properties': { 'url': ['http://a'] }, }], microformats2.object_to_json(obj)['children']) html = microformats2.object_to_html(obj) self.assert_multiline_in( """\ <article class="u-quotation-of h-cite"> <span class="p-uid"></span> <a class="p-name u-url" href="http://p">p</a> <div class=""> </div> </article> <article class="u-quotation-of h-cite"> <span class="p-uid"></span> <a class="p-name u-url" href="http://a"></a> <div class=""> </div> </article> """, html)
def test_object_to_html_note_with_in_reply_to(self): expected = """\ <article class="h-entry"> <span class="u-uid"></span> <div class="e-content p-name"> @hey great post </div> <a class="u-in-reply-to" href="http://reply/target"></a> </article> """ result = microformats2.object_to_html({ 'content': '@hey great post', }, ctx={ 'inReplyTo': [{ 'url': 'http://reply/target', }] }) self.assertEquals(re.sub('\n\s*', '\n', expected), re.sub('\n\s*', '\n', result))
def test_object_to_html_note_with_in_reply_to(self): expected = """\ <article class="h-entry"> <span class="u-uid"></span> <div class="e-content p-name"> @hey great post </div> <a class="u-in-reply-to" href="http://reply/target"></a> </article> """ result = microformats2.object_to_html( { 'content': '@hey great post', }, ctx={'inReplyTo': [{ 'url': 'http://reply/target', }]}) self.assertEquals(re.sub('\n\s*', '\n', expected), re.sub('\n\s*', '\n', result))
def test_escape_html_attribute_values(self): obj = { 'author': { 'image': { 'url': 'author-img' }, 'displayName': 'a " b \' c', }, 'attachments': [{ 'objectType': 'image', 'image': { 'url': 'att-img' }, 'displayName': 'd & e' }], } # TODO: test that img alt gets displayName 'd & e' once mf2py handles that. # https://github.com/tommorris/mf2py/issues/83 self.assert_multiline_equals("""\ <article class="h-entry"> <span class="p-uid"></span> <span class="p-author h-card"> <span class="p-name">a " b ' c</span> <img class="u-photo" src="author-img" alt="" /> </span> <span class="p-name"></span> <div class=""> </div> <img class="u-photo" src="att-img" alt="" /> </article>""", microformats2.object_to_html(obj), ignore_blanks=True) content = microformats2.render_content(obj, render_attachments=True) self.assert_multiline_equals("""\ <p> <img class="u-photo" src="att-img" alt="d & e" /> <span class="name">d & e</span> </p>""", content, ignore_blanks=True)
def test_escape_html_attribute_values(self): self.assert_equals("""\ <article class="h-entry"> <span class="p-uid"></span> <span class="p-author h-card"> <span class="p-name">a " b ' c</span> <img class="u-photo" src="img" alt="" /> </span> <div class="e-content p-name"> <p> <img class="thumbnail" src="img" alt="d & e" /> <span class="name">d & e</span> </p> </div> </article>""", microformats2.object_to_html({ 'author': {'image': {'url': 'img'}, 'displayName': 'a " b \' c'}, 'attachments': [{'image': {'url': 'img'}, 'displayName': 'd & e'}], }))
def test_attachments_to_children(self): obj = {'attachments': [ {'objectType': 'note', 'url': 'http://p', 'displayName': 'p'}, {'objectType': 'x', 'url': 'http://x'}, {'objectType': 'article', 'url': 'http://a'}, ]} self.assert_equals([{ 'type': ['h-cite'], 'properties': {'url': ['http://p'], 'name': ['p']}, }, { 'type': ['h-cite'], 'properties': {'url': ['http://a']}, }], microformats2.object_to_json(obj)['children']) html = microformats2.object_to_html(obj) self.assert_multiline_in("""\ <article class="h-cite"> <span class="p-uid"></span> <a class="p-name u-url" href="http://p">p</a> <div class=""> </div> </article> <article class="h-cite"> <span class="p-uid"></span> <a class="u-url" href="http://a">http://a</a> <div class=""> </div> </article> """, html)