Skip to content

Commit e622ab1

Browse files
feat: subtext
1 parent f701474 commit e622ab1

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

src/markdown/render/elements/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,15 @@ export const Heading = styled.withConfig({
4848
},
4949
});
5050

51+
export const Subtext = styled.withConfig({
52+
displayName: "md-subtext",
53+
componentId: commonComponentId,
54+
})("small", {
55+
color: theme.colors.textMuted,
56+
fontSize: theme.fontSizes.s,
57+
display: "block",
58+
});
59+
5160
export const QuoteContainer = styled.withConfig({
5261
displayName: "md-quote-container",
5362
componentId: commonComponentId,

src/markdown/render/index.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ function createRules(rule: { [key: string]: any }) {
7272
);
7373
},
7474
},
75+
subtext: {
76+
order: defaultRules.heading.order,
77+
match(source, state) {
78+
const prevCaptureStr =
79+
state.prevCapture === null ? "" : state.prevCapture[0];
80+
const isStartOfLineCapture = /(?:^|\n)( *)$/.exec(prevCaptureStr);
81+
82+
if (isStartOfLineCapture) {
83+
source = isStartOfLineCapture[1] + source;
84+
return /^ *-#([^\n]+?)(?:\n|$)/.exec(source);
85+
}
86+
87+
return null;
88+
},
89+
parse: (capture) => ({ content: capture[1] }),
90+
react: (node, recurseOutput, state) => (
91+
<Styles.Subtext key={state.key}>
92+
{parse(node.content, state)}
93+
</Styles.Subtext>
94+
),
95+
},
7596
s: {
7697
order: rule.u.order,
7798
match: SimpleMarkdown.inlineRegex(/^~~([\s\S]+?)~~(?!_)/),

src/stories/Normal.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ ExtendedMarkdown.args = {
132132
id: "1042882684902453278",
133133
type: 0,
134134
content:
135-
"# :sparkles: Heading 1\n## :sparkles: Heading 2\n### :sparkles: Heading 3",
135+
"# :sparkles: Heading 1\n## :sparkles: Heading 2\n### :sparkles: Heading 3\n-# :sparkles: Subtext",
136136
channel_id: "998637045327081502",
137137
author: testUser,
138138
attachments: [],

src/stories/commonTestData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const testUser: APIUser = {
55
id: "132819036282159104",
66
username: "johnythecarrot",
77
global_name: "JohnyTheCarrot",
8-
avatar: "3a30ffeeeb354950804d77ded94162d3",
8+
avatar: "2345999621dd5a2df573c3b6fe8ce94c",
99
discriminator: "0001",
1010
public_flags: 4457220,
1111
};

0 commit comments

Comments
 (0)