def new_row(man, match): # build the row table = doc.Table() row_kind = doc.TAB_HEADER row_node = doc.Row(row_kind) table.content.append(row_node) use_par_style(row_node, match.group(1)) man.send(doc.ObjectEvent(doc.L_PAR, doc.ID_NEW_ROW, table)) row = match.group("row") while row: # scan the cell cell_node = doc.Cell(doc.TAB_NORMAL) while row: kind = doc.TAB_NORMAL if row[0] == '_': cell_node.kind = doc.TAB_HEADER kind = doc.TAB_HEADER row = row[1:] continue elif len(row) >= 2: if row[0] == '\\' and row[1] >= '0' and row[1] <= '9': cell_node.setInfo(doc.INFO_HSPAN, int(row[1])) row = row[2:] continue elif row[0] == '/' and row[1] >= '0' and row[1] <= '9': cell_node.setInfo(doc.INFO_VSPAN, int(row[1])) row = row[2:] continue new_row = consume_par_style(cell_node, row) if row == new_row: break row = new_row # find end pref = "" match = TABLE_SEP.search(row) while match and match.group() == "==": p = row.find("))", match.end()) if p < 0: pref = pref + row[:match.end()] row = row[match.end():] else: pref = pref + row[:p + 2] row = row[p + 2:] match = TABLE_SEP.search(row) if match: cell = pref + row[:match.start()] row = row[match.start() + 1:] else: cell = pref + row row = '' # dump object if required man.send(doc.ObjectEvent(doc.L_PAR, doc.ID_NEW_CELL, cell_node)) tparser.handleText(man, cell) if cell_node.kind == doc.TAB_NORMAL: row_node.kind = doc.TAB_NORMAL
def handle_header(man, match): level = len(match.group("level")) title = match.group("title") if title[-level:] == match.group("level"): title = title[:-level] man.send(doc.ObjectEvent(doc.L_HEAD, doc.ID_NEW, doc.Header(level))) tparser.handleText(man, title) man.send(doc.Event(doc.L_HEAD, doc.ID_TITLE))
def new_header(man, match): level = int(match.group(1)) header = doc.Header(level) use_par_style(header, match.group(2)) title = match.group("text") man.send(doc.ObjectEvent(doc.L_HEAD, doc.ID_NEW, header)) tparser.handleText(man, title) man.send(doc.Event(doc.L_HEAD, doc.ID_TITLE))
def new_style(man, match, style, id): text = match.group(id) if style: man.send(doc.StyleEvent(style)) text = use_text_style(man.get(), text) tparser.handleText(man, text, '') if style: man.send(doc.StyleEvent(style))
def new_list_item(man, match): pref = match.group("dots") if pref[-1] == '*': kind = doc.LIST_ITEM elif pref[-1] == '#': kind = doc.LIST_NUMBER depth = len(pref) man.send(doc.ItemEvent(kind, depth)) tparser.handleText(man, match.group("text"))
def new_squote(man, match): text = match.group("sqtext") t = i18n.getTranslator(man.doc) man.send( doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(t.get(i18n.GLYPH_OPEN_SQUOTE)))) tparser.handleText(man, text, '') man.send( doc.ObjectEvent(doc.L_WORD, doc.ID_NEW, doc.Word(t.get(i18n.GLYPH_CLOSE_SQUOTE))))
def new_footnote_multi(man, match): fn = doc.FootNote(doc.FOOTNOTE_DEF, match.group(1)) use_par_style(fn, match.group(2)) man.send(doc.ObjectEvent(doc.L_WORD, doc.ID_NEW_STYLE, fn)) tparser.handleText(man, match.group("text"))
def new_multi_def(man, match): man.send(MyDefEvent(doc.ID_NEW_DEF, 1)) tparser.handleText(man, match.group(1), '')
def new_definition(man, match): man.send(doc.DefEvent(doc.ID_NEW_DEF, 0)) tparser.handleText(man, match.group(1), '') man.send(doc.DefEvent(doc.ID_END_TERM, 0)) tparser.handleText(man, match.group(3), '')
def handleList(man, kind, match): depth = computeDepth(match.group(1)) man.send(doc.ItemEvent(kind, depth)) tparser.handleText(man, match.group(3))
def new_par_ext(man, match): man.send(doc.ObjectEvent(doc.L_PAR, doc.ID_END, doc.Par())) use_par_style(man.get(), match.group(1)) tparser.handleText(man, match.group('text'))
def handleQuote(man, match): man.send(doc.QuoteEvent(len(match.group(1)))) tparser.handleText(man, match.group(2))
def handleRow(man, match): table = doc.Table() if match.group(4) == '^': kind = doc.TAB_HEADER else: kind = doc.TAB_NORMAL row = doc.Row(kind) table.content.append(row) man.send(doc.ObjectEvent(doc.L_PAR, doc.ID_NEW_ROW, table)) row = match.group(1) object = None while row: # look kind if row[0] == '^': kind = doc.TAB_HEADER else: kind = doc.TAB_NORMAL row = row[1:] # find end pref = "" match = TABLE_SEP.search(row) while match and match.group() == "%%": p = row.find("%%", match.end()) if p < 0: pref = pref + row[:match.end()] row = row[match.end():] else: pref = pref + row[:p + 2] row = row[p + 2:] match = TABLE_SEP.search(row) if match: last = match.start() else: last = len(row) cell = pref + row[:last] row = row[last:] # dump object if required if cell == '' and object: #object.span += 1 object.setInfo(doc.INFO_HSPAN, object.getInfo(doc.INFO_HSPAN, 0) + 1) continue if object: man.send(doc.ObjectEvent(doc.L_PAR, doc.ID_NEW_CELL, object)) tparser.handleText(man, text) # strip and find align total = len(cell) cell = cell.lstrip() left = total - len(cell) total = len(cell) cell = cell.rstrip() right = total - len(cell) if left < right: align = doc.TAB_LEFT elif left > right: align = doc.TAB_RIGHT else: align = doc.TAB_CENTER # generate cell object = doc.Cell(kind, align, 1) text = cell # dump final object man.send(doc.ObjectEvent(doc.L_PAR, doc.ID_NEW_CELL, object)) tparser.handleText(man, text)
def handle_def(man, match): depth = computeDepth(match.group(1)) man.send(doc.DefEvent(doc.ID_NEW_DEF, depth)) tparser.handleText(man, match.group(3)) man.send(doc.DefEvent(doc.ID_END_TERM)) tparser.handleText(man, match.group(4))
def handle_item_list(man, match): man.send(doc.ItemEvent(doc.LIST_ITEM, 1)) tparser.handleText(man, match.group("text"))
def new_multi_blockquote(man, match): bq = BlockQuote() use_par_style(bq, match.group(1)) man.send(doc.ObjectEvent(doc.L_PAR, doc.ID_END, bq)) tparser.handleText(man, match.group("text"))
def handle_number_list(man, match): man.send(doc.ItemEvent(doc.LIST_NUMBER, 1)) tparser.handleText(man, match.group("text"))
def handleHeader(man, match): level = 6 - len(match.group(1)) title = match.group(2) man.send(doc.ObjectEvent(doc.L_HEAD, doc.ID_NEW, doc.Header(level))) tparser.handleText(man, title) man.send(doc.Event(doc.L_HEAD, doc.ID_TITLE))