Exemplo n.º 1
0
def test_can_remote_multiple_excluded_marks():
    schema = Schema({
        "nodes": {
            "doc": {
                "content": "text*"
            },
            "text": {}
        },
        "marks": {
            "big": {
                "excludes": "small1 small2"
            },
            "small1": {},
            "small2": {}
        },
    })
    tr = Transform(
        schema.node(
            "doc",
            None,
            schema.text("hi", [schema.mark("small1"),
                               schema.mark("small2")]),
        ))
    assert len(tr.doc.first_child.marks) == 2
    tr.add_mark(0, 2, schema.mark("big"))
    assert len(tr.doc.first_child.marks) == 1
Exemplo n.º 2
0
def test_split(doc, expect, args, test_transform):
    if expect == "fail":
        with pytest.raises(TransformError):
            Transform(doc).split(doc.tag.get("a"), *args)
    else:
        tr = Transform(doc).split(doc.tag.get("a"), *args)
        test_transform(tr, expect)
Exemplo n.º 3
0
 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"))))
Exemplo n.º 4
0
 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"))))
Exemplo n.º 5
0
 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"))))
Exemplo n.º 6
0
 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"))))
Exemplo n.º 7
0
 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
Exemplo n.º 8
0
 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)
Exemplo n.º 9
0
def test_replace(doc, from_, to, content, open_start, open_end, result):
    if content:
        slice = Slice(content.content, open_start, open_end)
    else:
        slice = Slice.empty
    tr = Transform(doc).replace(from_, to, slice)
    assert tr.doc.eq(result)
Exemplo n.º 10
0
def test_set_block_type(doc, expect, node_type, attrs, test_transform):
    tr = Transform(doc).set_block_type(
        doc.tag.get("a"),
        doc.tag.get("b") or doc.tag.get("a"),
        schema.nodes[node_type],
        attrs,
    )
    test_transform(tr, expect)
Exemplo n.º 11
0
def test_replace(doc, source, expect, test_transform):
    slice = None
    if source is None:
        slice = Slice.empty
    elif isinstance(source, Slice):
        slice = source
    else:
        slice = source.slice(source.tag.get("a"), source.tag.get("b"))
    tr = Transform(doc).replace(doc.tag.get("a"),
                                doc.tag.get("b") or doc.tag.get("a"), slice)
    test_transform(tr, expect)
Exemplo n.º 12
0
def test_does_not_remove_non_excluded_marks_of_the_same_type():
    schema = Schema({
        "nodes": {
            "doc": {
                "content": "text*"
            },
            "text": {}
        },
        "marks": {
            "comment": {
                "excludes": "",
                "attrs": {
                    "id": {}
                }
            }
        },
    })
    tr = Transform(
        schema.node("doc", None,
                    schema.text("hi", [schema.mark("comment", {"id": 10})])))
    tr.add_mark(0, 2, schema.mark("comment", {"id": 20}))
    assert len(tr.doc.first_child.marks) == 2
Exemplo n.º 13
0
def test_add_mark(doc, mark, expect, test_transform):
    test_transform(
        Transform(doc).add_mark(doc.tag["a"], doc.tag["b"], mark), expect)
Exemplo n.º 14
0
def test_delete_range(doc, expect, test_transform):
    tr = Transform(doc).delete_range(doc.tag.get("a"),
                                     doc.tag.get("b") or doc.tag.get("a"))
    test_transform(tr, expect)
Exemplo n.º 15
0
def test_replace_range_with(doc, node, expect, test_transform):
    tr = Transform(doc).replace_range_with(
        doc.tag.get("a"),
        doc.tag.get("b") or doc.tag.get("a"), node)
    test_transform(tr, expect)
Exemplo n.º 16
0
 def test_step_json(tr):
     new_tr = Transform(tr.before)
     for step in tr.steps:
         new_tr.step(Step.from_json(tr.doc.type.schema, step.to_json()))
Exemplo n.º 17
0
def test_remove_mark(doc, mark, expect, test_transform):
    test_transform(
        Transform(doc).remove_mark(doc.tag.get("a", 0), doc.tag.get("b", 0),
                                   mark),
        expect,
    )
Exemplo n.º 18
0
def test_insert(doc, nodes, expect, test_transform):
    test_transform(Transform(doc).insert(doc.tag.get("a", 0), nodes), expect)
Exemplo n.º 19
0
def test_join(doc, expect, test_transform):
    tr = Transform(doc).join(doc.tag.get("a"))
    test_transform(tr, expect)
Exemplo n.º 20
0
 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"]())))
Exemplo n.º 21
0
def test_lift(doc, expect, test_transform):
    range = doc.resolve(doc.tag.get("a")).block_range(
        doc.resolve(doc.tag.get("b") or doc.tag.get("a")))
    tr = Transform(doc).lift(range, lift_target(range))
    test_transform(tr, expect)
Exemplo n.º 22
0
def test_wrap(doc, expect, type, attrs, test_transform):
    range = doc.resolve(doc.tag.get("a")).block_range(
        doc.resolve(doc.tag.get("b") or doc.tag.get("a")))
    tr = Transform(doc).wrap(range,
                             find_wrapping(range, schema.nodes[type], attrs))
    test_transform(tr, expect)
Exemplo n.º 23
0
 def invert(transform):
     out = Transform(transform.doc)
     for i, step in reversed(list(enumerate(transform.steps))):
         out.step(step.invert(transform.docs[i]))
     return out
Exemplo n.º 24
0
def test_set_node_markup(doc, expect, type, attrs, test_transform):
    tr = Transform(doc).set_node_markup(doc.tag.get("a"), schema.nodes[type],
                                        attrs)
    test_transform(tr, expect)
Exemplo n.º 25
0
def test_set_block_type_works_after_another_step(test_transform):
    d = doc(p("f<x>oob<y>ar"), p("baz<a>"))
    tr = Transform(d).delete(d.tag.get("x"), d.tag.get("y"))
    pos = tr.mapping.map(d.tag.get("a"))
    tr.set_block_type(pos, pos, schema.nodes["heading"], {"level": 1})
    test_transform(tr, doc(p("f<x><y>ar"), h1("baz<a>")))