在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:aim42/htmlSanityCheck开源软件地址:https://github.com/aim42/htmlSanityCheck开源编程语言:Groovy 54.4%开源软件介绍:Html Sanity CheckThis project provides some basic sanity checking on html files. It can be helpful in case of html generated from e.g. Asciidoctor, Markdown or other formats - as converters usually don’t check for missing images or broken links. It can be used as Gradle plugin. Standalone Java and graphical UI are planned for future releases. InstallationUse the following snippet inside a Gradle build file: build.gradle
plugins {
id 'org.aim42.htmlSanityCheck' version '1.1.5'
} OR build.gradle
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
}
dependencies {
classpath ('gradle.plugin.org.aim42:htmlSanityCheck:1.1.5')
}
}
apply plugin: 'org.aim42.htmlSanityCheck' UsageThe plugin adds a new task named This task exposes a few properties as part of its configuration:
Examplesbuild.gradle (small example)
apply plugin: 'org.aim42.htmlSanityCheck'
htmlSanityCheck {
sourceDir = new File( "$buildDir/docs" )
// where to put results of sanityChecks...
checkingResultsDir = new File( "$buildDir/report/htmlchecks" )
// fail build on errors?
failOnErrors = true
} build.gradle (extensive example)
import org.aim42.htmlsanitycheck.check.*
buildscript {
repositories {
maven {
url "https://plugins.gradle.org/m2/"
}
jcenter()
}
}
plugins {
id 'org.aim42.htmlsanitycheck' version '1.1.1'
id 'org.asciidoctor.convert' version '1.5.8'
}
// ==== path definitions =====
// ===========================
// location of AsciiDoc files
def asciidocSrcPath = "$projectDir/src/asciidoc"
// location of images used in AsciiDoc documentation
def srcImagesPath = "$asciidocSrcPath/images"
// results of asciidoc compilation (HTML)
// (input for htmlSanityCheck)
// this is the default path for asciidoc-gradle-convert
def htmlOutputPath = "$buildDir/asciidoc/html5"
// images used by generated html
def targetImagesPath = htmlOutputPath + "/images"
// where HTMLSanityCheck checking results ares stored
def checkingResultsPath = "$buildDir/report/htmlchecks"
apply plugin: 'org.asciidoctor.convert'
asciidoctor {
sourceDir = new File( asciidocSrcPath )
options backends: ['html5'],
doctype: 'book',
icons: 'font',
sectlink: true,
sectanchors: true
resources {
from( srcImagesPath )
into targetImagesPath
}
}
apply plugin: 'org.aim42.htmlSanityCheck'
htmlSanityCheck {
// ensure asciidoctor->html runs first
// and images are copied to build directory
dependsOn asciidoctor
sourceDir = new File( htmlOutputPath )
// files to check, specified as a file tree with filtering
sourceDocuments = fileTree(sourceDir) {
include "many-errors.html", "no-errors.html"
}
// where to put results of sanityChecks...
checkingResultsDir = new File( checkingResultsPath )
// fail build on errors?
failOnErrors = false
// http connection timeout in milliseconds
httpConnectionTimeout = 1000
// which statuscodes shall be interpreted as warning, error or success
// defaults to standard
httpWarningCodes = [401]
// httpErrorCodes
// httpSuccessCodes
// only execute a subset of all available checks
// available checker:
// * BrokenCrossReferencesChecker
// * BrokenHttpLinksChecker
// * DuplicateIdChecker
// * ImageMapChecker
// * MissingAltInImageTagsChecker
// * MissingImageFilesChecker
// * MissingLocalResourcesChecker
checkerClasses = [DuplicateIdChecker, MissingImageFilesChecker]
} Typical OutputTypes of Sanity ChecksBroken Cross References (aka Broken Internal Links)Finds all '<a href="XYZ">' where XYZ is not defined. src/broken.html
<a href="#missing">internal anchor</a>
...
<h2 id="missinG">Bookmark-Header</h2> In this example, the bookmark is misspelled. Use checkerClass BrokenCrossReferencesChecker. Missing Images FilesImages, referenced in '<img src="XYZ"…' tags, refer to external files. The existence of these files is checked by the plugin. Use checkerClass MissingImageFilesChecker. Multiple Definitions of Bookmarks or ID’sIf any is defined more than once, any anchor linking to it will be confused :-) Use checkerClass DuplicateIdChecker. Missing Local ResourcesAll files (e.g. downloads) referenced from html. Use checkerClass MissingLocalResourcesChecker. Missing Alt-tags in ImagesImage-tags should contain an alt-attribute that the browser displays when the original image file cannot be found or cannot be rendered. Having alt-attributes is good and defensive style. Use checkerClass MissingAltInImageTagsChecker. Broken HTTP LinksThe current version (derived from branch 1.0.0-RC-2) contains a simple implementation that identifies errors (status >400) and warnings (status 1xx or 3xx). StatusCodes are configurable ranges (as some people might want some content behind paywalls NOT to result in errors…) Localhost or numerical IP addresses are currently NOT marked as suspicious. Please comment in case you have additional requirements. Use checkerClass BrokenHttpLinksChecker. Other types of external linksplanned: ftp, ntp or other protocols are currently not checked, but should… Technical DocumentationIn addition to checking HTML, this project serves as an example for arc42. Please see our software architecture documentation. FundamentalsThis tiny piece rests on incredible groundwork:
Ideas and Origin
DevelopmentIn case you want to checkout, fork and/or contribute: The documentation is maintained using the awesome docToolchain, created by @rdmueller. After checkout you should execute:
to ensure that the docToolchain submodule is downloaded. Helpful Sources for DevelopmentSeveral sources provided help during development:
Similar Projects
ContributingPlease report issues or suggestions. Want to improve the plugin: Fork our repository and send a pull request. Licence |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论