some website source code is compressed and in one line. which i want in default HTML structured. Can i do with terminal? I want to do it with wget command. i use online tool textFixer. But i want to do it with terminal.
i want one line text into default HTML structure using terminal or using script.
is example of one line compressed source code.
i want to one line source code to default HTML structured.
if you are able to utilize php you could do something like
curl URL | php -r '$s = ""; while($l = fgets(STDIN)) {$s .= $l;} $x=new DOMDocument(); $x->loadHTML($s); $x->preserveWhiteSpace = false; $x->formatOutput = true; echo $x->saveHTML();'
saveHTML seems to not insert leading white spaces (for improved indentation), but saveXML does, so you can use $x->saveXML() instead.
That will most likely result in many warnings, so you might want to change it to:
curl URL | php -r 'error_reporting(E_ERROR); $s = ""; while($l = fgets(STDIN)) {$s .= $l;} $x=new DOMDocument(); $x->loadHTML($s); $x->preserveWhiteSpace = false; $x->formatOutput = true; echo $x->saveXML();'
Of course you can provide the script within your $PATH
to make it more simple
#!/usr/bin/env php
<?php
error_reporting(E_ERROR);
$input = call_user_func(function(){
$lines = [];
while ($line = fgets(STDIN)) {
$lines[] = $line;
}
return implode("\n", $lines);
});
$domDocument = new DomDocument();
$domDocument->preserveWhiteSpace = false;
$domDocument->formatOutput = true;
$domDocument->loadHTML($input);
echo $domDocument->saveXML();
And save that file for example to /usr/local/bin/phphtmltidy
and make it executeable ( sudo chmod +x /usr/local/bin/phphtmltidy
)
Then you could simply:
curl URL | phphtmltidy
Of course you could also use node as interpreter and work with a library like this one
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.