From aaeb00e59f2b0c49827113896111c872818a87e8 Mon Sep 17 00:00:00 2001 From: Ben Armstrong Date: Mon, 11 Dec 2023 14:14:48 -0400 Subject: [PATCH] Provide pattern to match selected obs query. --- dronefly/core/parsers/url.py | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/dronefly/core/parsers/url.py b/dronefly/core/parsers/url.py index 5f40603..c9e9ea6 100644 --- a/dronefly/core/parsers/url.py +++ b/dronefly/core/parsers/url.py @@ -44,18 +44,14 @@ PAT_OBS_LINK = re.compile( r"\b(?P" + WWW_URL_PAT + r"/observations/(?P\d+))\b", re.I ) -# Match observation URL from `obs` embed generated for observations matching a -# specific taxon_id and filtered by optional place_id and/or user_id. -PAT_OBS_TAXON_LINK = re.compile( - r"\b(?P" + WWW_URL_PAT + r"/observations" - r"\?taxon_id=(?P\d+)(&place_id=(?P\d+))?(&user_id=(?P\d+))?)\b", - re.I, -) -QUERY_PAT = r"\??(?:&?[^=&]*=[^=&]*)*" -PAT_OBS_QUERY = re.compile( - r"(?P" + WWW_URL_PAT + r"/observations" + QUERY_PAT + ")" -) +QUERY_PAT = r"\??(?:&?[^\n=&]*=[^\n=&]*)*" +_OBS_QUERY_PAT = r"(?P" + WWW_URL_PAT + r"/observations" + QUERY_PAT + ")" +PAT_OBS_QUERY = re.compile(_OBS_QUERY_PAT) +# - the ">" character is markdown for block-quote, but only at the start of a +# line, so in the middle of a line we use it to indicate a selected entry +_SELECTED_OBS_LINK_PAT = r"^(?!> ).*?>.*?\[.*?\]\(" + _OBS_QUERY_PAT + r"\)" +PAT_SELECTED_OBS_LINK = re.compile(_SELECTED_OBS_LINK_PAT, re.MULTILINE) MARKDOWN_LINK = re.compile(r"\[.*?\]\((?P.*?)\)") # Match place link from any partner site.