@@ -23,6 +23,25 @@ import { MatrixClientPeg } from "../MatrixClientPeg";
2323import SettingsStore from "../settings/SettingsStore" ;
2424import { Pill , PillType , pillRoomNotifLen , pillRoomNotifPos } from "../components/views/elements/Pill" ;
2525import { parsePermalink } from "./permalinks/Permalinks" ;
26+ import { PermalinkParts } from "./permalinks/PermalinkConstructor" ;
27+
28+ /**
29+ * A node here is an A element with a href attribute tag.
30+ *
31+ * It should not be pillified if the permalink parser result contains an event id.
32+ *
33+ * It should be pillified if the permalink parser returned a result and one of the following conditions match:
34+ * - Text content equals href. This is the case when sending a plain permalink in a message.
35+ * - The link does not have the "linkified" class.
36+ * Composer completions already create an A tag.
37+ * Linkify will not linkify things again. → There won't be a "linkified" class.
38+ */
39+ const shouldBePillified = ( node : Element , href : string , parts : PermalinkParts | null ) : boolean => {
40+ if ( ! parts || parts . eventId ) return ;
41+
42+ const textContent = node . textContent ;
43+ return href === textContent || ! node . classList . contains ( "linkified" ) ;
44+ } ;
2645
2746/**
2847 * Recurses depth-first through a DOM tree, converting matrix.to links
@@ -51,9 +70,8 @@ export function pillifyLinks(nodes: ArrayLike<Element>, mxEvent: MatrixEvent, pi
5170 } else if ( node . tagName === "A" && node . getAttribute ( "href" ) ) {
5271 const href = node . getAttribute ( "href" ) ! ;
5372 const parts = parsePermalink ( href ) ;
54- // If the link is a (localised) matrix.to link, replace it with a pill
55- // We don't want to pill event permalinks, so those are ignored.
56- if ( parts && ! parts . eventId ) {
73+
74+ if ( shouldBePillified ( node , href , parts ) ) {
5775 const pillContainer = document . createElement ( "span" ) ;
5876
5977 const pill = (
0 commit comments