[docs]classTableWriter(writer_.Writer):""" Writes normalized documents and highlights to a simple table. Resembles: .. code-block:: text highlight_text highlight_page_number document_name -------------------------------------------------------------- ----------------------- ------------------------- Alice was sitting curled up in a corner of the great arm-chair 11 Through the Looking Glass :param documents: The list of documents to generate a table for. :param highlights: The list of highlights to generate a table for. :param columns: The columns to print for the table. A list of columns can be found by running ``remarking list columns`` :param truncate: If the ``highligh_text`` column should be truncated. :param print_plain: If a plain table with only spaces and new lines should be printed. """def__init__(self,documents:List[models.Document],highlights:List[models.Highlight],columns:T.Optional[List[str]]=None,truncate:bool=True,print_plain:bool=False)->None:self.truncate=truncateself.print_plain=print_plainself.highlights,self.headers=common.get_column_filtered_highlights_and_header(documents,highlights,columns)defwrite(self,logger:log.CommandLineLogger)->None:ifself.print_plain:logger.output_result(tabulate(self.highlights,headers="keys",tablefmt="plain")+'\n'ifself.highlightselse"")else:ifself.truncate:forhighlightinself.highlights:text=highlight['highlight_text']highlight['highlight_text']=text[0:100]+("..."iflen(text)>99else"")forhighlightinself.highlights:text=highlight['document_name']highlight['document_name']=text[0:100]+("..."iflen(text)>99else"")logger.output_result(tabulate(self.highlights,headers="keys",tablefmt="simple")+'\n'ifself.highlightselse"")
[docs]classTableWriterCommand(writer_command.WriterCommand):""" The writer command implementation for the ``table`` output writer."""defname(self)->str:return"table"defoptions(self)->List[writer_command.ClickOption]:returncommon.column_based_output_options+[click.option("--plain/--no-plain","print_plain",default=False,help="Output one data entry per line."),click.option("--truncate/--no-truncate","do_truncate",default=True,help="Truncate results when printing plain")]deflong_description(self)->str:return"""Output highlights normalized with documents as a table.Check out `remarking list columns` for a list of columns to choose fromfor the `--columns` option. """defshort_description(self)->str:return"Output highlights normalized with documents as a table"defwriter(self,documents:List[models.Document],highlights:List[models.Highlight],**kwargs:T.Any)->writer_.Writer:columns=kwargs['columns']do_truncate=kwargs['do_truncate']print_plain=kwargs['print_plain']returnTableWriter(documents,highlights,columns,do_truncate,print_plain)