Listing criteria for Validator to check?

For technical support and bug reports for all editions of CSS HTML Validator, including htmlval for Linux and Mac.
jtramontana
Rank I - Novice
Posts: 13
Joined: Thu Feb 23, 2023 12:35 pm

Listing criteria for Validator to check?

Post by jtramontana »

I am a middle school computer science teacher and my 8th graders make a TON of custom websites throughout the year.
Sometimes I give them a specific list of criteria they need to meet on a page/site.
Like:
Must use <header> <nav> <main> <section> <footer> tags.
Must use hex code for background color in an external stylesheet saved in css\global.css

Is there a way to have CSS HTML Validator look for things like this and report if they are missing?
User avatar
Albert Wiersch
Site Admin
Posts: 3785
Joined: Sat Dec 11, 2004 9:23 am
Location: Near Dallas, TX

Re: Listing criteria for Validator to check?

Post by Albert Wiersch »

Hello,

Very nice to see another teaching using CSS HTML Validator!

It's easy to check if certain elements were used and to generate an error message if not. You can use a user functions file and specify the user functions file in the Validator Engine Options, Config File page. A user functions file is just a text file with some simple scripting (called TNPL) that CSS HTML Validator understands, so you could copy and paste the below into a file name "userfunctions.txt".

The below "user functions" should generate errors if certain elements are not found/used in an HTML document.

Code: Select all

function onStartTag_header() { $mystuff[toLower(CurrentTagName)]++; }
function onStartTag_nav() { $mystuff[toLower(CurrentTagName)]++; }
function onStartTag_main() { $mystuff[toLower(CurrentTagName)]++; }
function onStartTag_section() { $mystuff[toLower(CurrentTagName)]++; }
function onStartTag_footer() { $mystuff[toLower(CurrentTagName)]++; }

function onEndingValidation() {
 $e='header'; checkIfElementUsed();
 $e='nav'; checkIfElementUsed();
 $e='main'; checkIfElementUsed();
 $e='section'; checkIfElementUsed();
 $e='footer'; checkIfElementUsed();
}

function checkIfElementUsed() {
 if !isSet($mystuff[$e]) { Message(1,MSG_ERROR,'<'+$e+'> element not found'); }
}
Unfortunately it's not currently possible to check for a hex background color in a style sheet. The current scripting functions are designed primarily for HTML documents.

More information about TNPL (the scripting language) is here:
https://www.htmlvalidator.com/current/d ... l?tnpl.htm

I hope this helps! Please let me know if you have any more questions.
Albert Wiersch, CSS HTML Validator Developer • Download CSS HTML Validator FREE Trial