The thing is. I keep in the database of the article. For some of them I use MarkDown. Here is a piece of the article in the editor (MarkDown markup):

enter image description here

What should be here - ```shell opens a block of code. Everything inside is wrapped around the output in the <pre class="lang-shell"> ... </pre> block. Then, after loading, the page is processed by the Highlight.js library to highlight the syntax. But the problem is that inside the pre blocks (and ONLY in them! Everything is fine in other places) the transfers are mysteriously lost. This is in the editor (simple <textarea> field):

enter image description here

There are transfers. Next, look at the page:

enter image description here

No transfers. At all. From the word "absolutely." Now we take and display the contents of $post->body not into the template, but simply through var_dump() :

enter image description here

Then we will see the following:

enter image description here

At first I thought it was an oddity template. Crawled into the cache, but there all that it does is simply translate the templating directives into PHP functions. $post->body , in particular, it outputs as follows:

enter image description here

That is, no additional filters, trim() s and other things. Just prints. But hyphenation in the code disappear. Which way to look? Thank.

PS The project is built on the Phalcon PHP Framework, the base MongoDB 3.4, PHP 7.0 PPS The Highlight.js library has nothing to do with it. The problem was even before its implementation, and when you turn off the library is saved.

    1 answer 1

    The point was that the \n symbol for HTML does not exist. Therefore, before displaying the text on the page, it was first necessary to replace the characters \n and \r with the corresponding HTML analogs:

     $post->body = str_replace( "\r", '&#13;', $post->body ); $post->body = str_replace( "\n", '&#10;', $post->body ); 

    And everything became wonderful.