markdownvtigerparsedown

Strange behaviour when rendering vtiger text fields with markdown: Wrong indent of item lists


I experienced a very strange behaviour: I wrote a custom function for PDF-Maker that sends the text of a custom field through Markdown (I used Parsedown). (The idea is that we can easily do some simple formatting in text fields in vtiger where we don't have any advanced editor.)

I have the following list in the text field:

* a
* b
* c

The output of Parsedown causes all items from the second line on to be rendered as a nested list:

<ul>
<li>a
<ul>
<li>b</li>
<li>c</li>
</ul></li>
</ul>

Of course, if I paste the text direktly to parsedown, it gets rendered correctly:

<ul>
<li>a</li>
<li>b</li>
<li>c</li>
</ul>

What happens here? Any hint ...?


Solution

  • After hours of trying different things I noticed that the text that is passed to the custom function has an additional space character at the beginning of each line from the second line on ... the text that parsedown receives is in fact:

    * a
     * b
     * c
    

    So I added

    $text = preg_replace("/^\s/m", "", $text);
    

    and everything works fine ......