From 48ae073706a501f4312a3e56f5e94e16a1183474 Mon Sep 17 00:00:00 2001 From: Melissa Zhang Date: Sat, 25 Jul 2020 15:52:35 -0700 Subject: fix link deletion --- src/client/apis/hypothesis/HypothesisApiUtils.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/client/apis/hypothesis/HypothesisApiUtils.ts b/src/client/apis/hypothesis/HypothesisApiUtils.ts index cf265479a..1158dcc11 100644 --- a/src/client/apis/hypothesis/HypothesisApiUtils.ts +++ b/src/client/apis/hypothesis/HypothesisApiUtils.ts @@ -69,14 +69,11 @@ export namespace Hypothesis { await editAnnotation(annotationId, newText); }; - /** - * Edit an annotation with ID @param annotationId to delete a hyperlink to the Dash document with URL @param linkUrl - */ export const deleteLink = async (annotationId: string, linkUrl: string) => { const annotation = await fetchAnnotation(annotationId); - const regex = new RegExp(`(\[[^[]*)\(${linkUrl.replace('/', '\/')}\)`); - const target = regex.exec(annotation.text); // use regex to extract the link to be deleted, which is written in [title](hyperlink) format - target && editAnnotation(annotationId, annotation.text.replace(target[0], '')); + const regex = new RegExp(`\\[[^\\]]*\\]\\(${linkUrl}\\)`); // finds the link (written in [title](hyperlink) format) to be deleted + const out = annotation.text.replace(regex, ""); + editAnnotation(annotationId, out); }; // Finds the most recent placeholder annotation created and returns its ID -- cgit v1.2.3-70-g09d2