rtts / djhtml

Django/Jinja template indenter
GNU General Public License v3.0
582 stars 32 forks source link

Multi-line tag attribute values #53

Closed neruson closed 2 years ago

neruson commented 2 years ago

Similar title to #50, but not quite the same thing.

If I have a long attribute value that spans multiple lines, such as the d attribute of an SVG path, djhtml currently formats it like this:

<svg width="325" height="325" xmlns="http://www.w3.org/2000/svg">
    <path
        d="M 80 80
        A 45 45, 0, 0, 0, 125 125
        L 125 80 Z"
        fill="green"
    />
</svg>

Personally, this feels unexpected, and I would expect one of the three following behaviors. (I've arranged them starting with what feels most intuitive to me.)

  1. Because it's part of a string value and not HTML, the original file's whitespace is preserved.

  2. The beginning of each line of the string is aligned.

    <svg width="325" height="325" xmlns="http://www.w3.org/2000/svg">
        <path
            d="M 80 80
               A 45 45, 0, 0, 0, 125 125
               L 125 80 Z"
            fill="green"
        />
    </svg>
  3. Each line after the first is indented one level.

    <svg width="325" height="325" xmlns="http://www.w3.org/2000/svg">
        <path
            d="M 80 80
                A 45 45, 0, 0, 0, 125 125
                L 125 80 Z"
            fill="green"
        />
    </svg>

What do you think?

JaapJoris commented 2 years ago

I think option 3 makes the most sense. I've created a PR for it. Would you be willing to give it a quick review?

neruson commented 2 years ago

Fantastic! The code looks good to me, thank you so much for the improvement!