def render_ents(self, text, spans, title):
markup = "<STR_LIT>"<EOL>offset = <NUM_LIT:0><EOL>for span in spans:<EOL><INDENT>label = span["<STR_LIT:label>"]<EOL>start = span["<STR_LIT:start>"]<EOL>end = span["<STR_LIT:end>"]<EOL>entity = escape_html(text[start:end])<EOL>fragments = text[offset:start].split("<STR_LIT:\n>")<EOL>for i, fragment in enumerate(fragments):<EOL><INDENT>markup += escape_html(fragment)<EOL>if len(fragments) > <NUM_LIT:1> and i != len(fragments) - <NUM_LIT:1>:<EOL><INDENT>markup += "<STR_LIT>"<EOL><DEDENT><DEDENT>if self.ents is None or label.upper() in self.ents:<EOL><INDENT>color = self.colors.get(label.upper(), self.default_color)<EOL>ent_settings = {"<STR_LIT:label>": label, "<STR_LIT:text>": entity, "<STR_LIT>": color}<EOL>if self.direction == "<STR_LIT>":<EOL><INDENT>markup += TPL_ENT_RTL.format(**ent_settings)<EOL><DEDENT>else:<EOL><INDENT>markup += TPL_ENT.format(**ent_settings)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>markup += entity<EOL><DEDENT>offset = end<EOL><DEDENT>markup += escape_html(text[offset:])<EOL>markup = TPL_ENTS.format(content=markup, dir=self.direction)<EOL>if title:<EOL><INDENT>markup = TPL_TITLE.format(title=title) + markup<EOL><DEDENT>return markup<EOL>
Render entities in text.

        text (unicode): Original text.
        spans (list): Individual entity spans and their start, end and label.
        title (unicode or None): Document title set in Doc.user_data['title'].