From fd650d3dff2e542524c7fd7055dab14f7e35ff5c Mon Sep 17 00:00:00 2001 From: Nicolas Date: Fri, 28 Feb 2025 12:37:21 +0100 Subject: [PATCH] column alignment for markdown output added --- README.md | 4 ++-- src/pelfy/__init__.py | 3 +++ src/pelfy/output_formatter.py | 4 ++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 275f071..8413433 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ elf.sections elf.functions ``` | index | name | info | size | stb | description | -|-------|--------------------|----------|-----:|------------|-------------------------| +|------:|--------------------|----------|-----:|------------|-------------------------| | 11 | result_float | STT_FUNC | 8 | STB_GLOBAL | Symbol is a code object | | 12 | result_float_float | STT_FUNC | 12 | STB_GLOBAL | Symbol is a code object | | 13 | add_float_float | STT_FUNC | 12 | STB_GLOBAL | Symbol is a code object | @@ -61,7 +61,7 @@ elf.functions elf.symbols['read_float'].get_relocations() ``` | index | symbol name | type | calculation | -|-------|--------------------|----------------------|-------------| +|------:|--------------------|----------------------|-------------| | 4 | .LANCHOR0 | R_RISCV_PCREL_HI20 | S + A - P | | 5 | | R_RISCV_RELAX | | | 6 | .L0 | R_RISCV_PCREL_LO12_I | S - P | diff --git a/src/pelfy/__init__.py b/src/pelfy/__init__.py index d815206..08d374a 100644 --- a/src/pelfy/__init__.py +++ b/src/pelfy/__init__.py @@ -302,6 +302,9 @@ class elf_list(Generic[_T]): def _repr_html_(self) -> str: return self._repr_table('html') + def _repr_markdown_(self) -> str: + return self._repr_table('markdown') + class section_list(elf_list[elf_section]): """A class for representing a list of ELF section diff --git a/src/pelfy/output_formatter.py b/src/pelfy/output_formatter.py index 77ed349..7ba68dd 100644 --- a/src/pelfy/output_formatter.py +++ b/src/pelfy/output_formatter.py @@ -11,7 +11,7 @@ def generate_table(data: list[list[Any]], columns: list[str], elif format == 'markdown': return generate_md_table(data, columns, right_adj_col) else: - return generate_md_table(data, columns, right_adj_col).replace('|', '') + return generate_md_table(data, columns, right_adj_col).replace('|', '').replace(':', '-') def generate_md_table(data: list[list[Any]], columns: list[str], right_adj_col: list[str] = []) -> str: @@ -22,7 +22,7 @@ def generate_md_table(data: list[list[Any]], columns: list[str], right_adj_col: formatted_row = ' | '.join(f"{str(item):<{column_widths[i]}}" for i, item in enumerate(columns)) table += '| ' + formatted_row + ' |\n' - table += '|-' + '-|-'.join('-' * width for width in column_widths) + '-|\n' + table += '|' + '|'.join('-' * width + '-:' if c in right_adj_col else ':-' + '-' * width for width, c in zip(column_widths, columns)) + '|\n' for row in data: formatted_row = ''