コード例 #1
0
ファイル: test_command.py プロジェクト: atng/draftjs_exporter
 def test_from_style_ranges_single(self):
     self.assertEqual(str(Command.from_style_ranges({
         'inlineStyleRanges': [
             {
                 'offset': 0,
                 'length': 4,
                 'style': 'shazam',
             }
         ]
     })), str([
         Command('start_inline_style', 0, 'shazam'),
         Command('stop_inline_style', 4, 'shazam'),
     ]))
コード例 #2
0
    def build_commands(self, block: Block) -> List[Command]:
        """
        Build all of the manipulation commands for a given block.
        - One pair to set the text.
        - Multiple pairs for styles.
        - Multiple pairs for entities.
        """
        style_commands = Command.from_style_ranges(block)
        entity_commands = Command.from_entity_ranges(block)
        styles_and_entities = style_commands + entity_commands
        styles_and_entities.sort(key=attrgetter("index"))

        return ([Command("start_text", 0)] + styles_and_entities +
                [Command("stop_text", len(block["text"]))])
コード例 #3
0
 def test_from_style_ranges_single(self):
     self.assertEqual(
         str(
             Command.from_style_ranges({
                 "inlineStyleRanges": [{
                     "offset": 0,
                     "length": 4,
                     "style": "shazam"
                 }]
             })),
         str([
             Command("start_inline_style", 0, "shazam"),
             Command("stop_inline_style", 4, "shazam"),
         ]),
     )
コード例 #4
0
ファイル: test_command.py プロジェクト: atng/draftjs_exporter
 def test_from_style_ranges_multiple(self):
     self.assertEqual(str(Command.from_style_ranges({
         'inlineStyleRanges': [
             {
                 'offset': 0,
                 'length': 4,
                 'style': 'shazam',
             },
             {
                 'offset': 9,
                 'length': 3,
                 'style': 'wazzum',
             },
         ],
     })), str([
         Command('start_inline_style', 0, 'shazam'),
         Command('stop_inline_style', 4, 'shazam'),
         Command('start_inline_style', 9, 'wazzum'),
         Command('stop_inline_style', 12, 'wazzum'),
     ]))
コード例 #5
0
 def test_from_style_ranges_multiple(self):
     self.assertEqual(
         str(
             Command.from_style_ranges({
                 "inlineStyleRanges": [
                     {
                         "offset": 0,
                         "length": 4,
                         "style": "shazam"
                     },
                     {
                         "offset": 9,
                         "length": 3,
                         "style": "wazzum"
                     },
                 ]
             })),
         str([
             Command("start_inline_style", 0, "shazam"),
             Command("stop_inline_style", 4, "shazam"),
             Command("start_inline_style", 9, "wazzum"),
             Command("stop_inline_style", 12, "wazzum"),
         ]),
     )
コード例 #6
0
 def test_from_style_ranges_empty(self):
     self.assertEqual(
         str(Command.from_style_ranges({"inlineStyleRanges": []})), str([]))