Skip to content

Commit

Permalink
"markdown-tidy": Tweak handling of private notes.
Browse files Browse the repository at this point in the history
  • Loading branch information
damiendart committed Dec 9, 2024
1 parent 273ec44 commit 4decfd5
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions bin/markdown-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def format_markdown(
wrap_text: bool,
remove_private_notes: bool,
) -> str:
# The "- - -" thematic break is used for separating private notes to
# prevent conflicts with front matter delimiters.
if remove_private_notes:
markdown = re.split(r"^- - -", markdown, flags=re.MULTILINE)[0].strip()
else:
markdown = re.sub(r"^- - -", "", markdown, flags=re.MULTILINE)

markdown = subprocess.check_output(
[
"pandoc",
Expand Down Expand Up @@ -63,9 +70,6 @@ def format_markdown(
text=True,
)

if remove_private_notes:
markdown = markdown.split("---")[0].strip()

# Surround the URL portion of reference links with angle brackets
# to match the syntax of automatic links.
markdown = re.sub(
Expand Down Expand Up @@ -189,7 +193,7 @@ def parse_arguments(arguments: typing.List[str]) -> argparse.Namespace:
"--keep-private-notes",
action="store_true",
dest="keep_private_notes",
help='keep content after the first "---"',
help='keep content after the first "- - -"',
)

group = parser.add_mutually_exclusive_group()
Expand Down

0 comments on commit 4decfd5

Please sign in to comment.