Skip to content

Commit 4cd4417

Browse files
authored
Add support for description lists (<dl>, <dt> and <dd>) (#2098)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description <!-- Please include a summary of the change. Please also include relevant motivation and context. List any dependencies that are required for this change. --> This PR adds support for `<dl>`, `<dt>`, and `<dd>` HTML tags in messages. <img width="417" height="208" alt="Rendered message containing a description list." src="https://github.com/user-attachments/assets/da6cfeb9-00a3-44ac-989d-37014f640fb7" /> As with the tables PR, this PR does not add support for editing the description list. > [!Warning] > > The Matrix spec seems to recommend not supporting description lists: https://spec.matrix.org/v1.19/client-server-api/#mroommessage-msgtypes > > I don't see any risk or harm in implementing them anyway, as they have no way of being a vector for cyberattacks. (Should a MSC be submitted to add them?) Fixes #2050. #### Type of change - [ ] Bug fix (non-breaking change which fixes an issue) - [x] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [x] I have made corresponding changes to the documentation - [x] My changes generate no new warnings ### AI disclosure: - [x] Created without the usage of AI - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You MUST prove you understand what the code in this PR does. You MUST explain what modifications you have made in order to ensure that the result is compatible with THE LICENSE By deleting this section or comment, in code or in body, the PR should be rejected and closed. -->
2 parents c7a9092 + 6baf963 commit 4cd4417

5 files changed

Lines changed: 55 additions & 0 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: minor
3+
---
4+
5+
# Add support for description lists

‎src/app/plugins/markdown/allowedHtmlTags.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ export const MARKDOWN_ALLOWED_HTML_TAGS = new Set([
55
'blockquote',
66
'br',
77
'code',
8+
'dd',
89
'del',
910
'details',
1011
'div',
12+
'dl',
13+
'dt',
1114
'em',
1215
'h1',
1316
'h2',

‎src/app/plugins/react-custom-html-parser.tsx‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,28 @@ export const getReactCustomHtmlParser = (
792792
);
793793
}
794794

795+
if (name === 'dl') {
796+
return (
797+
<dl {...props} className={css.DescriptionList}>
798+
{renderChildren()}
799+
</dl>
800+
);
801+
}
802+
if (name === 'dt') {
803+
return (
804+
<dt {...props} className={css.DescriptionTerm}>
805+
{renderChildren()}
806+
</dt>
807+
);
808+
}
809+
if (name === 'dd') {
810+
return (
811+
<dd {...props} className={css.DescriptionDetails}>
812+
{renderChildren()}
813+
</dd>
814+
);
815+
}
816+
795817
if (name === 'code') {
796818
if (parent && 'name' in parent && parent.name === 'pre') {
797819
const codeContent = renderChildren();

‎src/app/styles/CustomHtml.css.ts‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,25 @@ export const Td = style([
338338
minWidth: toRem(100),
339339
},
340340
]);
341+
342+
export const DescriptionList = style([
343+
DefaultReset,
344+
{
345+
display: 'flex',
346+
flexDirection: 'column',
347+
},
348+
]);
349+
350+
export const DescriptionTerm = style([
351+
DefaultReset,
352+
{
353+
fontWeight: 'bolder',
354+
},
355+
]);
356+
357+
export const DescriptionDetails = style([
358+
DefaultReset,
359+
{
360+
marginInlineStart: config.space.S700,
361+
},
362+
]);

‎src/app/utils/sanitize.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ const permittedHtmlTags = [
4343
'img',
4444
'details',
4545
'summary',
46+
'dl',
47+
'dt',
48+
'dd',
4649
] as const;
4750

4851
const permittedTagToAttributes = {

0 commit comments

Comments
 (0)