django-froala-editor icon indicating copy to clipboard operation
django-froala-editor copied to clipboard

Disabling auto-formatting on `code` view

Open duoi opened this issue 6 years ago • 0 comments

Hello,

Froala doesn't seem to handle django/jinga template tags too well. For example, it automagically wraps for loops (i.e {% for i in y %}) in paragraph tags.

This is frustrating but somewhat manageable, however the real issue comes in when dealing with tables. If I have a for loop that sits outside of a tag inside a table, it would take it and append it into single string paragraph at the top.

For example,

<table>
<tr>
{% for user in users %}
<td>{{ user.first_name }}</td>
{% endfor %}
</tr>
</table>

Would become

<p>{% for user in users %} {% endfor %}</p>
<table>
<tr>
<td>{{ user.first_name }}</td>
</tr>
</table>

Even if I'm entering it view the "code" view. This of course makes it unusable for this purpose.

Is there a way to disable formatting, at least when entering things via the "code" view? Or a way to make {{ foo }} and {% bar %} exempt from auto-formatting?

Forgive my horrible regex, but I'd like to spare the following three inputs from autoformatting:

  1. ({{)(.*)(}}) (i.e {{ foo }})
  2. ({% for)(.*)(endfor %}) (i.e {% for i in x %} foo {% endfor %})
  3. ({% if)(.*)(endif %}) (i.e {% if bar %} foo {% else %} foobar {% endif %})

duoi avatar Apr 23 '19 01:04 duoi