def parse(cls, lines): header = lines[0].strip() term, classifier = header_regex.split(header, maxsplit=1) if \ (' :' in header) else (header, '') trimed_lines = trim_indent(lines[1:]) if (len(lines) > 1) else [''] definition = [line.rstrip() for line in trimed_lines] return cls(term.strip(), [classifier.strip()], definition)
def parse(cls, lines): """Parse a definition item from a set of lines. The class method parses the definition list item from the list of docstring lines and produces a DefinitionItem with the term, classifier and the definition. .. note:: The global indention in the definition lines is striped. The term definition is assumed to be in one of the following formats:: term Definition. :: term : Definition. :: term Definition, paragraph 1. Definition, paragraph 2. :: term: Definition, paragraph 1. Definition, paragraph 2. :: term : any text is valid here Definition. Arguments --------- lines docstring lines of the definition without any empty lines before or after. Returns ------- definition : AnyItem """ header = lines[0].strip() term, classifier = header_regex.split(header, maxsplit=1) if \ (' :' in header) else (header, '') classifier = classifier.strip() classifier = [] if classifier == '' else [classifier] trimed_lines = trim_indent(lines[1:]) if (len(lines) > 1) else [] definition = [line.rstrip() for line in trimed_lines] return cls(term.strip(), classifier, definition)