当前位置: 首页>>代码示例>>Python>>正文


Python DOM.create_element方法代码示例

本文整理汇总了Python中draftjs_exporter.dom.DOM.create_element方法的典型用法代码示例。如果您正苦于以下问题:Python DOM.create_element方法的具体用法?Python DOM.create_element怎么用?Python DOM.create_element使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在draftjs_exporter.dom.DOM的用法示例。


在下文中一共展示了DOM.create_element方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: render_entities

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
    def render_entities(self, style_node):
        # We have a complete (start, stop) entity to render.
        if self.completed_entity is not None:
            entity_details = self.get_entity_details(self.completed_entity)
            opts = Options.for_entity(self.entity_decorators, entity_details['type'])
            props = entity_details['data'].copy()
            props['entity'] = {
                'type': entity_details['type'],
            }

            if len(self.element_stack) == 1:
                children = self.element_stack[0]
            else:
                children = DOM.create_element()

                for n in self.element_stack:
                    DOM.append_child(children, n)

            self.completed_entity = None
            self.element_stack = []

            # Is there still another entity? (adjacent) if so add the current style_node for it.
            if self.has_entity():
                self.element_stack.append(style_node)

            return DOM.create_element(opts.element, props, children)

        if self.has_entity():
            self.element_stack.append(style_node)
            return None

        return style_node
开发者ID:springload,项目名称:draftjs_exporter,代码行数:34,代码来源:entity_state.py

示例2: button

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
def button(props):
    href = props.get('href', '#')
    icon_name = props.get('icon', None)
    text = props.get('text', '')

    return DOM.create_element(
        'a',
        {'class': 'icon-text' if icon_name else None, 'href': href},
        DOM.create_element(icon, {'name': icon_name}) if icon_name else None,
        DOM.create_element('span', {'class': 'icon-text__text'}, text) if icon_name else text
    )
开发者ID:springload,项目名称:draftjs_exporter,代码行数:13,代码来源:test_entities.py

示例3: update_stack

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
    def update_stack(self, options, depth):
        if depth >= self.stack.length():
            # If the depth is gte the stack length, we need more wrappers.
            depth_levels = range(self.stack.length(), depth + 1)

            for level in depth_levels:
                new_wrapper = Wrapper(level, options)

                # Determine where to append the new wrapper.
                if self.stack.head().last_child is None:
                    # If there is no content in the current wrapper, we need
                    # to add an intermediary node.
                    props = dict(options.props)
                    props['block'] = {
                        'type': options.type,
                        'depth': depth,
                        'data': {},
                    }
                    props['blocks'] = self.blocks

                    wrapper_parent = DOM.create_element(options.element, props)
                    DOM.append_child(self.stack.head().elt, wrapper_parent)
                else:
                    # Otherwise we can append at the end of the last child.
                    wrapper_parent = self.stack.head().last_child

                DOM.append_child(wrapper_parent, new_wrapper.elt)

                self.stack.append(new_wrapper)
        else:
            # Cut the stack to where it now stops, and add new wrapper.
            self.stack.slice(depth)
            self.stack.append(Wrapper(depth, options))
开发者ID:springload,项目名称:draftjs_exporter,代码行数:35,代码来源:wrapper_state.py

示例4: test_render_code_block

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
    def test_render_code_block(self):
        match = next(LINKIFY_DECORATOR['strategy'].finditer('test https://www.example.com'))

        self.assertEqual(DOM.create_element(LINKIFY_DECORATOR['component'], {
            'block': {'type': BLOCK_TYPES.CODE},
            'match': match,
        }, match.group(0)), match.group(0))
开发者ID:springload,项目名称:draftjs_exporter,代码行数:9,代码来源:test_composite_decorators.py

示例5: test_render_www

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
    def test_render_www(self):
        match = next(LINKIFY_DECORATOR['strategy'].finditer('test www.example.com'))

        self.assertEqual(DOM.render(DOM.create_element(LINKIFY_DECORATOR['component'], {
            'block': {'type': BLOCK_TYPES.UNSTYLED},
            'match': match,
        }, match.group(0))), '<a href="http://www.example.com">www.example.com</a>')
开发者ID:springload,项目名称:draftjs_exporter,代码行数:9,代码来源:test_composite_decorators.py

示例6: render_block

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
    def render_block(self, block, entity_map, wrapper_state):
        if block['inlineStyleRanges'] or block['entityRanges']:
            content = DOM.create_element()
            entity_state = EntityState(self.entity_decorators, entity_map)
            style_state = StyleState(self.style_map)

            for (text, commands) in self.build_command_groups(block):
                for command in commands:
                    entity_state.apply(command)
                    style_state.apply(command)

                # Decorators are not rendered inside entities.
                if entity_state.has_no_entity() and self.has_decorators:
                    decorated_node = render_decorators(self.composite_decorators, text, block, wrapper_state.blocks)
                else:
                    decorated_node = text

                styled_node = style_state.render_styles(decorated_node, block, wrapper_state.blocks)
                entity_node = entity_state.render_entities(styled_node)

                if entity_node is not None:
                    DOM.append_child(content, entity_node)

                    # Check whether there actually are two different nodes, confirming we are not inserting an upcoming entity.
                    if styled_node != entity_node and entity_state.has_no_entity():
                        DOM.append_child(content, styled_node)
        # Fast track for blocks which do not contain styles nor entities, which is very common.
        elif self.has_decorators:
            content = render_decorators(self.composite_decorators, block['text'], block, wrapper_state.blocks)
        else:
            content = block['text']

        return wrapper_state.element_for(block, content)
