ruricolist / spinneret

Common Lisp HTML5 generator
MIT License
369 stars 26 forks source link

inline elements are not indented #10

Closed mfiano closed 7 years ago

mfiano commented 7 years ago

Elements in *inline-elements*, such as <a> are not indented at all, and always start at column 0. This looks wrong and makes debugging difficult without client-side tools to reformat the html.

PuercoPop commented 7 years ago

The issue seems happen after the body tag:

(spinneret:with-html (:html (:head)
                            (:body (:a "hai"))))
<html lang=en>
 <head>
  <meta charset=UTF-8>
 </head>
 <body>
<a>hai</a>
 </body> 
</html>

While the following works ok

(spinneret:with-html (:ul (:li
                           (:a "hai"))))
<ul>
 <li><a>hai</a>
</ul>
mfiano commented 7 years ago

Yes, it seems to occur with non-*paragraph-elements* the most. However, the following happens with <li> and <a> (but does not occur with <div> and <a>), which I still think is wrong. It happens when the inline line is too long:

(spinneret:with-html
  (:div
   (:div
    (:div
     (:ul
      (:li
       (:a.class1.class2.class3.class4.class5
        :href "hello hello hello")))))))

#| =>
<div>
 <div>
  <div>
   <ul>
    <li><a class="class1 class2 class3 class4 class5" href="hello hello hello">
     </a>
   </ul>
  </div>
 </div>
</div>
|#

Note how the closing </A> is on a new line and does not match up with any opening tag.

ruricolist commented 7 years ago

Inline elements not indenting is definitely a bug.

I don't understand, though, what the problem is in the second example (where the inline line is too long). The line has to wrap somewhere. How do you think that should look?

mfiano commented 7 years ago

@ruricolist It doesn't have to wrap, and infact it already does not wrap with non-inline tags.

ruricolist commented 7 years ago

I believe I've fixed the problem with elements not getting indented. @mfiano, would you check if it fixes your other problem?

mfiano commented 7 years ago

@ruricolist The changes fix the bug of not indenting, but does nothing for the other problem. On top of this, I just discovered another similar but more serious problem:

(spinneret:with-html (:div "hello" (:a :href "#") "there"))

#|
<div>
hello<a href=#></a>  there
</div>
|#

It is very bad that 2 space characters are inserted before "there". I have tried to track down why this is occuring and throwing off my whole html format to no avail.

ruricolist commented 7 years ago

I've pushed a fix for the extraneous space bug.

mfiano commented 7 years ago

@ruricolist The extraneous space fix still has some issues that are deeper than I thought.

For example, if an inline tag is wrapped to a new line such as:

<a href=/some/url>
title</a>

That is actually rendered as the equivalent of:

&nbsp;title

instead of

title

This is why I suggested optionally turning off wrapping in #11 A newline (with 0 or more spaces to follow) is rendered as &nbsp;

In addition, now there is no way to add explicit spaces:

CL-USER> (spinneret:with-html-string (:div "hi" (:span " there")))
"<div>
hi<span>there</span>
</div>"
mfiano commented 7 years ago

I will not be providing anymore feedback with the pretty printing, as rendering with *print-pretty* as NIL does not have these issues and will allow me to continue my project. Feel free to close this or leave it open as a reminder that pretty printing still needs some work.

ruricolist commented 7 years ago

Thanks for the testing. And good luck with your project.

ruricolist commented 7 years ago

At this point, the pretty-printer has been almost completely rewritten, so I'm closing this issue as no longer relevant.