Skip to content

Instantly share code, notes, and snippets.

@smartwatermelon
Last active October 19, 2020 23:11
Show Gist options
  • Save smartwatermelon/7f0d5e110d571cac3db667e53894b16e to your computer and use it in GitHub Desktop.
Save smartwatermelon/7f0d5e110d571cac3db667e53894b16e to your computer and use it in GitHub Desktop.
htmlValidator: @cassidoo's 2020-10-19 newsletter interview question
#!/bin/bash
function htmlValidator ()
{
if xmllint --noout --nowarning - 2> /dev/null <<< "$1"; then
echo "valid";
else
echo "not valid";
fi
}
# htmlValidator '<tag>I love coding <Component />!</tag>'
# => valid
# htmlValidator '<tag>I love coding <Component />!</ta'
# => not valid
# note: xmllint is included in macOS since at least 10.7.5, probably earlier
# source this file to add the function, e.g.
# source htmlvalidator.sh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment