def test_can_split_a_fragment_and_place_its_children_in_different_parents( self): hb = self.hb doc = hb["doc"] h = hb["h"] b = hb["b"] p = hb["p"] tr = Transform(doc(h("Head"), b(h("One"), p("Two")))) tr.replace(0, tr.doc.content.size, tr.doc.slice(7, 17)) assert tr.doc.eq(doc(h("One"), b(p("Two"))))
def test_will_insert_filler_nodes_before_a_node_when_necessary(self): hb = self.hb doc = hb["doc"] h = hb["h"] b = hb["b"] p = hb["p"] tr = Transform(doc(h("Head"), b(p("One")))) tr.replace(0, tr.doc.content.size, tr.doc.slice(6, tr.doc.content.size)) assert tr.doc.eq(doc(h(), b(p("One"))))
def test_can_wrap_a_paragraph_in_a_body_even_when_its_not_the_first_node( self): hb = self.hb doc = hb["doc"] h = hb["h"] b = hb["b"] p = hb["p"] tr = Transform(doc(h("Head"), b(p("One"), p("Two")))) tr.replace(0, tr.doc.content.size, tr.doc.slice(8, 16)) assert tr.doc.eq(doc(h("One"), b(p("Two"))))
def test_can_unwrap_a_body_after_a_placed_node(self): hb = self.hb doc = hb["doc"] h = hb["h"] b = hb["b"] p = hb["p"] tr = Transform(hb["doc"](hb["h"]("Head"), hb["b"](hb["p"]("Content")))) tr.replace(7, 7, tr.doc.slice(0, tr.doc.content.size)) assert tr.doc.eq( doc(h("Head"), b(h("Head"), p("Content"), p("Content"))))
def test_preserves_marks_on_open_slice_block_nodes(self): ms = self.ms tr = Transform( ms.node("doc", None, [ms.node("paragraph", None, [ms.text("a")])])) tr.replace( 3, 3, ms.node( "doc", None, [ms.node("paragraph", None, [ms.text("b")], [ms.mark("em")])], ).slice(1, 3), ) assert tr.doc.child_count == 2 assert len(tr.doc.last_child.marks) == 1
def test_preserves_mark_on_block_nodes(self): ms = self.ms tr = Transform( ms.node( "doc", None, [ ms.node("paragraph", None, [ms.text("hey")], [ms.mark("em")]), ms.node("paragraph", None, [ms.text("ok")], [ms.mark("strong")]), ], )) tr.replace(2, 7, tr.doc.slice(2, 7)) assert tr.doc.eq(tr.before)
def test_can_unwrap_a_paragraph_when_replacing_into_a_strict_schema(self): hb = self.hb tr = Transform(hb["doc"](hb["h"]("Head"), hb["b"](hb["p"]("Content")))) tr.replace(0, tr.doc.content.size, tr.doc.slice(7, 16)) assert tr.doc.eq(hb["doc"](hb["h"]("Content"), hb["b"](hb["p"]())))