Commit f5239811 authored by Yannis Barlas's avatar Yannis Barlas

fix(email): make sure title html does not introduce line breaks

parent d7f40cc8
......@@ -218,7 +218,6 @@ if (process.env.NODE_ENV === 'development') {
},
],
comments: '<p>some comments here</p>',
dataType: 'geneExpression',
disclaimer: true,
funding: 'blah',
geneExpression: {
......
const config = require('config')
const mailer = require('@pubsweet/component-send-email')
const cheerio = require('cheerio')
const mailer = require('@pubsweet/component-send-email')
const User = require('pubsweet-server/src/models/User')
const Team = require('pubsweet-server/src/models/Team')
......@@ -20,11 +21,18 @@ const dashboardLink = `
</p>
`
const formatManuscriptTitle = str => {
const $ = cheerio.load(str)
/* eslint-disable-next-line no-param-reassign */
const formatted = $('p').each((i, item) => (item.tagName = 'span'))
return formatted
}
const getArticleUrl = articleId => `${baseUrl}/article/${articleId}`
const getArticleLink = articleId => `
<p>
<a href="${getArticleUrl(articleId)}">
View it on the Micropublication platform.
View it on the microPublication platform.
</a>
</p>
`
......@@ -137,7 +145,7 @@ const sendEmail = data => {
const emailData = {
from: config.get('mailer.from'),
html: `<p>${content}</p>`,
subject: `Micropublication | ${subject}`,
subject: `microPublication | ${subject}`,
text: content,
to,
}
......@@ -163,7 +171,8 @@ const articleAccepted = async context => {
const content = `
<p>
Your article "${manuscript.title}" has been accepted by the editors!
Your article "${formatManuscriptTitle(manuscript.title)}"
has been accepted by the editors!
</p>
<h4>
Decision letter:
......@@ -192,7 +201,8 @@ const articleRejected = async context => {
const content = `
<p>
Your article "${manuscript.title}" has been rejected by the editors.
Your article "${formatManuscriptTitle(manuscript.title)}"
has been rejected by the editors.
</p>
<h4>
Decision letter:
......@@ -222,7 +232,7 @@ const articleRevision = async context => {
const content = `
<p>
The editors have requested revisions for your article
"${manuscript.title}".
"${formatManuscriptTitle(manuscript.title)}".
</p>
<h4>
Decision letter:
......@@ -265,7 +275,7 @@ const chat = async context => {
const content = `
<p>
User ${user.username} sent the following chat message for article
"${manuscript.title}".
"${formatManuscriptTitle(manuscript.title)}":
</p>
<p>
${message.content}
......@@ -295,7 +305,7 @@ const currentlyWith = async context => {
const content = `
<p>
Your attention was requested by user ${currentUser.username} on article
"${manuscript.title}".
"${formatManuscriptTitle(manuscript.title)}".
</p>
${getArticleLink(manuscript.id)}
`
......@@ -318,10 +328,14 @@ const dataTypeSelected = async context => {
const content = `
<p>
The Micropublication editors assigned your article "${manuscript.title}"
The microPublication editors assigned your article
"${formatManuscriptTitle(manuscript.title)}"
the "${toRegularText(manuscript.dataType)}" data type.
</p>
<p>You can now complete your full submission!</p>
<p>
You can now complete your full submission! Scroll down to the bottom of
the submission and fill out the relevant fields.
</p>
${getArticleLink(manuscript.id)}
`
......@@ -346,7 +360,7 @@ const fullSubmission = async context => {
const content = `
<p>
User ${currentUser.username} just finished the full submission for
article "${manuscript.title}".
article "${formatManuscriptTitle(manuscript.title)}".
</p>
${getArticleLink(manuscript.id)}
`
......@@ -371,7 +385,9 @@ const initialSubmission = async context => {
const content = `
<p>There has been a new submission!</p>
<p>
User ${currentUser.username} just submitted article "${manuscript.title}".
User ${
currentUser.username
} just submitted article "${formatManuscriptTitle(manuscript.title)}".
</p>
${getArticleLink(manuscript.id)}
`
......@@ -405,7 +421,7 @@ const reviewerInvitationResponse = async context => {
const content = `
<p>
User ${currentUser.username} has ${invitationText} your invitation
to review article "${manuscript.title}"
to review article "${formatManuscriptTitle(manuscript.title)}"
</p>
${getArticleLink(manuscript.id)}
`
......@@ -428,7 +444,9 @@ const reviewerInvited = async context => {
const content = `
<p>
You have been invited to review article "${manuscript.title}"!
You have been invited to review article "${formatManuscriptTitle(
manuscript.title,
)}"!
</p>
${dashboardLink}
`
......@@ -454,7 +472,7 @@ const reviewSubmitted = async context => {
const content = `
<p>
User ${reviewer.username} just submitted a review for article
"${manuscript.title}"!
"${formatManuscriptTitle(manuscript.title)}"!
</p>
${getArticleLink(manuscript.id)}
`
......@@ -479,7 +497,7 @@ const scienceOfficerApprovalStatusChange = async context => {
const content = `
<p>
The science officer has changed the approval status of article
${manuscript.title}.
${formatManuscriptTitle(manuscript.title)}.
</p>
${getArticleLink(manuscript.id)}
`
......@@ -504,9 +522,9 @@ const sendExternalReviewerInvitation = async context => {
const content = `
<p>
You have been invited to review article "${
manuscript.title
}" on the Micropublication submission platform.
You have been invited to review article "${formatManuscriptTitle(
manuscript.title,
)}" on the microPublication submission platform.
</p>
<p>
Please <a href="${baseUrl}/signup">sign up</a>
......
......@@ -2683,6 +2683,7 @@ chardet@^0.4.0:
cheerio@^1.0.0-rc.2:
version "1.0.0-rc.2"
resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-1.0.0-rc.2.tgz#4b9f53a81b27e4d5dac31c0ffd0cfa03cc6830db"
integrity sha1-S59TqBsn5NXawxwP/Qz6A8xoMNs=
dependencies:
css-select "~1.2.0"
dom-serializer "~0.1.0"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment