httpie / cli

🥧 HTTPie CLI — modern, user-friendly command-line HTTP client for the API era. JSON support, colors, sessions, downloads, plugins & more.
https://httpie.io
BSD 3-Clause "New" or "Revised" License
33.36k stars 3.68k forks source link

Pretty Print HTML Output (with newlines and indentation)? #959

Closed ryanerwin closed 4 years ago

ryanerwin commented 4 years ago

When printing Content-type: application/json httpie formats the json with newlines and indentation making it very easy to read.

  http --body 'https://api2.nicehash.com/main/api/v2/legacy?method=stats.global.current'
{
    "method": "stats.global.current",
    "result": {
        "error": "Method not supported"
    }
}

However, when returning text/html, the output is syntax highlighted but not reformatted with newlines and indentation. For short HTML pages, reformatting would make the results a lot more easily readable.

  http --body google.com
<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>

Syntax highlighting is fantastic, but would be very easy to read like:

<HTML>
   <HEAD>
      <meta http-equiv="content-type" content="text/html;charset=utf-8">
      <TITLE>301 Moved</TITLE>
   </HEAD>
   <BODY>
      <H1>301 Moved</H1>
      The document has moved
      <A HREF="http://www.google.com/">here</A>.
   </BODY>
</HTML>
jkbrzt commented 4 years ago

@ryanerwin thanks for the suggestion. We used to have a XML/HTML formatter, but these languages are notoriously problematic in this regard, and there simply is no usable parser/formatter that we could just plug in at this point. So I’m closing this for now.

tobske commented 2 years ago

@jakubroztocil Just a very vague idea: Could you maybe use prettier from https://prettier.io/ for this? I know that is commonly used in combination with editors but in the end it is just a npm module.

BoboTiG commented 2 years ago

@tobske, HTTPie is Python-based code, it would not make sense to install the whole NodeJS suite just to have HTML formatting. We may rethink that part when we will know about a potential Python module that would solve the case.

tobske commented 2 years ago

Okay, I can understand that.

martinszeltins commented 6 months ago

I would also be interested in a formatter for html output, would make it so much easier to read.