* Fix highlights in messages (or search results) breaking links Fixes #17011 and fixes #29807, by running the linkifier that turns text into links before the highlighter that adds highlights to text. * Fix jest test * Fix tests related to emojis and pills-inside-spoilers * Remove dead code * Address review comments around sanitizeParams * Address review comment about linkify-matrix * Fix code style * Refactor if statement per review --------- Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
27 lines
822 B
TypeScript
27 lines
822 B
TypeScript
/*
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import React from "react";
|
|
import { domToReact, type DOMNode } from "html-react-parser";
|
|
|
|
import { type RendererMap } from "./utils.tsx";
|
|
import Spoiler from "../components/views/elements/Spoiler.tsx";
|
|
|
|
/**
|
|
* Replaces spans with `data-mx-spoiler` with a Spoiler component.
|
|
*/
|
|
export const spoilerRenderer: RendererMap = {
|
|
span: (span, params) => {
|
|
const reason = span.attribs["data-mx-spoiler"];
|
|
if (typeof reason === "string") {
|
|
return (
|
|
<Spoiler reason={reason}>{domToReact(span.children as DOMNode[], { replace: params.replace })}</Spoiler>
|
|
);
|
|
}
|
|
},
|
|
};
|