Skip to content

Commit f32bdd2

Browse files
committed
fix: render code-wrapped anchors as clickable
1 parent c729003 commit f32bdd2

3 files changed

Lines changed: 49 additions & 16 deletions

File tree

docs/v1/affinity_api_docs.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -379,11 +379,11 @@ Use the common use cases below to learn how Affinity API endpoints work.
379379
> - To reduce API calls, create any initial backfills with the REST API then use [Webhooks](#webhooks) to keep data synced. You may want to schedule occasional syncs via the REST API to fixed any inconsistencies
380380
> - Your instance may contain multiple fields with the same name (e.g. Last Funding Date). To confirm the field ID, manually make an edit to the field in question and inspect the request payload for the bulk request. The field ID will be listed as `entityAttributeId` ![](https://api-docs.affinity.co/images/request-payload-1136ff0a.png)
381381
> - The ID for a list, person, organization and opportunity can be found via the URL in the CRM. For a list `affinity.affinity.co/lists/[list_id]` and for a company profile `affinity.affinity.co/companies/[company_id]`
382-
> - For large lists, use `page_size` and `page_token` parameters in the `[GET /lists/list_id}/list-entries](#get-all-list-entries)` endpoint to improve performance
382+
> - For large lists, use `page_size` and `page_token` parameters in the [`GET /lists/list_id}/list-entries`](#get-all-list-entries) endpoint to improve performance
383383
384384
## Getting Field Values for All List Entries on a List
385385

386-
1. Query `[GET /lists](#get-all-lists)` to get all lists and filter results by list name to get the appropriate list ID
386+
1. Query [`GET /lists`](#get-all-lists) to get all lists and filter results by list name to get the appropriate list ID
387387

388388
```
389389
GET /lists Response:
@@ -400,7 +400,7 @@ GET /lists Response:
400400
]
401401
```
402402

403-
2. Query `[GET /lists/12058/list-entries](#get-all-list-entries)` to get all list entries. Store the `entity_id` associated with each list entry ID
403+
2. Query [`GET /lists/12058/list-entries`](#get-all-list-entries) to get all list entries. Store the `entity_id` associated with each list entry ID
404404

405405
```
406406
GET /lists/{list_id}/list-entries Response:
@@ -421,7 +421,7 @@ GET /lists/{list_id}/list-entries Response:
421421
]
422422
```
423423

424-
3. For each list entry, query `[GET /field-values](#get-field-values)` with the `entity_id` from the previous step. Make sure you are passing `entity_id` through the appropriate parameter (e.g person_id)
424+
3. For each list entry, query [`GET /field-values`](#get-field-values) with the `entity_id` from the previous step. Make sure you are passing `entity_id` through the appropriate parameter (e.g person_id)
425425

426426
```
427427
GET /field-values Response:
@@ -470,7 +470,7 @@ GET /fields Response:
470470

471471
## Getting Field Value Changes for Status Fields
472472

473-
1. Query `[GET /lists](#get-all-lists)` and filter results to get the appropriate list ID
473+
1. Query [`GET /lists`](#get-all-lists) and filter results to get the appropriate list ID
474474

475475
```
476476
GET /lists Response:
@@ -513,7 +513,7 @@ GET /fields Response:
513513
]
514514
```
515515

516-
3. Query `[GET /field-values-changes](#field-value-changes)` passing in the `id` from Step 2
516+
3. Query [`GET /field-values-changes`](#field-value-changes) passing in the `id` from Step 2
517517

518518
```
519519
GET /field-values-changes Response:
@@ -559,7 +559,7 @@ GET /field-values-changes Response:
559559
]
560560
```
561561

562-
4. Filter results of `[GET /field-values-changes](#field-value-changes)` (e.g.: If you only want status field changes for a specific organization in your list, search by the `list_entry_id`).
562+
4. Filter results of [`GET /field-values-changes`](#field-value-changes) (e.g.: If you only want status field changes for a specific organization in your list, search by the `list_entry_id`).
563563

564564
```
565565
GET /field-values-changes Response:
@@ -607,7 +607,7 @@ GET /field-values-changes Response:
607607

608608
## Getting the Strongest Relationship Strength Connection to an Organization on a List
609609

610-
1. Query `[GET /lists](#get-all-lists)` to get all lists and filter results to get the appropriate list ID
610+
1. Query [`GET /lists`](#get-all-lists) to get all lists and filter results to get the appropriate list ID
611611

612612
```
613613
GET /lists Response:
@@ -624,7 +624,7 @@ GET /lists Response:
624624
]
625625
```
626626

627-
2. Query `[GET /lists/12058/list-entries](#get-all-list-entries)` to get all list entries. Store the `entity_id` associated with each list entry ID
627+
2. Query [`GET /lists/12058/list-entries`](#get-all-list-entries) to get all list entries. Store the `entity_id` associated with each list entry ID
628628

629629
```
630630
GET /lists/{list_id}/list-entries Response:
@@ -651,7 +651,7 @@ GET /lists/{list_id}/list-entries Response:
651651
]
652652
```
653653

654-
3. For each list entry, query `[GET /organizations/{organization_id}](#get-a-specific-organization)` to get all list people associated with the organization. Store the `person_ids` associated with each organization
654+
3. For each list entry, query [`GET /organizations/{organization_id}`](#get-a-specific-organization) to get all list people associated with the organization. Store the `person_ids` associated with each organization
655655

656656
```
657657
GET /organizations/7133202 Response:
@@ -677,7 +677,7 @@ GET /organizations/7133202 Response:
677677
}
678678
```
679679

680-
4. For each person ID from Step 3, query `[GET /relationships-strengths](#get-relationship-strength)` passing in the person ID. Once all person IDs have been looped through, filter for the highest `strength`
680+
4. For each person ID from Step 3, query [`GET /relationships-strengths`](#get-relationship-strength) passing in the person ID. Once all person IDs have been looped through, filter for the highest `strength`
681681

682682
```
683683
GET /relationships-strengths Response:
@@ -1172,7 +1172,7 @@ Creates a new list entry in the list with the supplied list id.
11721172

11731173
#### Notes
11741174

1175-
> - Opportunities cannot be created using this endpoint. Instead use the `[POST /opportunities](#create-a-new-opportunity)` endpoint.
1175+
> - Opportunities cannot be created using this endpoint. Instead use the [`POST /opportunities`](#create-a-new-opportunity) endpoint.
11761176
> - Person and company lists can contain the same entity multiple times. Depending on your use case, before you add an entry, you may want to verify whether or not it exists in the list already.
11771177
11781178
#### Returns
@@ -1228,9 +1228,9 @@ By default, Affinity provides all teams with a few default global fields: For pe
12281228

12291229
#### Notes
12301230

1231-
> - Global field IDs for persons are returned from `[GET /persons/fields](#get-global-person-fields)`
1232-
> - Global field IDs for organizations are returned from `[GET /organizations/fields](#get-global-organizations-fields)`
1233-
> - List-specific field IDs are also returned from `[GET /lists/{list_id}](#get-a-specific-list)`
1231+
> - Global field IDs for persons are returned from [`GET /persons/fields`](#get-global-person-fields)
1232+
> - Global field IDs for organizations are returned from [`GET /organizations/fields`](#get-global-organizations-fields)
1233+
> - List-specific field IDs are also returned from [`GET /lists/{list_id}`](#get-a-specific-list)
12341234
12351235
## The Field Resource
12361236

@@ -1630,7 +1630,7 @@ An array of all the field values associated with the supplied `person`, `organiz
16301630

16311631
> - Exactly one of `person_id`, `organization_id`, `opportunity_id`, or `list_entry_id` must be specified to the endpoint.
16321632
> - If a `person_id`, `organization_id`, or `opportunity_id` is specified, the endpoint returns all field values tied to these entities - including those that are associated with all list entries that exist for the given person or organization. Opportunities can only have one list entry.
1633-
> - Smart fields cannot be retrieved using the field values endpoint. Smart field values can be retrieved using the `with_interaction_dates` parameter on the `[GET /persons/{person_id}](#get-a-specific-person)` or `[GET /organizations/{organization_id}](#get-a-specific-organization)` endpoints. The people associated with smart fields can be retrieved using the `with_interaction_persons` on the `[GET /persons/{person_id}](#get-a-specific-person)` or `[GET /organizations/{organization_id}](#get-a-specific-organization)` endpoints.
1633+
> - Smart fields cannot be retrieved using the field values endpoint. Smart field values can be retrieved using the `with_interaction_dates` parameter on the [`GET /persons/{person_id}`](#get-a-specific-person) or [`GET /organizations/{organization_id}`](#get-a-specific-organization) endpoints. The people associated with smart fields can be retrieved using the `with_interaction_persons` on the [`GET /persons/{person_id}`](#get-a-specific-person) or [`GET /organizations/{organization_id}`](#get-a-specific-organization) endpoints.
16341634
> - Field values endpoint does return Crunchbase fields, but with `null` values.
16351635
16361636
## Create a New Field Value

tests/test_documentation_updates.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,21 @@ def test_affinity_parser_extracts_text_and_code_samples() -> None:
101101
assert parser.code_samples
102102
assert parser.code_samples[0].language == "bash"
103103
assert parser.code_samples[0].section == "Introduction"
104+
105+
106+
def test_code_wrapped_anchor_becomes_clickable() -> None:
107+
html = dedent(
108+
"""
109+
<html>
110+
<body>
111+
<h2 id="get-thing">Heading</h2>
112+
<div class="content">
113+
<p><code><a href="#get-thing">GET /thing</a></code></p>
114+
</div>
115+
</body>
116+
</html>
117+
"""
118+
)
119+
parser = sync.AffinityV1Parser(html)
120+
markdown = parser.build_markdown()
121+
assert "[`GET /thing`](#get-thing)" in markdown

tools/v1_sync_pipeline/sync_v1_docs.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,21 @@ def render_inline(self, node) -> str: # noqa: ANN001
319319
name = node.name
320320
text = self.render_inline_children(node)
321321
if name == "code":
322+
anchor_child = next(
323+
(child for child in node.children if isinstance(child, Tag) and child.name == "a"),
324+
None,
325+
)
326+
if anchor_child and anchor_child.parent is node:
327+
href = anchor_child.get("href")
328+
label = normalize_text(anchor_child.get_text())
329+
if href:
330+
if "@" in href and not href.lower().startswith(("mailto:", "http://", "https://", "#")):
331+
href = f"mailto:{href}"
332+
if href.startswith("#"):
333+
target = href[1:]
334+
if target not in self.anchor_ids and target in BROKEN_ANCHOR_MAP:
335+
href = f"#{BROKEN_ANCHOR_MAP[target]}"
336+
return f"[`{label}`]({href})" if href else f"`{label}`"
322337
return f"`{text}`"
323338
if name in {"strong", "b"}:
324339
return f"**{text}**"

0 commit comments

Comments
 (0)