gramps-web icon indicating copy to clipboard operation
gramps-web copied to clipboard

Automatically detect URLs and make them clickable in source publication field

Open TheMihle opened this issue 1 year ago • 5 comments

This is an extension of this feature request to other Gramps reports: https://gramps-project.org/bugs/view.php?id=13337

It would be very nice if reports that show the citations/sources/attributes would detect URLs in the most common places to have them, and made them clickable.

This could potentially be done with detecting if there is a http:// or https:// or something like that and wrap it in a link tag. Unless that causes issues I cant think of.

I think some of the most common locations you may put URLs are: Citation Volume/Page field. Source Publication field. Attributes, both on citation and sources

TheMihle avatar Jun 28 '24 21:06 TheMihle

Good idea. We already do this in notes:

https://github.com/gramps-project/gramps-web/blob/main/src/components/GrampsjsNoteContent.js#L4-L12

So, should be straightforward to generalize.

DavidMStraub avatar Jun 29 '24 06:06 DavidMStraub

Good idea. We already do this in notes:

https://github.com/gramps-project/gramps-web/blob/main/src/components/GrampsjsNoteContent.js#L4-L12

So, should be straightforward to generalize.

I did notice its already done in Notes.

If you end up doing it for Gramps Web, is it easy to include in for example Narrative Web and Dynamic Web report too? Like could it maybe just be copy pasted in to those too? I ask mostly because I am curious.

TheMihle avatar Jun 30 '24 13:06 TheMihle

I realized this is a bit trickier than anticipated.

For notes, we're injecting the anchor tags into the note HTML after rendering it. But this is only safe because note content is sanitized by the backend.

For the other elements, they may contain unsafe HTML code in principle - this is not an issue because Lit will not render it as HTML. But if would use the same approach as in notes, we would have to render the raw (unsanitized) string which could contain malitious code.

So this needs a bit more thought to implement in a safe way; either by sanitizing those elements in the backend or finding a way to use lit-html to replace the URLs.

DavidMStraub avatar Jul 05 '24 13:07 DavidMStraub

Nevermind, found a way :wink:

DavidMStraub avatar Jul 05 '24 13:07 DavidMStraub

Note complete - citation page & attribute values done, source publication missing.

DavidMStraub avatar Jul 06 '24 18:07 DavidMStraub