开发者ID:springload,项目名称:draftjs_exporter,代码行数:35,代码来源:html.py

示例7: render

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
    def render(self, content_state=None):
        """
        Starts the export process on a given piece of content state.
        """
        if content_state is None:
            content_state = {}

        blocks = content_state.get('blocks', [])
        wrapper_state = WrapperState(self.block_map, blocks)
        document = DOM.create_element()
        entity_map = content_state.get('entityMap', {})
        min_depth = 0

        for block in blocks:
            depth = block['depth']
            elt = self.render_block(block, entity_map, wrapper_state)

            if depth > min_depth:
                min_depth = depth

            # At level 0, append the element to the document.
            if depth == 0:
                DOM.append_child(document, elt)

        # If there is no block at depth 0, we need to add the wrapper that contains the whole tree to the document.
        if min_depth > 0 and wrapper_state.stack.length() != 0:
            DOM.append_child(document, wrapper_state.stack.tail().elt)

        return DOM.render(document)
开发者ID:springload,项目名称:draftjs_exporter,代码行数:31,代码来源:html.py

示例8: image

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
def image(props):
    return DOM.create_element('img', {
        'src': props.get('src'),
        'width': props.get('width'),
        'height': props.get('height'),
        'alt': props.get('alt'),
    })
开发者ID:springload,项目名称:draftjs_exporter,代码行数:9,代码来源:example.py

示例9: link

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
def link(props):
    attributes = {}
    for key in props:
        attr = key if key != 'url' else 'href'
        attributes[attr] = props[key]

    return DOM.create_element('a', attributes, props['children'])
开发者ID:springload,项目名称:draftjs_exporter,代码行数:9,代码来源:test_entities.py

示例10: br

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
def br(props):
    """
    Replace line breaks (\n) with br tags.
    """
    # Do not process matches inside code blocks.
    if props['block']['type'] == BLOCK_TYPES.CODE:
        return props['children']

    return DOM.create_element('br')
开发者ID:springload,项目名称:draftjs_exporter,代码行数:11,代码来源:example.py

示例11: hashtag

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
def hashtag(props):
    """
    Wrap hashtags in spans with a specific class.
    """
    # Do not process matches inside code blocks.
    if props['block']['type'] == BLOCK_TYPES.CODE:
        return props['children']

    return DOM.create_element('span', {'class': 'hashtag'}, props['children'])
开发者ID:springload,项目名称:draftjs_exporter,代码行数:11,代码来源:example.py

示例12: __init__

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
    def __init__(self, depth, options=None):
        self.depth = depth
        self.last_child = None

        if options:
            self.type = options.wrapper
            self.props = options.wrapper_props

            wrapper_props = dict(self.props) if self.props else {}
            wrapper_props['block'] = {
                'type': options.type,
                'depth': depth,
            }

            self.elt = DOM.create_element(self.type, wrapper_props)
        else:
            self.type = None
            self.props = None
            self.elt = DOM.create_element()
开发者ID:springload,项目名称:draftjs_exporter,代码行数:21,代码来源:wrapper_state.py

示例13: media_embed_entity

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
def media_embed_entity(props):
    """
    Helper to construct elements of the form
    <embed embedtype="media" url="https://www.youtube.com/watch?v=y8Kyi0WNg40"/>
    when converting from contentstate data
    """
    return DOM.create_element('embed', {
        'embedtype': 'media',
        'url': props.get('url'),
    })
开发者ID:BertrandBordage,项目名称:wagtail,代码行数:12,代码来源:rich_text.py

示例14: render_decorators

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
def render_decorators(decorators, text, block, blocks):
    decorated_children = list(apply_decorators(decorators, text, block, blocks))

    if len(decorated_children) == 1:
        decorated_node = decorated_children[0]
    else:
        decorated_node = DOM.create_element()
        for decorated_child in decorated_children:
            DOM.append_child(decorated_node, decorated_child)

    return decorated_node
开发者ID:springload,项目名称:draftjs_exporter,代码行数:13,代码来源:composite_decorators.py

示例15: document_link_entity

# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import create_element [as 别名]
def document_link_entity(props):
    """
    Helper to construct elements of the form
    <a id="1" linktype="document">document link</a>
    when converting from contentstate data
    """

    return DOM.create_element('a', {
        'linktype': 'document',
        'id': props.get('id'),
    }, props['children'])
开发者ID:Proper-Job,项目名称:wagtail,代码行数:13,代码来源:contentstate.py


注:本文中的draftjs_exporter.dom.DOM.create_element方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。