def mkfrag(text, tokens, startchar=None, endchar=None, charsbefore=0, charsafter=0):
 if (startchar is None):
  startchar = (tokens[0].startchar if tokens else 0)
 if (endchar is None):
  endchar = (tokens[(-1)].endchar if tokens else len(text))
 startchar = max(0, (startchar - charsbefore))
 endchar = min(len(text), (endchar + charsafter))
 return Fragment(text, tokens, startchar, endchar)

def mkfrag ( text , tokens , startchar = None , endchar = None , charsbefore = 0 , charsafter = 0 ) : if ( startchar is None ) : startchar = ( tokens [ 0 ] . startchar if tokens else 0 ) if ( endchar is None ) : endchar = ( tokens [ ( - 1 ) ] . endchar if tokens else len ( text ) ) startchar = max ( 0 , ( startchar - charsbefore ) ) endchar = min ( len ( text ) , ( endchar + charsafter ) ) return Fragment ( text , tokens , startchar , endchar )
returns a :class:fragment object based on the :class:analysis .