Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only wrap at tags #854

Closed
DustVoice opened this issue Jan 2, 2020 · 4 comments
Closed

Only wrap at tags #854

DustVoice opened this issue Jan 2, 2020 · 4 comments

Comments

@DustVoice
Copy link

DustVoice commented Jan 2, 2020

In our project, we would like to have each tag in a new line.

Currently we have the problem that tidy either puts attributes etc. on a new line:

<form action="#" th:action="@{/formular}"
th:object="${user}" method="post">
    <p><b>Persönliche Angaben</b></p>
    <div class="row">
        <div class="form-group col-md-6">
            <label for="TuId" class= "col-form-label">TU-ID</label>
            <input type="text" th:field= "*{TuId}" class="form-control" id= "TuId" placeholder="TU-ID" required="" />
            <span th:if= "${#fields.hasErrors('TuId')}" th:errors="*{TuId}" class= "text-danger"></span>
        </div>

=> tidy --indent auto --indent-spaces 4 --drop-proprietary-attributes no --drop-empty-elements no --tidy-mark no formular.html > formular2.html =>

<form action="#" th:action="@{/formular}"
th:object="${user}" method="post">
    <p><b>Persönliche Angaben</b></p>
    <div class="row">
        <div class="form-group col-md-6">
            <label for="TuId" class=
            "col-form-label">TU-ID</label>
            <input type="text" th:field=
            "*{TuId}" class="form-control" id=
            "TuId" placeholder="TU-ID"
            required="" /><span th:if=
            "${#fields.hasErrors('TuId')}"
            th:errors="*{TuId}" class=
            "text-danger"></span>
        </div>

or if I supply tidy with the --wrap 0 option, tidy mashes label, input and span onto one line:

<form action="#" th:action="@{/formular}"
th:object="${user}" method="post">
    <p><b>Persönliche Angaben</b></p>
    <div class="row">
        <div class="form-group col-md-6">
            <label for="TuId" class= "col-form-label">TU-ID</label>
            <input type="text" th:field= "*{TuId}" class="form-control" id= "TuId" placeholder="TU-ID" required="" />
            <span th:if= "${#fields.hasErrors('TuId')}" th:errors="*{TuId}" class= "text-danger"></span>
        </div>

=> tidy --indent auto --indent-spaces 4 --drop-proprietary-attributes no --drop-empty-elements no --tidy-mark no --wrap 0 formular.html > formular2.html =>

<form action="#" th:action="@{/formular}" th:object="${user}" method="post">
    <p><b>Persönliche Angaben</b></p>
    <div class="row">
        <div class="form-group col-md-6">
            <label for="TuId" class="col-form-label">TU-ID</label> <input type="text" th:field="*{TuId}" class="form-control" id="TuId" placeholder="TU-ID" required="" /> <span th:if="${#fields.hasErrors('TuId')}" th:errors="*{TuId}" class="text-danger"></span>
        </div>

We would love more of a result, like the -xml option produces:

<form action="#" th:action="@{/formular}"
th:object="${user}" method="post">
    <p><b>Persönliche Angaben</b></p>
    <div class="row">
        <div class="form-group col-md-6">
            <label for="TuId" class= "col-form-label">TU-ID</label>
            <input type="text" th:field= "*{TuId}" class="form-control" id= "TuId" placeholder="TU-ID" required="" />
            <span th:if= "${#fields.hasErrors('TuId')}" th:errors="*{TuId}" class= "text-danger"></span>
        </div>

=> tidy -xml --indent auto --indent-spaces 4 --drop-proprietary-attributes no --drop-empty-elements no --tidy-mark no --wrap 0 formular.html > formular2.html =>

<form action="#" th:action="@{/formular}" th:object="${user}" method="post">
    <p>
        <b>Persönliche Angaben</b>
    </p>
    <div class="row">
        <div class="form-group col-md-6">
            <label for="TuId" class="col-form-label">TU-ID</label>
            <input type="text" th:field="*{TuId}" class="form-control" id="TuId" placeholder="TU-ID" required="" />
            <span th:if="${#fields.hasErrors('TuId')}" th:errors="*{TuId}" class="text-danger"></span>
        </div>

but without the caveats that the -xml option has, like html validation, head and body tags indented, etc.

It would be nice, if one could tell tidy to --wrap 0 but place every tag on a new line or something.

This currently the only thing holding us back from using tidy the intended way in our production environment and we would be happy if there could be an option to achieve our wanted result.

Thanks in advance

@geoffmcl
Copy link
Contributor

@DustVoice at first glance, this looks like, potentially new Pretty Print option...

Maybe the title suggests a wrap-at-tags option, or something... but the full specification is maybe a little, or even, very, unclear...

Like maybe --wrap-at-tags yes implies -w 0, but it can't... that implies no wrap...

Or maybe it suggests, do not wrap, according to the current encountered-a-spacey-char rule(s)... only on the next tag... that is, sort of, keep all text, and/? attributes, in the same line, until an open tag encountered... assume allow close tags, on the same line... or ??? Getting lost in thought, possibilities, ...

For example, explain, show, how would you wrap-at-tags the html code <p>A <b><i><span class="c1">big</span></i></b> code <code>var i = 2;</code> thing</p>... What do you expect, especially when each of the pure text elements are expanded to long sentences... Does it mean wrap-at-all-tags, like you sort of get if you use a config of -i -w 1... if you see what I mean...

Although you have given several snippets... thanks... it would be good if you constructed a simple example... show the options you use... the output of current tidy, with its version... and then what you expect to see... may help, give ideas, speed up development...

Do not include the -xml option, as this output goes a completely separate path... or is this issue about XML?

So while this started out like a simple additional option, as I explore it, it seems much more explanation, samples, must be given... even to know where to start, and what is expected... or am I missing something, obvious... thanks...

@DustVoice
Copy link
Author

No problem I will supply you with the requested samples within the next few days.

@geoffmcl
Copy link
Contributor

geoffmcl commented Dec 2, 2020

@DustVoice as it has been nearly a year, and no clear specification has emerged, so can only close this... sorry...

To say something like Only wrap at tags is never going to be sufficient... for instance many inline tags, like <b>, <strong>, <span>, etc., etc., usually can not be wrapped without changing the documents browser rendering...

Current libTidy supports some 152 W3C tags, and of those some 79 have the CM_INLINE bit set - see tidy_15.htm, so it is also not really possible to say wrap tags without inline bit... so you can see the definition of what you want is very difficult to nail down...

And please understand, changing output specification, so called Pretty Printing, is very difficult at any time...

What one group of people like, others will complain... one wants a newline here, or there, while others will say there should not be any newline there, or here... the best tidy can do is some sort of messy compromise... never satisfying everybody at the same time...

That said, if you can come up with a clear spec, with samples, feel free to re-open, or file a new issue... thanks...

@geoffmcl geoffmcl closed this as completed Dec 2, 2020
@DustVoice
Copy link
Author

Yes sorry. Because we really needed the issue resolved rather quickly, as per request of our team leader, we had to drop tidy unfortunately. If I use tidy again and experience the same issue again, I will most certainly be able to provide you with a clear spec and reopen the issue. Until then I thank you for your time and effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants