Reputation: 141
I want to "beautify" a string from within a program I am developing with running it through TidyHTML. I was wondering if it is possible to pass to tidy just the string, or does it have to be a file?
It would save me from having to store the string to a file, tidy it, delete the file, and then put it inside the new file that I want to save :)
I was thinking of something like:
$ tidy '<html>.....</html>'
Upvotes: 1
Views: 313
Reputation: 4213
You certainly can. For example:
$ tidy --indent yes < <(printf "%s\n" "<p>asdf</p>")
line 1 column 1 - Warning: missing <!DOCTYPE> declaration
line 1 column 1 - Warning: inserting implicit <body>
line 1 column 1 - Warning: inserting missing 'title' element
Info: Document content looks like HTML5
Tidy found 3 warnings and 0 errors!
<!DOCTYPE html>
<html>
<head>
<meta name="generator" content=
"HTML Tidy for HTML5 for Mac OS X version 5.4.0">
<title></title>
</head>
<body>
<p>
asdf
</p>
</body>
</html>
Upvotes: 1
Reputation: 9288
If you only need to do this once, you can use HTML Tidy Online or Dirty Markup to clean up your string.
Otherwise, according to the tidy man, you should be able to pass in your string from standard input.
If no input file is specified, Tidy reads the standard input. If no output file is specified, Tidy writes the tidied markup to the standard output. If no error file is specified, Tidy writes messages to the standard error. For command line options that expect a numerical argument, a default is assumed if no meaningful value can be found.
Upvotes: 1