def as_yaml(self): """ Render the YAML node and subnodes as string. """ dumped = dump(self.as_marked_up(), Dumper=StrictYAMLDumper, allow_unicode=True) return dumped if sys.version_info[0] == 3 else dumped.decode("utf8")
def start_line(self, document): slicedpart = self._slice_segment( self._indices, document, include_selected=False ) if slicedpart is None or slicedpart == {} or slicedpart == []: return 1 else: return ( len(dump(slicedpart, Dumper=RoundTripDumper).rstrip().split("\n")) + 1 )
def problem_mark(self): problem_line = self._chunk.end_line() - 1 str_document = dump(self._chunk.whole_document, Dumper=RoundTripDumper) problem_index = len(u"\n".join( str_document.split(u"\n")[:problem_line])) return StringMark( self._chunk.label, problem_index, problem_line, 0, str_document, problem_index + 1, )
def context_mark(self): context_line = self._chunk.start_line() - 1 str_document = dump(self._chunk.whole_document, Dumper=RoundTripDumper) context_index = len(u"\n".join( str_document.split(u"\n")[:context_line])) return StringMark( self._chunk.label, context_index, context_line, 0, str_document, context_index + 1, )
def lines_after(self, document, how_many): return "\n".join( dump(document, Dumper=RoundTripDumper).split("\n")[ self.end_line(document) : self.end_line(document) + how_many ] )
def lines_before(self, document, how_many): return "\n".join( dump(document, Dumper=RoundTripDumper).split("\n")[ self.start_line(document) - 1 - how_many : self.start_line(document) - 1 ] )
def lines(self, document): return "\n".join( dump(document, Dumper=RoundTripDumper).split("\n")[ self.start_line(document) - 1 : self.end_line(document) ] )
def end_line(self, document): slicedpart = self._slice_segment(self._indices, document, include_selected=True) return len(dump(slicedpart, Dumper=RoundTripDumper).rstrip().split("\n"))