Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --no-page-labels switch to ignore page labels in markdown output #82

Merged
merged 2 commits into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.format_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.format_name()

def format_name(self, use_label: bool = 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
Loading