### Install htmltest via shell script Source: https://github.com/wjdp/htmltest/blob/master/README.md Use the godownloader script to install htmltest. The system-wide installation places the binary in /usr/local/bin, while the local installation places it in the current directory's bin folder. ```bash curl https://htmltest.wjdp.uk | sudo bash -s -- -b /usr/local/bin ``` ```bash curl https://htmltest.wjdp.uk | bash ``` -------------------------------- ### Installation Methods for htmltest Source: https://context7.com/wjdp/htmltest/llms.txt Details various methods for installing htmltest, including system-wide installation via curl script, direct download to the current directory, Homebrew package manager, and Go installation. ```bash # System-wide install on Linux/macOS curl https://htmltest.wjdp.uk | sudo bash -s -- -b /usr/local/bin # Install to current directory (good for CI) curl https://htmltest.wjdp.uk | bash # Homebrew (macOS/Linux) brew install htmltest # Go install go install github.com/wjdp/htmltest@latest ``` -------------------------------- ### Docker Usage for htmltest Source: https://context7.com/wjdp/htmltest/llms.txt Illustrates how to run htmltest using Docker, including basic usage, testing specific directories, passing additional arguments, and using a custom configuration file. This method avoids local installation. ```bash # Basic usage - mount current directory and test docker run -v $(pwd):/test --rm wjdp/htmltest # Test specific directory docker run -v $(pwd):/test --rm wjdp/htmltest public # With additional arguments docker run -v $(pwd):/test --rm wjdp/htmltest -l 3 -s # Use custom config file docker run -v $(pwd):/test --rm wjdp/htmltest -c .htmltest.yml ``` -------------------------------- ### CI/CD Integration Source: https://context7.com/wjdp/htmltest/llms.txt Examples for integrating htmltest into GitHub Actions and GitLab CI. ```yaml # GitHub Actions workflow name: HTML Test on: [push, pull_request] jobs: htmltest: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Install htmltest run: curl https://htmltest.wjdp.uk | bash - name: Build site run: hugo - name: Test HTML run: bin/htmltest - name: Cache htmltest results uses: actions/cache@v3 with: path: tmp/.htmltest key: htmltest-${{ github.ref }} ``` ```yaml # GitLab CI configuration htmltest: image: golang:latest script: - curl https://htmltest.wjdp.uk | bash - hugo - bin/htmltest cache: paths: - tmp/.htmltest/ ``` -------------------------------- ### YAML Configuration for htmltest Source: https://context7.com/wjdp/htmltest/llms.txt Provides an example of a `.htmltest.yml` configuration file, showcasing options for directory paths, file extensions, enabling/disabling checks, ignoring URLs and directories, error handling, performance tuning, logging, and HTTP headers. ```yaml # Basic configuration for a Jekyll site DirectoryPath: "_site" DirectoryIndex: "index.html" FileExtension: ".html" # Enable/disable specific checks CheckDoctype: true CheckAnchors: true CheckLinks: true CheckImages: true CheckScripts: true CheckMeta: true CheckGeneric: true CheckExternal: true CheckInternal: true CheckInternalHash: true CheckMailto: true CheckTel: true CheckFavicon: false CheckMetaRefresh: true # Enforce HTTPS for all external links EnforceHTTPS: true EnforceHTML5: false # Ignore patterns (regex supported) IgnoreURLs: - "example.com" - "^/misc/js/script.js$" - "linkedin.com" # Often blocks automated requests IgnoreDirs: - "lib" - "vendor" - "node_modules" # Error handling IgnoreInternalEmptyHash: false IgnoreEmptyHref: false IgnoreCanonicalBrokenLinks: true IgnoreExternalBrokenLinks: false IgnoreAltMissing: false IgnoreAltEmpty: false IgnoreDirectoryMissingTrailingSlash: false IgnoreSSLVerify: false # Performance tuning TestFilesConcurrently: false DocumentConcurrencyLimit: 128 HTTPConcurrencyLimit: 16 ExternalTimeout: 15 # Caching CacheExpires: "336h" # Two weeks OutputDir: "tmp/.htmltest" OutputCacheFile: "refcache.json" OutputLogFile: "htmltest.log" # Logging LogLevel: 2 # 0=debug, 1=info, 2=warning, 3=error LogSort: "document" # or "seq" for sequential # HTTP headers for external requests HTTPHeaders: Range: "bytes=0-0" Accept: "*/*" # Query string handling StripQueryString: true StripQueryExcludes: - "fonts.googleapis.com" ``` -------------------------------- ### Example htmltest YAML Configuration Source: https://github.com/wjdp/htmltest/blob/master/README.md This snippet demonstrates a typical configuration for htmltest using YAML format. It specifies the directory path for site files, enforces HTTPS, defines URLs and directories to ignore, and sets a cache expiration duration. ```yaml DirectoryPath: "_site" EnforceHTTPS: true IgnoreURLs: - "example.com" - "^/misc/js/script.js$" IgnoreDirs: - "lib" CacheExpires: "6h" ``` -------------------------------- ### Run htmltest with Docker Source: https://github.com/wjdp/htmltest/blob/master/README.md Execute htmltest within a Docker container by mounting the local directory containing HTML files. This allows for isolated testing without installing dependencies locally. ```docker docker run -v $(pwd):/test --rm wjdp/htmltest docker run -v $(pwd):/test --rm wjdp/htmltest -l 3 -s ``` -------------------------------- ### Dynamically Insert Google CSE Script with JavaScript Source: https://github.com/wjdp/htmltest/blob/master/htmltest/fixtures/html/ignore_namespace.html This snippet asynchronously loads the Google Custom Search Engine (CSE) script. It constructs the script's source URL dynamically based on the page's protocol (HTTP or HTTPS) and a provided CSE cx identifier. The script is then inserted into the document's head. ```javascript (function() { var cx = 'foo'; var gcse = document.createElement('script'); gcse.type = 'text/javascript'; gcse.async = true; gcse.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//cse.google.com/cse.js?cx=' + cx; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(gcse, s); })(); ``` -------------------------------- ### Configure htmltest for Hugo Projects Source: https://github.com/wjdp/htmltest/wiki/Using-With-Hugo This configuration snippet sets the directory path for htmltest to scan within a Hugo project. It assumes the Hugo site has been built and the output is located in the 'public' directory. This is a common setup for static site generators. ```yaml DirectoryPath: public ``` -------------------------------- ### CLI Usage for htmltest Source: https://context7.com/wjdp/htmltest/llms.txt Demonstrates various command-line interface commands for htmltest, including testing directories, single files, using custom configurations, skipping checks, setting log levels, and showing the version. ```bash # Test a directory of HTML files htmltest _site # Test a single HTML file htmltest _site/index.html # Test with custom config file htmltest -c myconfig.yml # Skip external link checks for faster testing htmltest -s _site # Set log level (0=debug, 1=info, 2=warning, 3=error) htmltest -l 0 _site # Show version htmltest -v ``` -------------------------------- ### Integrate htmltest as a Go library Source: https://context7.com/wjdp/htmltest/llms.txt Demonstrates how to import and use htmltest within a Go application. It covers initializing options, executing the test suite, and retrieving error counts. ```go package main import ( "fmt" "github.com/wjdp/htmltest/htmltest" ) func main() { options := map[string]interface{}{ "DirectoryPath": "_site", "CheckExternal": true, "EnforceHTTPS": true, "LogLevel": 2, } hT, err := htmltest.Test(options) if err != nil { fmt.Printf("Error: %v\n", err) return } errorCount := hT.CountErrors() docCount := hT.CountDocuments() fmt.Printf("Tested %d documents\n", docCount) if errorCount > 0 { fmt.Printf("Found %d errors\n", errorCount) } else { fmt.Println("All checks passed!") } } ``` -------------------------------- ### Hugo Integration Configuration for htmltest Source: https://context7.com/wjdp/htmltest/llms.txt Presents a sample `.htmltest.yml` configuration for Hugo projects, setting the output directory, enforcing HTTPS, enabling favicon checks, and ignoring specific URLs. ```yaml # .htmltest.yml for Hugo DirectoryPath: public EnforceHTTPS: true CheckFavicon: true IgnoreURLs: - "localhost:1313" ``` -------------------------------- ### Google Analytics Initialization (JavaScript) Source: https://github.com/wjdp/htmltest/blob/master/htmltest/fixtures/html/normal_looking_page.html Initializes Google Analytics by creating a script tag and sending a pageview event. This code is typically found in the header of a webpage to track user interactions. ```javascript (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); ga('create', 'UA-3769691-28', 'auto'); ga('send', 'pageview'); ``` -------------------------------- ### Jekyll Integration Configuration for htmltest Source: https://context7.com/wjdp/htmltest/llms.txt Shows a sample `.htmltest.yml` configuration tailored for Jekyll projects, specifying the output directory, enforcing HTTPS, and ignoring specific URLs and directories. ```yaml # .htmltest.yml for Jekyll DirectoryPath: _site EnforceHTTPS: true IgnoreURLs: - "localhost" IgnoreDirs: - "assets/vendor" ``` -------------------------------- ### htmltest CLI Usage Source: https://github.com/wjdp/htmltest/blob/master/README.md The command-line interface for htmltest allows users to specify paths, configuration files, logging levels, and skip external link checks. ```text htmltest [options] [] htmltest -v --version htmltest -h --help ``` -------------------------------- ### Configure logging and output behavior Source: https://context7.com/wjdp/htmltest/llms.txt Settings for controlling log verbosity and output formatting. Includes YAML configuration for log levels and shell commands for execution and output customization. ```yaml LogLevel: 2 LogSort: "document" EnableLog: true OutputLogFile: "htmltest.log" ``` ```bash # Disable colored output NO_COLOR=1 htmltest _site ``` -------------------------------- ### Anchor Link Initialization (JavaScript) Source: https://github.com/wjdp/htmltest/blob/master/htmltest/fixtures/html/normal_looking_page.html Initializes anchor links for elements with the class '.org-table h4'. This is likely used to create scrollable sections or sticky headers within the page content. ```javascript anchors.add('.org-table h4'); ``` -------------------------------- ### Execute htmltest via CLI Source: https://github.com/wjdp/htmltest/wiki/Using-With-Jekyll Command-line instruction to run htmltest against the default Jekyll output directory. This command validates the generated HTML files within the _site folder. ```bash htmltest _site ``` -------------------------------- ### Validate Links and Anchors Source: https://context7.com/wjdp/htmltest/llms.txt Demonstrates how to define various link types in HTML and configure link checking behavior in htmltest. ```html About Us Contact Jump to Section GitHub Email Us Call Us ``` ```yaml # Configure link checking behavior CheckAnchors: true CheckExternal: true CheckInternal: true CheckInternalHash: true CheckMailto: true CheckTel: true EnforceHTTPS: true ExternalTimeout: 15 IgnoreCanonicalBrokenLinks: true ``` -------------------------------- ### Validate Images and Alt Text Source: https://context7.com/wjdp/htmltest/llms.txt Shows how to structure images for accessibility and configure image validation rules. ```html Company Logo External photo Site Map Home ``` ```yaml # Configure image checking CheckImages: true IgnoreAltMissing: false IgnoreAltEmpty: false # Set true to allow alt="" for decorative images ``` -------------------------------- ### Configure Caching Source: https://context7.com/wjdp/htmltest/llms.txt Configures caching for external URL checks to improve performance. ```yaml # Cache configuration EnableCache: true OutputDir: "tmp/.htmltest" OutputCacheFile: "refcache.json" CacheExpires: "336h" ``` ```bash # Cache file location tmp/.htmltest/refcache.json # Clear cache by deleting the file rm tmp/.htmltest/refcache.json ``` -------------------------------- ### Configure htmltest performance settings Source: https://context7.com/wjdp/htmltest/llms.txt YAML configuration for optimizing htmltest execution speed. It defines concurrency limits for document processing and HTTP requests, along with external timeout settings. ```yaml TestFilesConcurrently: true DocumentConcurrencyLimit: 128 HTTPConcurrencyLimit: 16 ExternalTimeout: 30 ``` -------------------------------- ### Configure htmltest for Jekyll Source: https://github.com/wjdp/htmltest/wiki/Using-With-Jekyll A YAML configuration file for htmltest to specify the target directory for validation. This file should be placed in the root of the project to point the tool at the Jekyll _site output folder. ```yaml DirectoryPath: _site ``` -------------------------------- ### Validate Scripts and Resources Source: https://context7.com/wjdp/htmltest/llms.txt Covers validation of external scripts, stylesheets, and favicons. ```html ``` ```yaml # Configure script/resource checking CheckScripts: true CheckLinks: true CheckFavicon: true # Ensure every page has a favicon ``` -------------------------------- ### Client-Side Search Filter (jQuery) Source: https://github.com/wjdp/htmltest/blob/master/htmltest/fixtures/html/normal_looking_page.html Implements a live search filter for elements with the class 'searchable' using jQuery. It filters table rows based on user input in an element with the ID 'filter' and updates visibility of 'no-matches' and 'table-header' elements. ```javascript var GOOG_FIXURL_LANG = "en"; var GOOG_FIXURL_SITE = "http://government.github.com"; $(document).ready(function () { (function ($) { $('#filter').keyup(function () { var rex = new RegExp($(this).val(), 'i'); $('.searchable tr').hide(); $('.searchable tr').filter(function () { return rex.test($(this).text()); }).show(); if ($('.govtable tr:visible').length === 0) { $('.govtable.no-matches').show(); } else { $('.govtable.no-matches').hide(); $('.govtable.table-header').show(); } if ($('.civictable tr:visible').length === 0) { $('.civictable.no-matches').show(); } else { $('.civictable.no-matches').hide(); $('.civictable.table-header').show(); } }) }(jQuery)); }); ``` -------------------------------- ### Ignoring Content with htmltest Source: https://context7.com/wjdp/htmltest/llms.txt Demonstrates how to use the `data-proofer-ignore` attribute in HTML to exclude specific elements or sections from validation checks. Also shows how to configure a custom ignore attribute in the YAML file. ```html Not checked
This won't be checked
Skipped ``` -------------------------------- ### Validate Meta Refresh Tags Source: https://context7.com/wjdp/htmltest/llms.txt Checks meta refresh tags for valid redirect URLs and timing. ```html ``` ```yaml # Configure meta checking CheckMeta: true CheckMetaRefresh: true ``` -------------------------------- ### Validate Generic HTML5 Elements Source: https://context7.com/wjdp/htmltest/llms.txt Validates URLs in media elements, iframes, and citations. ```html
Quote text
Inline quote ``` ```yaml # Enable generic element checking CheckGeneric: true ``` -------------------------------- ### Ignore Content with data-proofer-ignore Attribute (HTML) Source: https://github.com/wjdp/htmltest/blob/master/README.md You can prevent specific HTML elements from being checked by adding the `data-proofer-ignore` attribute directly to the tag or as a class. This attribute's name can also be customized in the configuration. ```html Not checked. ``` -------------------------------- ### Validate Doctype Declarations Source: https://context7.com/wjdp/htmltest/llms.txt Ensures documents contain proper doctype declarations. ```html ... ... ``` ```yaml # Configure doctype checking CheckDoctype: true EnforceHTML5: false # Set true to require ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.