Skip to content

Commit

Permalink
Add --no-page-labels switch to ignore page labels in markdown output
Browse files Browse the repository at this point in the history
Fixes issue #65
  • Loading branch information
0xabu committed Aug 10, 2023
1 parent 41c9544 commit 7203f7f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
3 changes: 3 additions & 0 deletions pdfannots/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'group_highlights_by_color',
'print_filename',
'sections',
'use_page_labels',
'wrap_column',
]
"""Names of arguments passed to the markdown printer."""
Expand Down Expand Up @@ -74,6 +75,8 @@ def parse_args() -> typ.Tuple[argparse.Namespace, LAParams]:
', '.join(GroupedMarkdownPrinter.ALL_SECTIONS)))
g.add_argument("--no-condense", dest="condense", default=True, action="store_false",
help="Emit annotations as a blockquote regardless of length.")
g.add_argument("--no-page-labels", dest="use_page_labels", default=True, action="store_false",
help="Ignore page labels if present, just print 1-based page numbers.")
g.add_argument("--print-filename", dest="print_filename", default=False, action="store_true",
help="Print the name of each file with annotations.")
g.add_argument("-w", "--wrap", dest="wrap_column", metavar="COLS", type=int,
Expand Down
9 changes: 6 additions & 3 deletions pdfannots/printer/markdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,14 @@ def __init__(
print_filename: bool = False, # Whether to print file names
group_highlights_by_color: bool = False, # Whether to group highlights by color
remove_hyphens: bool = True, # Whether to remove hyphens across a line break
use_page_labels: bool = True, # Whether to use page labels
wrap_column: typ.Optional[int] = None, # Column at which output is word-wrapped
**kwargs: typ.Any # Other args, ignored
) -> None:
self.print_filename = print_filename
self.group_highlights_by_color = group_highlights_by_color
self.remove_hyphens = remove_hyphens
self.use_page_labels = use_page_labels
self.wrap_column = wrap_column
self.condense = condense

Expand Down Expand Up @@ -139,10 +141,11 @@ def print_file(
@staticmethod
def format_pos(
pos: Pos,
document: Document
document: Document,
use_page_label: bool
) -> str:

result = str(pos.page).title()
result = pos.page.pretty_name(use_label=use_page_label).title()

o = document.nearest_outline(pos)
if o:
Expand Down Expand Up @@ -229,7 +232,7 @@ def format_annot(

# compute the formatted position (and extra bit if needed) as a label
assert annot.pos is not None
label = self.format_pos(annot.pos, document) + \
label = self.format_pos(annot.pos, document, self.use_page_labels) + \
(" " + extra if extra else "") + ":"

# If we have short (few words) text with a short or no comment, and the
Expand Down
5 changes: 4 additions & 1 deletion pdfannots/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ def __repr__(self) -> str:
return '<Page #%d>' % self.pageno # zero-based page index

def __str__(self) -> str:
if self.label:
return self.pretty_name()

def pretty_name(self, use_label=True) -> str:
if self.label and use_label:
return 'page %s' % self.label
else:
# + 1 for 1-based page numbers in normal program output (error messages, etc.)
Expand Down

0 comments on commit 7203f7f

Please sign in to comment.