Skip to content

Commit 1854e59

Browse files
committed
Fix markdown link encoding by decoding URL-encoded strings from SOLR and updating README examples
1 parent b02daa9 commit 1854e59

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ vfb.get_term_info('FBbt_00003748')
101101
},
102102
{
103103
"id": "VFB_00101385",
104-
"label": "[ME%28R%29 on JRC_FlyEM_Hemibrain](VFB_00101385)",
104+
"label": "[ME(R) on JRC_FlyEM_Hemibrain](VFB_00101385)",
105105
"tags": "Nervous_system|Adult|Visual_system|Synaptic_neuropil_domain",
106-
"thumbnail": "[![ME(R) on JRC_FlyEM_Hemibrain aligned to JRC_FlyEM_Hemibrain](http://www.virtualflybrain.org/data/VFB/i/0010/1385/VFB_00101384/thumbnail.png 'ME(R) on JRC_FlyEM_Hemibrain aligned to JRC_FlyEM_Hemibrain')](VFB_00101384,VFB_00101385)"
106+
"thumbnail": "[![ME(R) on JRC_FlyEM_Hemibrain aligned to JRCFIB2018Fum](http://www.virtualflybrain.org/data/VFB/i/0010/1385/VFB_00101384/thumbnail.png 'ME(R) on JRC_FlyEM_Hemibrain aligned to JRCFIB2018Fum')](VFB_00101384,VFB_00101385)"
107107
},
108108
{
109109
"id": "VFB_00030810",

src/vfbquery/vfb_queries.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from marshmallow import ValidationError
1010
import json
1111
import numpy as np
12+
from urllib.parse import unquote
1213
from .solr_result_cache import with_solr_cache
1314

1415
# Custom JSON encoder to handle NumPy and pandas types
@@ -311,14 +312,13 @@ def __str__(self):
311312

312313
def encode_brackets(text):
313314
"""
314-
Encodes brackets in the given text.
315+
Encodes square brackets in the given text to prevent breaking markdown link syntax.
316+
Parentheses are NOT encoded as they don't break markdown syntax.
315317
316318
:param text: The text to encode.
317-
:return: The text with brackets encoded.
319+
:return: The text with square brackets encoded.
318320
"""
319-
return (text.replace('(', '%28')
320-
.replace(')', '%29')
321-
.replace('[', '%5B')
321+
return (text.replace('[', '%5B')
322322
.replace(']', '%5D'))
323323

324324
def encode_markdown_links(df, columns):
@@ -1055,12 +1055,16 @@ def _get_instances_from_solr(short_form: str, return_dataframe=True, limit: int
10551055
template_label = template_anatomy.get('label', '')
10561056
if template_anatomy.get('symbol') and len(template_anatomy.get('symbol', '')) > 0:
10571057
template_label = template_anatomy.get('symbol')
1058+
# Decode URL-encoded strings from SOLR (e.g., ME%28R%29 -> ME(R))
1059+
template_label = unquote(template_label)
10581060
template_short_form = template_anatomy.get('short_form', '')
10591061

10601062
# Prefer symbol over label for anatomy (matching Neo4j behavior)
10611063
anatomy_label = anatomy.get('label', '')
10621064
if anatomy.get('symbol') and len(anatomy.get('symbol', '')) > 0:
10631065
anatomy_label = anatomy.get('symbol')
1066+
# Decode URL-encoded strings from SOLR (e.g., ME%28R%29 -> ME(R))
1067+
anatomy_label = unquote(anatomy_label)
10641068
anatomy_short_form = anatomy.get('short_form', '')
10651069

10661070
if template_label and anatomy_label:
@@ -1077,6 +1081,8 @@ def _get_instances_from_solr(short_form: str, return_dataframe=True, limit: int
10771081
template_label = template_anatomy.get('label', '')
10781082
if template_anatomy.get('symbol') and len(template_anatomy.get('symbol', '')) > 0:
10791083
template_label = template_anatomy.get('symbol')
1084+
# Decode URL-encoded strings from SOLR (e.g., ME%28R%29 -> ME(R))
1085+
template_label = unquote(template_label)
10801086
template_short_form = template_anatomy.get('short_form', '')
10811087
if template_label and template_short_form:
10821088
template_formatted = f"[{template_label}]({template_short_form})"
@@ -1085,6 +1091,8 @@ def _get_instances_from_solr(short_form: str, return_dataframe=True, limit: int
10851091
anatomy_label = anatomy.get('label', 'Unknown')
10861092
if anatomy.get('symbol') and len(anatomy.get('symbol', '')) > 0:
10871093
anatomy_label = anatomy.get('symbol')
1094+
# Decode URL-encoded strings from SOLR (e.g., ME%28R%29 -> ME(R))
1095+
anatomy_label = unquote(anatomy_label)
10881096
anatomy_short_form = anatomy.get('short_form', '')
10891097

10901098
row = {

0 commit comments

Comments
 (0)