From 1927c8741319c73af8454aba1aa2c715b822b8b1 Mon Sep 17 00:00:00 2001 From: George Gevoian Date: Mon, 30 Sep 2024 12:34:35 -0400 Subject: [PATCH] (core) Treat URLs in Markdown cells as absolute Summary: The previous behavior didn't match HyperLink cells. Test Plan: Browser test. Reviewers: jarek Reviewed By: jarek Subscribers: jarek Differential Revision: https://phab.getgrist.com/D4358 --- app/client/models/gristUrlState.ts | 6 +++--- app/client/ui/MarkdownCellRenderer.ts | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/app/client/models/gristUrlState.ts b/app/client/models/gristUrlState.ts index 1d9fa247..4c5c3b15 100644 --- a/app/client/models/gristUrlState.ts +++ b/app/client/models/gristUrlState.ts @@ -224,7 +224,7 @@ export class UrlStateImpl { /** * Given value like `foo bar baz`, constructs URL by checking if `baz` is a valid URL and, - * if not, prepending `http://`. + * if not, prepending `https://`. */ export function constructUrl(value: CellValue): string { if (typeof value !== 'string') { @@ -235,8 +235,8 @@ export function constructUrl(value: CellValue): string { // Try to construct a valid URL return (new URL(url)).toString(); } catch (e) { - // Not a valid URL, so try to prefix it with http - return 'http://' + url; + // Not a valid URL, so try to prefix it with https + return 'https://' + url; } } diff --git a/app/client/ui/MarkdownCellRenderer.ts b/app/client/ui/MarkdownCellRenderer.ts index 036572ff..4151a65b 100644 --- a/app/client/ui/MarkdownCellRenderer.ts +++ b/app/client/ui/MarkdownCellRenderer.ts @@ -1,10 +1,11 @@ +import {constructUrl} from 'app/client/models/gristUrlState'; import {gristIconLink} from 'app/client/ui2018/links'; import escape from 'lodash/escape'; import {marked} from 'marked'; export const renderer = new marked.Renderer(); -renderer.link = ({href, text}) => gristIconLink(href, text).outerHTML; +renderer.link = ({href, text}) => gristIconLink(constructUrl(href), text).outerHTML; // Disable Markdown features that we aren't ready to support yet. renderer.hr = ({raw}) => raw;