Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Linkify mxc:// URLs as links to your media repo #11213

Merged
merged 1 commit into from
Jul 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/linkify-matrix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import * as linkifyjs from "linkifyjs";
import { EventListeners, Opts, registerCustomProtocol, registerPlugin } from "linkifyjs";
import linkifyElement from "linkify-element";
import linkifyString from "linkify-string";
import { User } from "matrix-js-sdk/src/matrix";
import { getHttpUriForMxc, User } from "matrix-js-sdk/src/matrix";

import {
parsePermalink,
Expand Down Expand Up @@ -185,6 +185,11 @@ export const options: Opts = {

formatHref: function (href: string, type: Type | string): string {
switch (type) {
case "url":
if (href.startsWith("mxc://") && MatrixClientPeg.get()) {
return getHttpUriForMxc(MatrixClientPeg.get()!.baseUrl, href);
}
// fallthrough
case Type.RoomAlias:
case Type.UserId:
default: {
Expand Down Expand Up @@ -244,6 +249,8 @@ registerPlugin(Type.UserId, ({ scanner, parser }) => {

registerCustomProtocol("matrix", true);

registerCustomProtocol("mxc", false);

export const linkify = linkifyjs;
export const _linkifyElement = linkifyElement;
export const _linkifyString = linkifyString;
Loading