Exemplo n.º 1
0
    def test_render_styles_data(self):
        blocks = [
            {
                'key': '5s7g9',
                'text': 'test',
                'type': 'unstyled',
                'depth': 0,
                'inlineStyleRanges': [],
                'entityRanges': [],
            },
        ]

        def component(props):
            self.assertEqual(props['blocks'], blocks)
            self.assertEqual(props['block'], blocks[0])
            self.assertEqual(props['inline_style_range']['style'], 'ITALIC')
            return None

        style_state = StyleState(Options.map_styles({
            'ITALIC': component,
        }))

        style_state.apply(Command('start_inline_style', 0, 'ITALIC'))
        style_state.render_styles('Test text', blocks[0], blocks)
        style_state.apply(Command('stop_inline_style', 9, 'ITALIC'))
Exemplo n.º 2
0
    def __init__(self, config: Optional[Config] = None) -> None:
        if config is None:
            config = {}

        self.composite_decorators = config.get("composite_decorators", [])

        self.entity_options = Options.map_entities(
            config.get("entity_decorators", {}))
        self.block_options = Options.map_blocks(
            config.get("block_map", BLOCK_MAP))
        self.style_options = Options.map_styles(
            config.get("style_map", STYLE_MAP))

        DOM.use(config.get("engine", DOM.STRING))
Exemplo n.º 3
0
    def __init__(self, config=None):
        if config is None:
            config = {}

        self.composite_decorators = config.get('composite_decorators', [])
        self.has_decorators = len(self.composite_decorators) > 0

        self.entity_options = Options.map_entities(
            config.get('entity_decorators', {}))
        self.block_options = Options.map_blocks(
            config.get('block_map', BLOCK_MAP))
        self.style_options = Options.map_styles(
            config.get('style_map', STYLE_MAP))

        DOM.use(config.get('engine', DOM.STRING))
    def test_render_styles_data(self):
        blocks = [{
            "key": "5s7g9",
            "text": "test",
            "type": "unstyled",
            "depth": 0,
            "inlineStyleRanges": [],
            "entityRanges": [],
        }]

        def component(props):
            self.assertEqual(props["blocks"], blocks)
            self.assertEqual(props["block"], blocks[0])
            self.assertEqual(props["inline_style_range"]["style"], "ITALIC")
            return None

        style_state = StyleState(Options.map_styles({"ITALIC": component}))

        style_state.apply(Command("start_inline_style", 0, "ITALIC"))
        style_state.render_styles("Test text", blocks[0], blocks)
        style_state.apply(Command("stop_inline_style", 9, "ITALIC"))
 def setUp(self):
     DOM.use(DOM.STRING)
     self.style_state = StyleState(
         Options.map_styles(style_map)  # type: ignore
     )