Skip to content

Commit ef98d1e

Browse files
author
Vikas Agarwal
committed
Converting markdown to html before sending to email service
1 parent 9a068a6 commit ef98d1e

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
"sequelize": "^4.21.0",
3636
"superagent": "^3.8.0",
3737
"tc-core-library-js": "appirio-tech/tc-core-library-js.git#v2.2",
38-
"winston": "^2.2.0"
38+
"winston": "^2.2.0",
39+
"remarkable": "^1.7.1"
3940
},
4041
"engines": {
4142
"node": "6.x"

src/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ function startKafkaConsumer(handlers) {
113113
name: user.firstName + ' ' + user.lastName,
114114
handle: user.handle,
115115
topicTitle: connectTopic.title || '',
116-
post: messageJSON.postContent,
116+
post: helperService.markdownToHTML(messageJSON.postContent),
117117
date: (new Date()).toISOString(),
118118
projectName: notification.contents.projectName,
119119
projectId: messageJSON.projectId,

src/services/helper.js

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
const request = require('superagent');
55
const config = require('config');
66
const _ = require('lodash');
7-
7+
const Remarkable = require('remarkable')
88

99
/**
1010
* Get users details by ids
@@ -63,7 +63,29 @@ const getTopic = (topicId, logger) => request
6363
});
6464

6565

66+
67+
/**
68+
* Convert markdown into raw draftjs state
69+
*
70+
* @param {String} markdown - markdown to convert into raw draftjs object
71+
* @param {Object} options - optional additional data
72+
*
73+
* @return {Object} ContentState
74+
**/
75+
const markdownToHTML = (markdown) => {
76+
const md = new Remarkable('full', {
77+
html: true,
78+
linkify: true,
79+
// typographer: true,
80+
})
81+
// Replace the BBCode [u][/u] to markdown '++' for underline style
82+
const _markdown = markdown.replace(new RegExp('\\[/?u\\]', 'g'), '++')
83+
return md.render(_markdown, {}) // remarkable js takes markdown and makes it an array of style objects for us to easily parse
84+
}
85+
86+
6687
module.exports = {
6788
getUsersById,
6889
getTopic,
90+
markdownToHTML,
6991
};

0 commit comments

Comments
 (0)