Skip to content

Commit f2d9ec3

Browse files
committed
(feat) add code text formatting
1 parent f98dcd7 commit f2d9ec3

File tree

5 files changed

+80
-11
lines changed

5 files changed

+80
-11
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,23 @@ textMessages="{
199199
| Underline | `° °` | `°This text is underlined°` | <ins>This text is underlined</ins> |
200200
| Nested formatting | `* *` and `_ _` | `*This text is _extremely_ important*` | **This text is _extremely_ important** |
201201

202+
**Inline Code**
203+
204+
Example: \`This is inline code\`
205+
206+
Output: `This is inline code`
207+
208+
**Multiline Code**
209+
210+
Example: \```This is multiline code\```
211+
212+
Output:
213+
214+
```bash
215+
This is
216+
multiline code
217+
```
218+
202219
(9) `responsiveBreakpoint` can be used to collapse the rooms list on the left when then viewport size goes below the specified width.
203220

204221
(10) `singleRoom` can be used if you never want to show the rooms list on the left. You still need to pass the `rooms` prop as an array with a single element.
@@ -283,6 +300,13 @@ styles="{
283300
colorReactionCounterMe: '#0b59b3'
284301
},
285302
303+
markdown: {
304+
background: 'rgba(239, 239, 239, 0.7)',
305+
border: 'rgba(212, 212, 212, 0.9)',
306+
color: '#e01e5a',
307+
colorMulti: '#0a0a0a'
308+
},
309+
286310
room: {
287311
colorUsername: '#0a0a0a',
288312
colorMessage: '#67717a',

src/ChatWindow/FormatMessage.vue

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@
1515
'text-bold': checkType(message, 'bold'),
1616
'text-italic': checkType(message, 'italic'),
1717
'text-strike': checkType(message, 'strike'),
18-
'text-underline': checkType(message, 'underline')
18+
'text-underline': checkType(message, 'underline'),
19+
'text-inline-code':
20+
!singleLine && checkType(message, 'inline-code'),
21+
'text-multiline-code':
22+
!singleLine && checkType(message, 'multiline-code')
1923
}"
2024
:href="message.href"
2125
target="_blank"

src/styles/helper.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,23 @@
6767
.text-underline {
6868
text-decoration: underline;
6969
}
70+
71+
.text-inline-code {
72+
font-size: 12px;
73+
color: var(--chat-markdown-color);
74+
background: var(--chat-markdown-bg);
75+
border: 1px solid var(--chat-markdown-border);
76+
border-radius: 3px;
77+
padding: 2px 3px;
78+
}
79+
80+
.text-multiline-code {
81+
display: block;
82+
font-size: 12px;
83+
color: var(--chat-markdown-color-multi);
84+
background: var(--chat-markdown-bg);
85+
border: 1px solid var(--chat-markdown-border);
86+
border-radius: 3px;
87+
margin: 4px 0;
88+
padding: 7px;
89+
}

src/themes/index.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ export const defaultThemeStyles = {
7575
colorReactionCounterMe: '#0b59b3'
7676
},
7777

78+
markdown: {
79+
background: 'rgba(239, 239, 239, 0.7)',
80+
border: 'rgba(212, 212, 212, 0.9)',
81+
color: '#e01e5a',
82+
colorMulti: '#0a0a0a'
83+
},
84+
7885
room: {
7986
colorUsername: '#0a0a0a',
8087
colorMessage: '#67717a',
@@ -186,6 +193,13 @@ export const defaultThemeStyles = {
186193
colorReactionCounterMe: '#fff'
187194
},
188195

196+
markdown: {
197+
background: 'rgba(239, 239, 239, 0.7)',
198+
border: 'rgba(212, 212, 212, 0.9)',
199+
color: '#e01e5a',
200+
colorMulti: '#0a0a0a'
201+
},
202+
189203
room: {
190204
colorUsername: '#fff',
191205
colorMessage: '#6c7278',
@@ -232,6 +246,7 @@ export const cssThemeVars = ({
232246
content,
233247
dropdown,
234248
message,
249+
markdown,
235250
room,
236251
emoji,
237252
icons
@@ -306,6 +321,12 @@ export const cssThemeVars = ({
306321
message.borderStyleReactionHoverMe,
307322
'--chat-message-color-reaction-counter-me': message.colorReactionCounterMe,
308323

324+
// markdown
325+
'--chat-markdown-bg': markdown.background,
326+
'--chat-markdown-border': markdown.border,
327+
'--chat-markdown-color': markdown.color,
328+
'--chat-markdown-color-multi': markdown.colorMulti,
329+
309330
// room
310331
'--chat-room-color-username': room.colorUsername,
311332
'--chat-room-color-message': room.colorMessage,

src/utils/formatString.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ const pseudo_markdown = {
3434
end: '°',
3535
allowed_chars: '.',
3636
type: 'underline'
37+
},
38+
'```': {
39+
end: '```',
40+
allowed_chars: '(.|\n)',
41+
type: 'multiline-code'
42+
},
43+
'`': {
44+
end: '`',
45+
allowed_chars: '.',
46+
type: 'inline-code'
3747
}
38-
// '```': {
39-
// end: '```',
40-
// allowed_chars: '(.|\n)',
41-
// object: child => `<div class="multiline-code">${child}</div>`
42-
// },
43-
// '`': {
44-
// end: '`',
45-
// allowed_chars: '.',
46-
// object: child => `<div class="inline-code">${child}</div>`
47-
// }
4848
// ':': {
4949
// allowed_chars: '[a-z_]',
5050
// end: ':',

0 commit comments

Comments
 (0)