Revisiting --tidy option

I would like to revisit the option to tidy HTML output. I feel this is “needed” because with any theme beyond essentially putting all the HTML elements in a distinct base template you can not efficiently get a correct indentation of elements, especially once your theme becomes more complex. I put “needed” in quotes because Hugo has got along quite well without this feature, but as it works towards the big 1.0 milestone I think it makes sense to include it. Especially since it has already implemented --minify which should act as its counterpart, and is theoretically as important considering that it could have been post-processed as well.

I have found some temporary workarounds, like just using DevTools to view the source or post-processing the content using tidy:

http://www.html-tidy.org/

However, DevTools is way different from viewing source by requiring much more interaction and copying content. Post-processing loses benefits from running hugo --server like rendering to memory. Another temporary solution I haven’t tried yet is using tmpfs, but I still prefer developing locally using hugo --server to get pretty logs and more.

An alternative would to be to add more ways to control indentation/whitepspace, like the functions Helm adds , but even then it would be incredibly complex and you will still encounter issues that requires significant thought into how to properly indent and manage whitespace, while potentially losing access to indentation of template logic.

When developing themes and HTML, there really is no supplement in the browser for Ctrl+U or right-click + “View page source”, and few things as close to an OCD developer’s heart as having correct indentation of all the elements and not having excessive whitespace.

I’d be happy to just see this implemented as a C library in Go using hugo-extended. I’m not the expert Go developer like some of you, so I doubt I’d be able to implement this myself and submit a PR or I probably would have. However, it may be something that can be done relatively easily using existing modules/libraries for the experienced developer. Here are some resources that may help:

3 Likes

I agree. I would like to make the source code of the pages I’m producing as correct and easy to read as possible. In addition, it would be nice to exempt minification of the HTML code from the --minify argument.

I do understand however that these requests might not be on the top of the list of features to priorities, and I can live with how it works today. These features would be nice, is all :slight_smile:

2 Likes

This topic was automatically closed after 3 days. New replies are no longer allowed.