Skip to content

Commit

Permalink
fix: make link substitution for aips > 999 work (#52)
Browse files Browse the repository at this point in the history
* fix: make link substitution for aips > 999 work

Fixes: #47

* fix: update comment for hyperlink substitution
  • Loading branch information
shwoodard authored May 12, 2022
1 parent e7546ca commit 5ffa2f2
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 5 additions & 4 deletions aip_site/models/aip.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,16 @@ def content(self) -> md.MarkdownDocument:
)

# Hotlink AIP references.
# We only hotlink the generally-applicable ones for now until we have
# a prefix system implemented.
# We can (now) link to AIPs outside of general, those that are numbered
# > 999, because the site redirects from 4221 to client-libraries/4221
# now, for example.
answer = re.sub(
r'\b(?<!\[)AIP-([\d]{1,3})\b', # AIP-###, but not after a `[`.
r'\b(?<!\[)AIP-(\d+)\b', # AIP-###, but not after a `[`.
fr'[AIP-\1]({self.site.relative_uri}/\1)',
answer,
)
answer = re.sub(
r'(?<=\])\[aip-([\d]{1,3})\]', # [aip-###], after a `]`.
r'(?<=\])\[aip-(\d+)\]', # [aip-###], after a `]`.
fr'({self.site.relative_uri}/\1)',
answer,
)
Expand Down
2 changes: 2 additions & 0 deletions tests/test_data/aip/general/0031.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,5 @@ author deeply.
- For more from Victor Hugo, read AIP-62.
- For Dickens instead, consult [AIP-43](./0043.md).
- More Dickens is available in [A Tale of Two Cities][aip-59].
- If you like poetry, AIP-1609 or [Orpheus][aip-1622] might be for you.

2 changes: 2 additions & 0 deletions tests/test_models_aip.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def test_content_hotlinking(site):
hunchback = site.aips[31]
les_mis = site.aips[62]
assert '[AIP-62](/62)' in hunchback.content
assert '[Orpheus](/1622)' in hunchback.content
assert '[AIP-1609](/1609)' in hunchback.content
assert '[A Tale of Two Cities](/59)' in hunchback.content
assert '[AIP-31](/31)' in les_mis.content
assert '[[AIP-31](/31)](/31)' not in les_mis.content
Expand Down

0 comments on commit 5ffa2f2

Please sign in to comment.