Support for both htmlBody and original body

This commit is contained in:
okbel
2018-02-21 16:37:19 -03:00
parent 9cfa5b6a0f
commit bf1bae8999
11 changed files with 216 additions and 16 deletions
@@ -16,7 +16,11 @@ class Editor extends React.Component {
init({
element: this.ref,
onChange: html => onChange(html),
onChange: htmlBody => {
// We want to save the original comment body
const originalBody = this.ref.childNodes[1].innerText;
onChange(originalBody, { htmlBody });
},
actions,
classes: {
actionbar: cn(
+13 -1
View File
@@ -1 +1,13 @@
module.exports = {};
const { readFileSync } = require('fs');
const path = require('path');
const hooks = require('./server/hooks');
const resolvers = require('./server/resolvers');
module.exports = {
typeDefs: readFileSync(
path.join(__dirname, 'server/typeDefs.graphql'),
'utf8'
),
hooks,
resolvers,
};
+1
View File
@@ -7,6 +7,7 @@
"author": "The Coral Project Team <coral@mozillafoundation.org>",
"license": "Apache-2.0",
"dependencies": {
"marked": "^0.3.16",
"pell": "^0.7.0"
}
}
+13
View File
@@ -0,0 +1,13 @@
const TurndownService = require('turndown');
module.exports = {
RootMutation: {
createComment: {
async pre(_, { input }, _context, _info) {
// Saving the HTML comment as Markdown
const ts = new TurndownService();
input.body = ts.turndown(input.body);
},
},
},
};
@@ -0,0 +1,7 @@
const marked = require('marked');
module.exports = {
Comment: {
body: comment => marked(comment.body),
},
};
@@ -0,0 +1,7 @@
input CreateCommentInput {
htmlBody: String
}
type Comment {
htmlBody: String
}
+4
View File
@@ -2,6 +2,10 @@
# yarn lockfile v1
marked@^0.3.16:
version "0.3.16"
resolved "https://registry.yarnpkg.com/marked/-/marked-0.3.16.tgz#2f188b7dfcfa6540fe9940adaf0f3b791c9a5cba"
pell@^0.7.0:
version "0.7.0"
resolved "https://registry.yarnpkg.com/pell/-/pell-0.7.0.tgz#46b3fcdfa8dd7e5999f73c550a337ecc80193dcc"