Skip to content

Commit e9bbe17

Browse files
authored
Allow markdown in messages (#180)
1 parent 62854d8 commit e9bbe17

File tree

6 files changed

+32
-7
lines changed

6 files changed

+32
-7
lines changed

docs/spec.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2021,10 +2021,10 @@
20212021
"example": 25
20222022
},
20232023
"message": {
2024-
"description": "The actual message.",
2024+
"description": "The message. Markdown (excluding html) is allowed.",
20252025
"type": "string",
20262026
"x-go-name": "Message",
2027-
"example": "Backup was successfully finished."
2027+
"example": "**Backup** was successfully finished."
20282028
},
20292029
"priority": {
20302030
"description": "The priority of the message.",

model/message.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ type MessageExternal struct {
3333
// required: true
3434
// example: 5
3535
ApplicationID uint `json:"appid"`
36-
// The actual message.
36+
// The message. Markdown (excluding html) is allowed.
3737
//
3838
// required: true
39-
// example: Backup was successfully finished.
39+
// example: **Backup** was successfully finished.
4040
Message string `form:"message" query:"message" json:"message" binding:"required"`
4141
// The title of the message.
4242
//

ui/package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"react-router": "^4.3.1",
2424
"react-router-dom": "^4.3.1",
2525
"react-timeago": "^4.1.9",
26+
"remove-markdown": "^0.3.0",
2627
"typeface-roboto": "0.0.54"
2728
},
2829
"scripts": {
@@ -49,6 +50,7 @@
4950
"@types/react-dom": "^16.0.7",
5051
"@types/react-infinite": "0.0.33",
5152
"@types/react-router-dom": "^4.3.0",
53+
"@types/remove-markdown": "^0.1.1",
5254
"@types/rimraf": "^2.0.2",
5355
"get-port": "^4.0.0",
5456
"prettier": "^1.14.2",

ui/src/message/Message.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import TimeAgo from 'react-timeago';
77
import Container from '../common/Container';
88
import * as config from '../config';
99
import {StyleRulesCallback} from '@material-ui/core/styles/withStyles';
10+
import ReactMarkdown from 'react-markdown';
1011

1112
const styles: StyleRulesCallback = () => ({
1213
header: {
@@ -24,6 +25,7 @@ const styles: StyleRulesCallback = () => ({
2425
},
2526
messageContentWrapper: {
2627
width: '100%',
28+
maxWidth: 585,
2729
},
2830
image: {
2931
marginRight: 15,
@@ -33,6 +35,15 @@ const styles: StyleRulesCallback = () => ({
3335
},
3436
content: {
3537
whiteSpace: 'pre-wrap',
38+
'& p': {
39+
margin: 0,
40+
},
41+
'& a': {
42+
color: '#ff7f50',
43+
},
44+
'& pre': {
45+
overflow: 'auto',
46+
},
3647
},
3748
});
3849

@@ -81,8 +92,8 @@ class Message extends React.PureComponent<IProps & WithStyles<typeof styles>> {
8192
<Delete />
8293
</IconButton>
8394
</div>
84-
<Typography component="p" className={`${classes.content} content`}>
85-
{content}
95+
<Typography component="div" className={`${classes.content} content`}>
96+
<ReactMarkdown source={content} escapeHtml={true} />
8697
</Typography>
8798
</div>
8899
</Container>

ui/src/snack/browserNotification.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import Notify from 'notifyjs';
2+
import removeMarkdown from 'remove-markdown';
23

34
export function requestPermission() {
45
if (Notify.needsPermission && Notify.isSupported()) {
@@ -11,7 +12,7 @@ export function requestPermission() {
1112

1213
export function notifyNewMessage(msg: IMessage) {
1314
const notify = new Notify(msg.title, {
14-
body: msg.message,
15+
body: removeMarkdown(msg.message),
1516
icon: msg.image,
1617
notifyClick: closeAndFocus,
1718
notifyShow: closeAfterTimeout,

0 commit comments

Comments
 (0)