def handle_starttag(self, name, attrs, state, contentstate): if state.current_block is None: # Inline entity element encountered at the top level - # start a new paragraph block to contain it block = Block('unstyled', depth=state.list_depth) contentstate.blocks.append(block) state.current_block = block state.leading_whitespace = STRIP_WHITESPACE if state.leading_whitespace == FORCE_WHITESPACE: # any pending whitespace should be output before handling this tag, # and subsequent whitespace should be collapsed into it (= stripped) state.current_block.text += ' ' state.leading_whitespace = STRIP_WHITESPACE # convert attrs from a list of (name, value) tuples to a dict # for get_attribute_data to work with attrs = dict(attrs) entity = Entity(self.entity_type, self.mutability, self.get_attribute_data(attrs)) key = contentstate.add_entity(entity) entity_range = EntityRange(key) entity_range.offset = len(state.current_block.text) state.current_block.entity_ranges.append(entity_range) state.current_entity_ranges.append(entity_range)
def create_entity(self, name, attrs, state, contentstate): return Entity('SNIPPET-EMBED', 'IMMUTABLE', { "id": attrs.get("id"), "string": attrs.get("data-string"), "edit_link": attrs.get("data-edit-link"), "app_name": attrs.get("data-app-name"), "model_name": attrs.get("data-model-name"), })
def create_entity(self, name, attrs, state, contentstate): """ Format a custom image entity out of database HTML into the Draft.js ContentState format. """ return Entity( 'NEWS-IMAGE', 'MUTABLE', { 'id': attrs.get('id'), 'title': attrs.get('title'), 'alt': attrs.get('alt'), 'href': attrs.get('href'), 'width': attrs.get('width'), })
def create_entity(self, name, attrs, state, contentstate): 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)
def create_entity(self, name, attrs, state, contentstate): 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)
def create_entity(self, name, attrs, state, contentstate): Image = get_image_model() try: image = Image.objects.get(id=attrs['id']) image_format = get_image_format(attrs['format']) rendition = get_rendition_or_not_found(image, image_format.filter_spec) src = rendition.url except Image.DoesNotExist: src = '' return Entity('IMAGE', 'IMMUTABLE', { 'id': attrs['id'], 'src': src, 'alt': attrs.get('alt'), 'format': attrs['format'] })
def create_entity(self, name, attrs, state, contentstate): Media = get_media_model() try: media = Media.objects.get(id=attrs['id']) except Media.DoesNotExist: media = None return Entity( 'MEDIA', 'IMMUTABLE', { 'id': attrs['id'], 'title': media.title, 'type': media.type, 'thumbnail': media.thumbnail.url if media.thumbnail else '', 'file': media.file.url if media.file else '', 'autoplay': True if attrs.get('autoplay') == 'true' else False, 'loop': True if attrs.get('loop') == 'true' else False, 'mute': True if attrs.get('mute') == 'true' else False })
def handle_starttag(self, name, attrs, state, contentstate): assert state.current_block is not None, "%s element found at the top level" % name if state.leading_whitespace == FORCE_WHITESPACE: # any pending whitespace should be output before handling this tag, # and subsequent whitespace should be collapsed into it (= stripped) state.current_block.text += ' ' state.leading_whitespace = STRIP_WHITESPACE # convert attrs from a list of (name, value) tuples to a dict # for get_attribute_data to work with attrs = dict(attrs) entity = Entity(self.entity_type, self.mutability, self.get_attribute_data(attrs)) key = contentstate.add_entity(entity) entity_range = EntityRange(key) entity_range.offset = len(state.current_block.text) state.current_block.entity_ranges.append(entity_range) state.current_entity_ranges.append(entity_range)
def create_entity(self, name, attrs, state, contentstate): Image = get_image_model() try: image = Image.objects.get(id=attrs["id"]) image_format = get_image_format(attrs["format"]) rendition = get_rendition_or_not_found(image, image_format.filter_spec) src = rendition.url except Image.DoesNotExist: src = "" return Entity( "IMAGE", "IMMUTABLE", { "id": attrs["id"], "src": src, "alt": attrs.get("alt"), "format": attrs["format"], }, )
def create_entity(self, name, attrs, state, contentstate): return Entity('HORIZONTAL_RULE', 'IMMUTABLE', {})
def create_entity(self, name, attrs, state, contentstate): return Entity('KATEX', 'IMMUTABLE', { 'text': attrs['data-katex-text'], })