Skip to content

Commit

Permalink
Allow markdown in messages (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmattheis committed Mar 30, 2019
1 parent 62854d8 commit e9bbe17
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 7 deletions.
4 changes: 2 additions & 2 deletions docs/spec.json
Original file line number Diff line number Diff line change
Expand Up @@ -2021,10 +2021,10 @@
"example": 25
},
"message": {
"description": "The actual message.",
"description": "The message. Markdown (excluding html) is allowed.",
"type": "string",
"x-go-name": "Message",
"example": "Backup was successfully finished."
"example": "**Backup** was successfully finished."
},
"priority": {
"description": "The priority of the message.",
Expand Down
4 changes: 2 additions & 2 deletions model/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ type MessageExternal struct {
// required: true
// example: 5
ApplicationID uint `json:"appid"`
// The actual message.
// The message. Markdown (excluding html) is allowed.
//
// required: true
// example: Backup was successfully finished.
// example: **Backup** was successfully finished.
Message string `form:"message" query:"message" json:"message" binding:"required"`
// The title of the message.
//
Expand Down
11 changes: 11 additions & 0 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-timeago": "^4.1.9",
"remove-markdown": "^0.3.0",
"typeface-roboto": "0.0.54"
},
"scripts": {
Expand All @@ -49,6 +50,7 @@
"@types/react-dom": "^16.0.7",
"@types/react-infinite": "0.0.33",
"@types/react-router-dom": "^4.3.0",
"@types/remove-markdown": "^0.1.1",
"@types/rimraf": "^2.0.2",
"get-port": "^4.0.0",
"prettier": "^1.14.2",
Expand Down
15 changes: 13 additions & 2 deletions ui/src/message/Message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import TimeAgo from 'react-timeago';
import Container from '../common/Container';
import * as config from '../config';
import {StyleRulesCallback} from '@material-ui/core/styles/withStyles';
import ReactMarkdown from 'react-markdown';

const styles: StyleRulesCallback = () => ({
header: {
Expand All @@ -24,6 +25,7 @@ const styles: StyleRulesCallback = () => ({
},
messageContentWrapper: {
width: '100%',
maxWidth: 585,
},
image: {
marginRight: 15,
Expand All @@ -33,6 +35,15 @@ const styles: StyleRulesCallback = () => ({
},
content: {
whiteSpace: 'pre-wrap',
'& p': {
margin: 0,
},
'& a': {
color: '#ff7f50',
},
'& pre': {
overflow: 'auto',
},
},
});

Expand Down Expand Up @@ -81,8 +92,8 @@ class Message extends React.PureComponent<IProps & WithStyles<typeof styles>> {
<Delete />
</IconButton>
</div>
<Typography component="p" className={`${classes.content} content`}>
{content}
<Typography component="div" className={`${classes.content} content`}>
<ReactMarkdown source={content} escapeHtml={true} />
</Typography>
</div>
</Container>
Expand Down
3 changes: 2 additions & 1 deletion ui/src/snack/browserNotification.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Notify from 'notifyjs';
import removeMarkdown from 'remove-markdown';

export function requestPermission() {
if (Notify.needsPermission && Notify.isSupported()) {
Expand All @@ -11,7 +12,7 @@ export function requestPermission() {

export function notifyNewMessage(msg: IMessage) {
const notify = new Notify(msg.title, {
body: msg.message,
body: removeMarkdown(msg.message),
icon: msg.image,
notifyClick: closeAndFocus,
notifyShow: closeAfterTimeout,
Expand Down

0 comments on commit e9bbe17

Please sign in to comment.