-
Notifications
You must be signed in to change notification settings - Fork 1.5k
GraphQLConf 2025 — allow limited HTML in session descriptions #2097
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,45 @@ | ||
import React from "react" | ||
|
||
const URL_REGEX = /https?:\/\/[^\s]+/g | ||
const LINK_REGEX = /<a\s+([^>]*href\s*=\s*[^>]*)>/gi | ||
|
||
export function formatDescription(text: string): string { | ||
// we coerce all existing anchor tags to have target="_blank" rel="noopener noreferrer" and typography-link class | ||
const result = text.replace(LINK_REGEX, (_, attributes) => { | ||
let attrs = attributes | ||
|
||
if (!attrs.includes("target=")) { | ||
attrs += ' target="_blank"' | ||
} | ||
|
||
if (!attrs.includes("rel=")) { | ||
attrs += ' rel="noopener noreferrer"' | ||
} | ||
|
||
if (!attrs.includes("class=")) { | ||
attrs += ' class="typography-link"' | ||
} else if (!attrs.includes("typography-link")) { | ||
attrs = attrs.replace( | ||
/class\s*=\s*["']([^"']*)/gi, | ||
'class="$1 typography-link', | ||
) | ||
} | ||
|
||
return `<a ${attrs}>` | ||
}) | ||
|
||
export function formatDescription(text: string): React.ReactNode { | ||
const res: React.ReactNode[] = [] | ||
// then we format plain URLs that are not already inside an anchor tag | ||
return result.replace(URL_REGEX, (url, offset) => { | ||
const beforeUrl = result.slice(0, offset) | ||
const afterUrl = result.slice(offset + url.length) | ||
|
||
let lastIndex = 0 | ||
let match: RegExpExecArray | null | ||
const lastOpenTag = beforeUrl.lastIndexOf("<") | ||
const lastCloseTag = beforeUrl.lastIndexOf(">") | ||
const nextCloseTag = afterUrl.indexOf(">") | ||
|
||
while ((match = URL_REGEX.exec(text)) !== null) { | ||
if (match.index > lastIndex) { | ||
res.push(text.slice(lastIndex, match.index)) | ||
if (lastOpenTag > lastCloseTag && nextCloseTag !== -1) { | ||
return url | ||
} | ||
|
||
res.push( | ||
<a | ||
href={match[0]} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className="typography-link" | ||
> | ||
{match[0].replace(/^https?:\/\//, "")} | ||
</a>, | ||
) | ||
|
||
lastIndex = match.index + match[0].length | ||
} | ||
|
||
if (lastIndex < text.length) { | ||
res.push(text.slice(lastIndex)) | ||
} | ||
|
||
return <>{res}</> | ||
const displayUrl = url.replace(/^https?:\/\//, "") | ||
return `<a href="${url}" target="_blank" rel="noopener noreferrer" class="typography-link">${displayUrl}</a>` | ||
}) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ import { | |
MenuItems, | ||
Transition, | ||
} from "@headlessui/react" | ||
import { stripHtml } from "string-strip-html" | ||
|
||
import { SchedSpeaker, ScheduleSession } from "@/app/conf/_api/sched-types" | ||
import { Anchor } from "@/app/conf/_design-system/anchor" | ||
|
@@ -132,10 +133,12 @@ export function ScheduleSessionCard({ | |
</span> | ||
)} | ||
<span className="mt-4 flex items-center gap-2 xl:mt-6"> | ||
<span className="typography-body-xs flex items-center gap-0.5"> | ||
<PinIcon className="size-4 text-pri-base [@container(width<240px)]:hidden" /> | ||
{session.venue} | ||
</span> | ||
{session.venue && ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The cruise doesn't have a venue. |
||
<span className="typography-body-xs flex items-center gap-0.5"> | ||
<PinIcon className="size-4 text-pri-base [@container(width<240px)]:hidden" /> | ||
{session.venue} | ||
</span> | ||
)} | ||
{blockTimeFraction < 1 && ( | ||
<span className="typography-body-xs flex items-center gap-0.5"> | ||
<ClockIcon className="size-4 text-pri-base [@container(width<240px)]:hidden" /> | ||
|
@@ -176,7 +179,7 @@ function AddToCalendarLink({ | |
title: eventTitle, | ||
start: session.event_start, | ||
end: session.event_end, | ||
description: session.description, | ||
description: stripHtml(session.description).result, | ||
location: session.venue, | ||
organizer: { | ||
name: `GraphQLConf ${new Date().getFullYear()}`, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,6 +15,7 @@ import React, { Fragment } from "react" | |
import { SessionTags } from "../../components/session-tags" | ||
import { Menu, MenuItem, MenuItems, Transition } from "@headlessui/react" | ||
import { MenuButton } from "@headlessui/react" | ||
import { stripHtml } from "string-strip-html" | ||
|
||
export interface LongSessionCardProps | ||
extends React.HTMLAttributes<HTMLDivElement> { | ||
|
@@ -172,7 +173,7 @@ function AddToCalendarLink({ | |
title: eventTitle, | ||
start: session.event_start, | ||
end: session.event_end, | ||
description: session.description, | ||
description: stripHtml(session.description).result, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As |
||
location: session.venue, | ||
organizer: { | ||
name: `GraphQLConf ${new Date().getFullYear()}`, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cruise doesn't have speakers.