def delimitMatches(thing, substring, markBefore, markAfter):
    if isinstance(thing, Annotator):
        realThing = thing.text
    else:
        realThing = str(thing)
    ListOfStartEndPairs = entry.findPrefixInText(substring, realThing)
    return delimit(thing, markBefore, markAfter, ListOfStartEndPairs)
        
if __name__=="__main__":
    #       012345678901234567890
    text = "this is a <b>test</b>"
    a = Annotator(text)
    a.quote()
    a.insertBefore(5, "<code>")
    a.insertAfter(8, "</code>")
    a.insertBefore(9, "<em>")
    a.insertAfter(20, "</em>")
    a.insertBefore(0, "<h1>")
    a.insertAfter(20, "</h1>")
    out = str(a)
    print "from", repr(text)
    print "got", repr(out)
    final = str(out)
    expected = '<h1>this <code>is a</code><em> &lt;b&gt;test&lt;/b&gt;</em></h1>'
    if final!=expected:
        raise ValueError, "final didn't match expected: "+repr((final, expected))
    text = "prefixinator \ncontaining\n prefix as prefixes several places"
    #import entry
    pairs = entry.findPrefixInText("prefix", text)
    d = delimit(text, "<b>", "</b>", pairs)
    print "from", repr(text)
    print "got", repr(d)
    expected = '<b>prefix</b>inator \ncontaining\n <b>prefix</b> as <b>prefix</b>es several places'
    if str(d)!=expected:
        raise ValueError, "delimit doesn't match expected "+repr((d, expected))
    print "summarize", d.summarize()
    a = d = None