def block_quote(self, lines: List[str], line_offset: int) -> List[nodes.Element]: """Parse a block quote, which is a block of text, followed by an (optional) attribution. :: No matter where you go, there you are. -- Buckaroo Banzai """ elements = [] # split attribution last_line_blank = False blockquote_lines = lines attribution_lines = [] attribution_line_offset = None # First line after a blank line must begin with a dash for i, line in enumerate(lines): if not line.strip(): last_line_blank = True continue if not last_line_blank: last_line_blank = False continue last_line_blank = False match = self.attribution_pattern.match(line) if not match: continue attribution_line_offset = i attribution_lines = [match.group(2)] for at_line in lines[i + 1:]: indented_line = at_line[len(match.group(1)):] if len(indented_line) != len(at_line.lstrip()): break attribution_lines.append(indented_line) blockquote_lines = lines[:i] break # parse block blockquote = nodes.block_quote() self.nested_parse(blockquote_lines, line_offset, blockquote) elements.append(blockquote) # parse attribution if attribution_lines: attribution_text = "\n".join(attribution_lines) lineno = self._lineno + line_offset + (attribution_line_offset or 0) textnodes, messages = self.inline_text(attribution_text, lineno) attribution = nodes.attribution(attribution_text, "", *textnodes) ( attribution.source, attribution.line, ) = self.state_machine.get_source_and_line(lineno) blockquote += attribution elements += messages return elements
else: targetid = "index-%s" % env.index_num targetnode = nodes.target('', '', ids=[targetid]) targetnode['classes'] = ['epigraph'] node = quote_node() node += nodes.block_quote( '', nodes.paragraph('', '\n'.join(self.content), classes=['text'])) #state.nested_parse(self.content, self.content_offset, node) for element in node: if isinstance(element, nodes.block_quote): element['classes'] += ['epigraph'] signode = [nodes.attribution('--', '--')] # Embed all components within attributions siglb = nodes.line_block('') # Pre-format some if 'date' in options: options['date'] = '[%(date)s]' % options if 'source' in options: options['source'] = 'Source: %(source)s' % options for el in ['author', 'date', 'affiliation', 'source']: if el in options: siglb += [nodes.inline('', ' '+options[el], classes=[el])] signode[0].extend(siglb) node[0].extend(signode) node.line = self.lineno # tune up options _prep_tags(self.options)