def parse_appendix_paragraphs(p_elements, id_type, label): for p_element in p_elements: p = pre_process_tags(p_element) if id_type == 'section': p_content = parse_ids(p.text, label) + "\n" p.replaceWith(lint_paragraph(p_content)) else: p_content = LEVEL_STATE.parse_appendix_graph(p, label) + "\n" p.replaceWith(lint_paragraph(p_content))
def parse_multi_id_graph(graph, ids, label): """ Parse a graph with 1 to 3 ids and return individual graphs with their own braced IDs. """ new_graphs = '' id_refs = PAYLOAD.interp_refs.get(label) LEVEL_STATE.next_token = ids[0] pid1 = LEVEL_STATE.next_id() split1 = graph.partition('({})'.format(ids[1])) text1 = lint_paragraph(combine_bolds(split1[0])) pid2_marker = split1[1] remainder = bold_first_italics(split1[2]) new_graphs += "\n{" + pid1 + "}\n" new_graphs += text1 + '\n' if id_refs and pid1 in id_refs: new_graphs += '\n' + id_refs[pid1] + '\n' LEVEL_STATE.next_token = ids[1] pid2 = LEVEL_STATE.next_id() new_graphs += "\n{" + pid2 + "}\n" if len(ids) == 2: text2 = lint_paragraph( combine_bolds(" ".join([pid2_marker, remainder]))) new_graphs += text2 + '\n' if id_refs and pid2 in id_refs: new_graphs += '\n' + id_refs[pid2] + '\n' return new_graphs else: split2 = remainder.partition('({})'.format(ids[2])) pid3_marker = split2[1] remainder2 = bold_first_italics(split2[2]) text2 = lint_paragraph( combine_bolds(" ".join([pid2_marker, split2[0]]))) new_graphs += text2 + '\n' LEVEL_STATE.next_token = ids[2] pid3 = LEVEL_STATE.next_id() new_graphs += "\n{" + pid3 + "}\n" text3 = lint_paragraph( combine_bolds(" ".join([pid3_marker, remainder2]))) new_graphs += text3 + '\n' if id_refs and pid3 in id_refs: new_graphs += '\n' + id_refs[pid3] + '\n' return new_graphs
def parse_singleton_graph(graph_text, label): """Take a paragraph with a single ID and return styled with a braced ID""" new_graph = '' id_refs = PAYLOAD.interp_refs.get(label) id_match = re.search(paren_id_patterns['initial'], graph_top(graph_text)) linted = lint_paragraph(combine_bolds(graph_text)) if not id_match: return '\n' + linted + '\n' id_token = id_match.group(1).strip('*') if not LEVEL_STATE.token_validity_test(id_token): return '\n' + linted + '\n' LEVEL_STATE.next_token = id_token pid = LEVEL_STATE.next_id() if pid: new_graph += "\n{" + pid + "}\n" new_graph += linted + '\n' if id_refs and pid in id_refs: new_graph += '\n' + id_refs[pid] + '\n' return new_graph
def test_paragraph_emdash_linting(self): test_graph = 'Now is the time -\n' expected_result = 'Now is the time ---\n' result = paragraphs.lint_paragraph(test_graph) self.assertEqual(result, expected_result)
def test_paragraph_bold_linting_insensitive_sic(self): test_graph = 'Now is the time to **see** the best **Et. seq.** ever.' expected_result = 'Now is the time to *see* the best *Et. seq.* ever.' result = paragraphs.lint_paragraph(test_graph) self.assertEqual(result, expected_result)
def test_paragraph_bold_linting(self): test_graph = 'Now is the time to **See** the best **et seq.** ever.' expected_result = 'Now is the time to *See* the best *et seq.* ever.' result = paragraphs.lint_paragraph(test_graph) self.assertEqual(result, expected_result)