def parse_title(heading_line): # WARNING this regular expression fails if there is just one or no # word in the heading but a tag! m = REGEX_HEADING.match(heading_line) if m: r = m.groupdict() level = len(r[u'level']) todo = None title = u'' tags = filter(test_not_empty, r[u'tags'].split(u':')) if r[u'tags'] else [] tags = list(tags) # if there is just one or no word in the heading, redo the parsing mt = REGEX_TAG.match(r[u'title']) if not tags and mt: r = mt.groupdict() tags = filter( test_not_empty, r[u'tags'].split(u':')) if r[u'tags'] else [] tags = list(tags) if r[u'title'] is not None: _todo_title = [ i.strip() for i in r[u'title'].split(None, 1) ] if _todo_title and _todo_title[0] in allowed_todo_states: todo = _todo_title[0] if len(_todo_title) > 1: title = _todo_title[1] else: title = r[u'title'].strip() return (level, todo, title, tags) raise ValueError(u'Data doesn\'t start with a heading definition.')
def parse_title(heading_line): # WARNING this regular expression fails if there is just one or no # word in the heading but a tag! m = REGEX_HEADING.match(heading_line) if m: r = m.groupdict() level = len(r[u'level']) todo = None title = u'' tags = filter(test_not_empty, r[u'tags'].split(u':')) if r[u'tags'] else [] tags = list(tags) # if there is just one or no word in the heading, redo the parsing mt = REGEX_TAG.match(r[u'title']) if not tags and mt: r = mt.groupdict() tags = filter(test_not_empty, r[u'tags'].split(u':')) if r[u'tags'] else [] tags = list(tags) if r[u'title'] is not None: _todo_title = [i.strip() for i in r[u'title'].split(None, 1)] if _todo_title and _todo_title[0] in allowed_todo_states: todo = _todo_title[0] if len(_todo_title) > 1: title = _todo_title[1] else: title = r[u'title'].strip() return (level, todo, title, tags) raise ValueError(u'Data doesn\'t start with a heading definition.')
def parse_title(heading_line): # checkbox is not heading if REGEX_HEADING.match(heading_line) is not None: return None m = REGEX_CHECKBOX.match(heading_line) if m: r = m.groupdict() return (len(r[u'level']), r[u'type'], r[u'status'], r[u'title']) return None
def identify_checkbox(cls, line): u""" Test if a certain line is a checkbox or not. :line: the line to check :returns: indent_level """ # checkbox is not heading if REGEX_HEADING.match(line) is not None: return None m = REGEX_CHECKBOX.match(line) if m: r = m.groupdict() return len(r[u'level']) return None