本文整理汇总了Python中draftjs_exporter.dom.DOM.render方法的典型用法代码示例。如果您正苦于以下问题:Python DOM.render方法的具体用法?Python DOM.render怎么用?Python DOM.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类draftjs_exporter.dom.DOM
的用法示例。
在下文中一共展示了DOM.render方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render
# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import render [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)
示例2: test_render_www
# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import render [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>')
示例3: test_render_decorators_conflicting_order_two
# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import render [as 别名]
def test_render_decorators_conflicting_order_two(self):
self.assertEqual(DOM.render(render_decorators([HASHTAG_DECORATOR, LINKIFY_DECORATOR], 'test https://www.example.com#hash #hashtagtest', {'type': BLOCK_TYPES.UNSTYLED, 'depth': 0}, [])), 'test https://www.example.com<span class="hashtag">#hash</span> <span class="hashtag">#hashtagtest</span>')
示例4: test_render_decorators_single
# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import render [as 别名]
def test_render_decorators_single(self):
self.assertEqual(DOM.render(render_decorators([LINKIFY_DECORATOR], 'test https://www.example.com#hash #hashtagtest', {'type': BLOCK_TYPES.UNSTYLED, 'depth': 0}, [])), 'test <a href="https://www.example.com#hash">https://www.example.com#hash</a> #hashtagtest')
示例5: test_render
# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import render [as 别名]
def test_render(self):
self.assertEqual(DOM.render(DOM.create_element(BR_DECORATOR['component'], {'block': {'type': BLOCK_TYPES.UNSTYLED}}, '\n')), '<br/>')
示例6: test_render_without_icon
# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import render [as 别名]
def test_render_without_icon(self):
self.assertEqual(DOM.render(DOM.create_element(button, {
'href': 'http://example.com',
'text': 'Launch',
})), '<a href="http://example.com">Launch</a>')
示例7: test_render_with_icon
# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import render [as 别名]
def test_render_with_icon(self):
self.assertEqual(DOM.render(DOM.create_element(button, {
'href': 'http://example.com',
'icon': 'rocket',
'text': 'Launch',
})), '<a class="icon-text" href="http://example.com"><svg class="icon"><use xlink:href="#icon-rocket"></use></svg><span class="icon-text__text">Launch</span></a>')
示例8: test_render
# 需要导入模块: from draftjs_exporter.dom import DOM [as 别名]
# 或者: from draftjs_exporter.dom.DOM import render [as 别名]
def test_render(self):
self.assertEqual(DOM.render(DOM.create_element(link, {
'url': 'http://example.com',
}, 'wow')), '<a href="http://example.com">wow</a>')