diff --git a/client/src/components/Draftail/sources/EmbedSource.js b/client/src/components/Draftail/sources/EmbedSource.js index 2360b9f86b..90cb443da5 100644 --- a/client/src/components/Draftail/sources/EmbedSource.js +++ b/client/src/components/Draftail/sources/EmbedSource.js @@ -8,16 +8,14 @@ class EmbedSource extends ModalSource { this.parseData = this.parseData.bind(this); } - parseData(html) { - const embed = $.parseHTML(html)[0]; - + parseData(html, embed) { this.onConfirmAtomicBlock({ - embedType: embed.getAttribute('data-embedtype'), - url: embed.getAttribute('data-url'), - providerName: embed.getAttribute('data-provider-name'), - authorName: embed.getAttribute('data-author-name'), - thumbnail: embed.getAttribute('data-thumbnail-url'), - title: embed.getAttribute('data-title'), + embedType: embed.embedType, + url: embed.url, + providerName: embed.providerName, + authorName: embed.authorName, + thumbnail: embed.thumbnail, + title: embed.title, }); } diff --git a/wagtail/embeds/rich_text.py b/wagtail/embeds/rich_text.py index f8443e993f..9f7b48e258 100644 --- a/wagtail/embeds/rich_text.py +++ b/wagtail/embeds/rich_text.py @@ -4,7 +4,7 @@ from draftjs_exporter.dom import DOM from wagtail.admin.rich_text.converters import editor_html from wagtail.admin.rich_text.converters.contentstate_models import Entity from wagtail.admin.rich_text.converters.html_to_contentstate import AtomicBlockEntityElementHandler -from wagtail.embeds import format +from wagtail.embeds import embeds, format from wagtail.embeds.exceptions import EmbedException @@ -76,7 +76,19 @@ class MediaEmbedElementHandler(AtomicBlockEntityElementHandler): to contentstate """ def create_entity(self, name, attrs, state, contentstate): - return Entity('EMBED', 'IMMUTABLE', {'url': attrs['url']}) + try: + embed_obj = embeds.get_embed(attrs['url']) + embed_data = { + 'embedType': embed_obj.type, + 'url': embed_obj.url, + 'providerName': embed_obj.provider_name, + 'authorName': embed_obj.author_name, + 'thumbnail': embed_obj.thumbnail_url, + 'title': embed_obj.title, + } + except EmbedException: + embed_data = {'url': attrs['url']} + return Entity('EMBED', 'IMMUTABLE', embed_data) ContentstateMediaConversionRule = {