In case you are a internet developer or dressmaker, you might in finding your self operating with numerous HTML information. Whilst those information would possibly include precious content material, they may be able to now and again be tough to learn or edit because of formatting problems. Beautifying your HTML information, or making them correctly formatted, permits them more straightforward to learn, alter and debug. Alternatively, manually beautifying numerous HTML information generally is a time-consuming activity.

tidy vs untidy html codes

Thankfully, with a little bit little bit of scripting wisdom, you’ll be able to automate the method of beautifying HTML information the usage of a Bash script for your Mac. On this article, we will be able to information you during the procedure of making a Bash script that may can help you adorn your HTML information in batches.

By means of the top of this educational, you’re going to have a fully-functional Bash script that you’ll be able to use to briefly and simply adorn more than one HTML information directly, saving you effort and time.

Right here’s how an unformatted, or untidy HTML report looks as if:

Instance Site

Welcome to our Site

About Us

Lorem ipsum dolor take a seat amet, consectetur adipiscing elit. Sed vitae ultrices mauris. Sed finibus mauris et tortor malesuada, at elementum nunc lacinia. Donec euismod elit nec arcu vulputate eleifend. Duis euismod mauris at nisl consequat, take a seat amet pretium dolor luctus. Etiam lobortis, ex vitae consectetur congue, magna odio dignissim ante, european tristique sapien turpis identification odio. Nam dignissim tellus et ligula dignissim, a sollicitudin magna posuere. Nulla facilisi. Donec et metus volutpat, feugiat quam non, dictum libero. Curabitur auctor, libero take a seat amet interdum facilisis, ante sapien eleifend turpis, at congue ex mi identification velit.

And right here’s how it could appear to be after being formatted:




  
  Instance Site
  


  

Welcome to our Site

About Us

Lorem ipsum dolor take a seat amet, consectetur adipiscing elit. Sed vitae ultrices mauris. Sed finibus mauris et tortor malesuada, at elementum nunc lacinia. Donec euismod elit nec arcu vulputate eleifend. Duis euismod mauris at nisl consequat, take a seat amet pretium dolor luctus. Etiam lobortis, ex vitae consectetur congue, magna odio dignissim ante, european tristique sapien turpis identification odio. Nam dignissim tellus et ligula dignissim, a sollicitudin magna posuere. Nulla facilisi. Donec et metus volutpat, feugiat quam non, dictum libero. Curabitur auctor, libero take a seat amet interdum facilisis, ante sapien eleifend turpis, at congue ex mi identification velit.

The next is the bash script you’re going to want.

#!/bin/bash

# Take a look at if `tidy` command-line instrument is put in
if ! command -v tidy &> /dev/null
then
    echo "Error: tidy isn't put in. Please set up tidy the usage of 'brew set up tidy' command." >&2
    go out 1
fi

# Take a look at if enter folder argument is supplied
if [ $# -eq 0 ]
then
    echo "Error: No enter folder supplied. Please supply an enter folder as an issue." >&2
    go out 1
fi

# Take a look at if enter folder exists
if [ ! -d "$1" ]
then
    echo "Error: Folder '$1' does now not exist." >&2
    go out 1
fi

# Loop thru HTML information within the enter folder and adorn them
in finding "$1" -type f -name "*.html" -print0 | whilst learn -d $'' report
do
    # Embellish HTML code and substitute the unique report
    tidy -indent -wrap 0 -quiet -m -i "$report"
executed

# Go out with good fortune standing
go out 0

Obtain beautify_html.sh

What the Bash Script Does

This script is written within the Bash scripting language and it automates the method of beautifying HTML information in bulk on a Mac.

The script assessments if the ‘tidy’ command-line instrument is put in and if an enter folder argument is supplied. If the enter folder exists, the script then loops thru all HTML information within the enter folder, and beautifies them the usage of the ‘tidy’ command-line instrument. The unique HTML information are changed with the beautified variations.

If ‘tidy’ isn’t put in or the enter folder does now not exist, the script will output an error message and go out with an error standing. If the whole lot runs effectively, the script exits with a good fortune standing.

Use This Script

This is an easy-to-follow information for the usage of the script to adorn both a unmarried HTML report or more than one information in bulk.

  1. Open a textual content editor for your Mac, corresponding to TextEdit or Elegant Textual content.
  2. Reproduction and paste the script into a brand new report.
  3. Save the report with a reputation, corresponding to “beautify_html.sh“, and ensure the report extension is “.sh“.
  4. Open the Terminal app for your Mac.
  5. Navigate to the listing the place the script report is stored the usage of the “cd” command.
  6. Sort chmod +x beautify_html.sh and press Input to make the script executable.
  7. Sort ./beautify_html.sh /trail/to/enter/folder and press Input to run the script, changing /trail/to/enter/folder with the real trail to the folder containing your HTML information.
  8. Look forward to the script to complete working. It is going to loop thru all HTML information within the enter folder and adorn them the usage of the ‘tidy‘ command-line instrument.
  9. As soon as the script has completed working, your HTML information will have to be beautified and stored as the unique information.

The submit Embellish HTML Information (in Bulk) on Mac seemed first on Hongkiat.

WordPress Website Development Source: https://www.hongkiat.com/blog/beautify-htmls-bulk-mac/

[ continue ]