Retrieve HTML text from the MySQL database with EJS (Node.js)

1

I'm developing a news portal on Node.js where I save posts to a MySQL database. As a template engine, I use EJS.

I use the Tinymce plugin to format the text of the posts (use bold, italic and etc). Tinymce is a visual editor for robust Internet pages written entirely in JavaScript.

This plugin saves text already formatted in HTML in the database. For example:

<strong>negrito</strong> e <p>texto em paragrafo</p>

The problem is time to submit this content. I query the database and it returns with the tags, not the formatted text. I'm calling the tinymce the right way:

<script src="tinymce/tinymce.min.js"></script>
<script>tinymce.init({ selector:'textarea' });</script>

And it's saving right in the bank. But when I query to view, it looks like this:

Theview'scodeisthis:

<divclass="col-md-12">
                <div class="noticia_wrapper">
                    <span class="noticia_autor"><%= noticia[0].autor %></span>
                    <span class="noticia_titulo"><%= noticia[0].titulo %></span>
                    <span class="noticia_data"><%= moment(noticia[0].data_criacao).format('DD/MM/YYYY') %></span>
                    <br />
                    <p class="noticia_resumo">
                        <%= noticia[0].noticia %>
                    </p>                        
                </div>
            </div>

Can anyone give a light?

    
asked by anonymous 28.05.2017 / 16:29

1 answer

1

You need EJS to display this HTML without escaping it. Looking at the documentation the command for this is <%- , so you can do:

<p class="noticia_resumo">
    <%- noticia[0].noticia %>
</p> 
    
28.05.2017 / 16:45