I'm using node.js mailer module to send email from node server. I used template file for that but I got all spaces trimmed when the message was sent. I tried to add '\n' at the end line of the template but it doesn't work also. Here is an example of template file:
Hi {{username}},\\n
Thanks for creating an account with us
I tried \n and \n , nothing all doesn't work. Any help?
Thanks,
nodemailer supports two types of templates, i.e. text and html (or templateFn() - case of loopback).
The option text is used for email clients which don't support HTML rendering so that \n should be used in this option for a new line.
On the contrary, you should swap \n with <br> in the option html.
Hope this would help you.
It's a known behavior, mustache is made to work with HTML templates, in HTML, new lines will be contracted as one space only.
You can try doing something like {{new_line}} instead your \\n, and define new_line: "\n\xA0" in your datas. \xA0 is the non-breakable space, it can separate line if you want to make two new lines.
An other solution is to not use the template, but just get the content of the file as text with fs.readFileSync(filename) and use a regexp to replace {{xxx}} by an object content.
Related
i want to break a line and used \n but its not working. creating Lambda function.
callback(buildFulfilmentResult('Fulfilled',"Thanks, for using our services " +item.Name+ " Your Flight status is Confirmed \n Arrival city: " +item.Arrival_city));
how to do then?
we need more information about how the text is being displayed to give you a really good answer.
Handling line breaks is the responsibility of the entity handling the display, and so, what you need to send depends greatly on how the text is being displayed.
For example, if your chat bot is for the web, you might be able to get it to display line breaks by sending <br> instead of \n, since that is the line break code for HTML.
That said -- accepting and displaying raw HTML from your back end could represent a serious security risk.
If I was designing a this whole thing, I would use \n to represent the line break in NodeJS, and on the web where I displayed the text, I would
take apart the string (string.split("\n")),
create a new DOM element for each part of the string,
make sure these elements were display: block, and
put the text into each of those elements via the .textContent property.
This final step avoids making the browser parse HTML, mitigating that security risk.
I have this NodeJS application, that uses Jade as template language. On one particular page, one text block is retrieved from the server, which reads the text from database.
The problem is, the returned text might contain line-breaks and links, and an operator might change this text at any time. How do I make these elements display correctly?
Most answers suggest using a new line:
p
| this is the start of the para
a(href='http://example.com') a link
| and this is the rest of the paragraph
But I cannot do this, since I cannot know when the a element appears. I've solved how to get newline correct, by this trick:
p
each l in line.description.split(/\n/)
= l
br
But I cannot seem to solve how to get links to render correctly. Does anyone know?
Edit:
I am open to any kind of format for links in the database, whatever would solve the issue. For example, say database contains the following text:
Hello!
We would like you to visit [a("http://www.google.com")Google]
Then we would like that to output text that looks like this:
Hello!
We would like you to visit Google
Looks like what you're looking for is unescaped string interpolation. The link does not work in the output because Pug automatically escapes it. Wrap the content you want to insert with !{} and it should stop breaking links. (Disclaimer: Make sure you don't leave user input unescaped - this only is a viable option if you know for sure the content of your DB does not have unwanted HTML/JS code in it.)
See this CodePen for illustration.
With this approach, you would need to use standard HTML tags (<a>) in your DB text. If you don't want that, you could have a look at Pug filters such as markdown-it (you will still need to un-escape the compilation output of that filter).
I am trying to replace the strings in my template
To do this ive done the following:
section = helper.Section("%course_name%", "Tekst");
mail.addSection(section);
section = helper.Section("%user%", "Textforasubstitutiontagofsection2");
mail.addSection(section);
However when i recieve the mail the strings are not replace and stand as the above picture
Can anyone tell me what im doing wrong?
You want to be using substitutions rather than sections in this case. section tags are meant to encapsulate groups of substitution tags. Docs for more info.
I am looking to use Blockly to allow non-techie users to specify test scripts.
One part of it will require a File Selector, however, I can't see that Blockly has one. Does it?
Actually, I can't find a complete list of standard blocks. Does anyone have a URL?
If there is no standard Blockly File Selector, (how) can I access the Windows File Selector? (and how, in general, can I execute DOS commands?)
As far as I know, I think that you cannot get a File Selector from Blockly but maybe this post is useful for you in which a man creates a custom Block for this purpose.
Also, I could not find a list with only the names of all the standard blocks but I saw that on the playground of Blockly you can see all the standard blocks that Google provides to you. If you want to see the code of all of them you can see it on Blockly GitHub.
I suppose that if Blockly does not have a File Selector it will not also has access to the Windows File Selector but maybe you can create a custom Block for that purpose via Javascript (I do not know what programming language are you using for). This link can help with Javascript Windows File Selector.
I expect it will be useful for you!
You can override the showEditor_ function on a blockly input - this works quite well with FieldTextInput. See https://youtu.be/eYHo0VeSLCI for an example of an 'intercepted' click opening a jquery mobile dialog, that then fills in the text value. The text value is then retrieved by the javascript generator to load the selected file at 'runtime'.
I've pasted below some cut down code:
Show a standard text input
let fileInput = new Blockly.FieldTextInput('** CHOOSE A FILE **')
Then you can attach a click handler which would show your file selector - so the standard browser file selector may do...
fileInput.showEditor_=(()=>alert("Intercepted"))
You'll need to replace the alert with your file selector code. Your code will also need to set the value of the text input - with something like this:
let block = Blockly.mainWorkspace.getBlockById(block_id)
block.setFieldValue(filename, widget_id)
Where widget_id identifies the text input and block_id the actual containing block.
I've got a form with Tinymce editor so any user can format it's text to look good.
If he writes any malicious script in the form, it is automatically escaped. But if the user cheats and posts the form using something like Postman, he can submit unescaped scripts (like iframes).
How do I validate the Tinymce input? If I use the validator plugin with the "escape" function, it removes all formatting. I tried to use some Google Caja plugins for node to sanitize the input but it's not removing any malicious code, like iframes. Any help?
I've found a pretty good Node.js module to sanitize html input.
It's called Sanitize-html and it does exactly what I want, removes dangerous html tags from the input string and you can add/remove specific tags