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

Commit cac2a91

Browse files
committed
Allow extended HTML when showing topic with slash command
1 parent 172d87e commit cac2a91

File tree

3 files changed

+69
-5
lines changed

3 files changed

+69
-5
lines changed

res/css/_common.scss

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,70 @@ legend {
304304
overflow-y: auto;
305305
}
306306

307-
.mx_Dialog strong {
308-
font-weight: $font-semi-bold;
307+
.mx_Dialog .markdown-body {
308+
font-family: inherit !important;
309+
white-space: normal !important;
310+
line-height: inherit !important;
311+
color: inherit; // inherit the colour from the dark or light theme by default (but not for code blocks)
312+
font-size: $font-14px;
313+
314+
pre,
315+
code {
316+
font-family: $monospace-font-family !important;
317+
background-color: $codeblock-background-color;
318+
}
319+
320+
// this selector wrongly applies to code blocks too but we will unset it in the next one
321+
code {
322+
white-space: pre-wrap; // don't collapse spaces in inline code blocks
323+
}
324+
325+
pre code {
326+
white-space: pre; // we want code blocks to be scrollable and not wrap
327+
328+
>* {
329+
display: inline;
330+
}
331+
}
332+
333+
pre {
334+
// have to use overlay rather than auto otherwise Linux and Windows
335+
// Chrome gets very confused about vertical spacing:
336+
// https://github.com/vector-im/vector-web/issues/754
337+
overflow-x: overlay;
338+
overflow-y: visible;
339+
340+
&::-webkit-scrollbar-corner {
341+
background: transparent;
342+
}
343+
}
344+
}
345+
346+
.mx_Dialog .markdown-body h1,
347+
.mx_Dialog .markdown-body h2,
348+
.mx_Dialog .markdown-body h3,
349+
.mx_Dialog .markdown-body h4,
350+
.mx_Dialog .markdown-body h5,
351+
.mx_Dialog .markdown-body h6 {
352+
font-family: inherit !important;
353+
color: inherit;
354+
}
355+
356+
/* Make h1 and h2 the same size as h3. */
357+
.mx_Dialog .markdown-body h1,
358+
.mx_Dialog .markdown-body h2 {
359+
font-size: 1.5em;
360+
border-bottom: none !important; // override GFM
361+
}
362+
363+
.mx_Dialog .markdown-body a {
364+
color: $accent-alt;
365+
}
366+
367+
.mx_Dialog .markdown-body blockquote {
368+
border-left: 2px solid $blockquote-bar-color;
369+
border-radius: 2px;
370+
padding: 0 10px;
309371
}
310372

311373
.mx_Dialog_fixedWidth {

src/HtmlUtils.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,9 +618,10 @@ export function bodyToHtml(content: IContent, highlights: string[], opts: IOpts
618618
* @param topic plain text topic
619619
* @param htmlTopic optional html topic
620620
* @param ref React ref to attach to any React components returned
621+
* @param allowExtendedHtml whether to allow extended HTML tags such as headings and lists
621622
* @return The HTML-ified node.
622623
*/
623-
export function topicToHtml(topic: string, htmlTopic?: string, ref?: React.Ref<HTMLSpanElement>): ReactNode {
624+
export function topicToHtml(topic: string, htmlTopic?: string, ref?: React.Ref<HTMLSpanElement>, allowExtendedHtml: boolean = false): ReactNode {
624625
if (!SettingsStore.getValue("feature_html_topic")) {
625626
htmlTopic = null;
626627
}
@@ -633,7 +634,7 @@ export function topicToHtml(topic: string, htmlTopic?: string, ref?: React.Ref<H
633634
topicHasEmoji = mightContainEmoji(isFormattedTopic ? htmlTopic : topic);
634635

635636
if (isFormattedTopic) {
636-
safeTopic = sanitizeHtml(htmlTopic, topicSanitizeHtmlParams);
637+
safeTopic = sanitizeHtml(htmlTopic, allowExtendedHtml ? sanitizeHtmlParams : topicSanitizeHtmlParams);
637638
if (topicHasEmoji) {
638639
safeTopic = formatEmojis(safeTopic, true).join('');
639640
}

src/SlashCommands.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,12 +480,13 @@ export const Commands = [
480480
: { text: _t('This room has no topic.') };
481481

482482
const ref = e => e && linkifyElement(e);
483-
const body = topicToHtml(topic.text, topic.html, ref);
483+
const body = topicToHtml(topic.text, topic.html, ref, true);
484484

485485
Modal.createTrackedDialog('Slash Commands', 'Topic', InfoDialog, {
486486
title: room.name,
487487
description: <div ref={ref}>{ body }</div>,
488488
hasCloseButton: true,
489+
className: "markdown-body",
489490
});
490491
return success();
491492
},

0 commit comments

Comments
 (0)