Talesoft / tale-jade

A complete and fully-functional implementation of the Jade template language for PHP
http://jade.talesoft.codes
MIT License
88 stars 10 forks source link

pre-tag compiles with indentation causing extra spaces to appear #124

Closed SnijderC closed 7 years ago

SnijderC commented 7 years ago

Assuming tale-jade is in pretty printing mode, it seems the way the compiler works is to unwind the node hierarchy, adding extra the set indentation type for every level in the hierarchy. This doesn't work when compiling pre tags because any indentation added to the content of the pre tag will be interpreted by the browsers instead of ignored. So when we do this:

$my_var= "foobar"
div
    div
        div
            pre=$my_var

It is rendered as:

<?php $my_var = "foobar"?>
<div>
  <div>
    <div>
      <pre>
        <?=htmlentities(isset($my_var) ? $my_var : '', \ENT_QUOTES, 'UTF-8')?>
      </pre>
    </div>
  </div>
</div>

Note that with pre this renders as a pre with 8 spaces prepended and 7 spaces appended.

        foobar       

A link to the sandbox site for reference: http://sandbox.jade.talesoft.codes/id-58209a041c37e.html

Expected result: when <pre> is compiled indentation is not added.

TorbenKoehn commented 7 years ago

Interesting, thanks for that find. I think I can fix that pretty quickly, the pre-tag just needs to render inline all the time.

TorbenKoehn commented 7 years ago

You may pull *@dev and test it :)

I implemented a new option called force_inlined_tags (Default value is ['pre', 'code'])

Having an element force inline will disable pretty-printing for it and all of its children automatically, so you can even use HTML inside pre without breaking it.

Notice this works only in HTML and XHTML mode, in XML-mode pre and code will be normal elements and indented as any other one.

Please give me a short feedback if this problem is fixed for you, I'll issue a release as soon as I fixed some other stuff.