def replace_a_tag(m):
     attrs = extract_attrs(m.group(1))
     if 'linktype' not in attrs:
         # return unchanged
         return m.group(0)
     handler = LINK_HANDLERS[attrs['linktype']]
     return handler.expand_db_attributes(attrs, for_editor)
예제 #2
0
        def replace_a_tag(m):
            """
            overridden, return href for Pages and Documents that
            journals frontend knows how to display
            """
            attrs = extract_attrs(m.group(1))
            if 'linktype' not in attrs:
                # return unchanged
                return m.group(0)
            if attrs['linktype'] == 'page':
                try:
                    page = Page.objects.get(id=attrs['id'])
                    return '<a href="{page_path}">'.format(
                        page_path=page.specific.get_frontend_page_path())
                except Page.DoesNotExist:
                    return "<a>"

            if attrs['linktype'] == 'document':
                try:
                    doc = JournalDocument.objects.get(id=attrs['id'])
                    return '<a href="{viewer_path}" target="_blank">'.format(
                        viewer_path=doc.get_viewer_url(base_url))
                except Page.DoesNotExist:
                    return "<a>"

            handler = get_link_handler(attrs['linktype'])
            return handler.expand_db_attributes(attrs, for_editor)
예제 #3
0
 def replace_embed_tag(m):
     """
     overriden, change img src to be absolute url so it can be
     rendered by frontend
     """
     attrs = extract_attrs(m.group(1))
     handler = get_embed_handler(attrs['embedtype'])
     html = handler.expand_db_attributes(attrs, for_editor)
     if attrs['embedtype'] == 'image':
         html = html.replace('src="/', 'src="{}'.format(base_url))
     return html
예제 #4
0
 def test_extract_attr(self):
     html = '<a foo="bar" baz="quux">snowman</a>'
     result = extract_attrs(html)
     self.assertEqual(result, {'foo': 'bar', 'baz': 'quux'})
예제 #5
0
 def test_extract_attr(self):
     html = '<a foo="bar" baz="quux">snowman</a>'
     result = extract_attrs(html)
     self.assertEqual(result, {'foo': 'bar', 'baz': 'quux'})
 def replace_embed_tag(m):
     attrs = extract_attrs(m.group(1))
     handler = NEW_EMBED_HANDLERS[attrs['embedtype']]
     return handler.expand_db_attributes(attrs, for_editor)
예제 #7
0
 def test_extract_attr(self):
     html = '<a foo="bar" baz="quux">snowman</a>'
     result = extract_attrs(html)
     self.assertEqual(result, {"foo": "bar", "baz": "quux"})