diff --git a/README.md b/README.md
index 6f57eab..9ab4cb7 100644
--- a/README.md
+++ b/README.md
@@ -10,7 +10,7 @@ A custom reporter for [grunt-html] - the HTML validation task - which formats th
You can use the reporter programmatically. In that case you do not need [Grunt] as stated below. You can also use the reporter directly with the [grunt-html] task. The reporter is usually installed and used together with other development tasks.
-You need [node >= 4][node], [npm] and [grunt >= 0.4][Grunt] installed and your project build managed by a [Gruntfile] with the necessary modules listed in [package.json], including [grunt-html]. If you haven't used Grunt before, be sure to check out the [Getting Started] guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
+You need [node >= 6][node], [npm] and [grunt >= 0.4][Grunt] installed and your project build managed by a [Gruntfile] with the necessary modules listed in [package.json], including [grunt-html]. If you haven't used Grunt before, be sure to check out the [Getting Started] guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
```sh
$ npm install grunt-html-html-reporter --save-dev
@@ -36,7 +36,13 @@ fs.writeFileSync('report.html', output, 'utf-8')
Type: `Boolean`
Default value: `false`
-Cuts the directory from tested HTML files, when creating page titles from in the report. If you use unique names for files alone, you will not get too long page titles, if you flip this flag tp `true`.
+Cuts the directory from tested HTML files, when creating page titles of them in the report. If you use unique names for files alone, you will not get too long page titles, if you flip this flag tp `true`.
+
+#### showCommonPathOnly
+Type: `Boolean`
+Default value: `true`
+
+Cuts the same initial part of the path from tested HTML files, when the paths are used for page titles in the report. If you use sub-directories to organize your files, this option will make the file paths in the report short, but still unique. The default is flipped to `true` already.
## Usage with grunt-html
@@ -61,6 +67,7 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.
## Release History
+ * 2018-05-14 v3.1.0 Allow cutting the same initial part of the path from tested HTML files for displaying purposes
* 2018-04-27 v3.0.0 Dropped support of Node.js 4
* 2018-03-05 v2.2.0 Allow generating page titles from file names without directory
* 2018-03-04 v2.1.0 Add filtering and accessibility to the reports
diff --git a/index.js b/index.js
index dd7f15b..7f3fea5 100644
--- a/index.js
+++ b/index.js
@@ -1,7 +1,8 @@
'use strict'
-const fs = require('fs')
-const path = require('path')
+const {getCommonPathLength} = require('common-path-start')
+const {readFileSync} = require('fs')
+const {basename, join, normalize} = require('path')
const objectValues = require('object.values')
if (!Object.values) {
@@ -9,7 +10,7 @@ if (!Object.values) {
}
function formatIssues (issues, panelColor) {
- return issues.map(function (issue) {
+ return issues.map(issue => {
const extract = issue.extract.split('<').join('<')
const message = issue.message.split('<').join('<').split('"').join('"')
const line = issue.line
@@ -54,22 +55,26 @@ function formatFile (file) {
return content
}
-module.exports = function (results, options) {
+module.exports = (results, options) => {
const showFileNameOnly = options && options.showFileNameOnly
+ const showCommonPathOnly = !(options && options.showCommonPathOnly === false)
+ const commonPathLength = showCommonPathOnly &&
+ getCommonPathLength(results.map(result => normalize(result.file)))
const files = {}
- var errorCount = 0
- var warningCount = 0
- var noticeCount = 0
+ let errorCount = 0
+ let warningCount = 0
+ let noticeCount = 0
- results.forEach(function (result) {
- const name = path.normalize(result.file)
+ results.forEach(result => {
+ const name = normalize(result.file)
const severity = result.type
- var file = files[name]
- var fileName, issues
+ let file = files[name]
+ let fileName, issues
if (!file) {
if (showFileNameOnly) {
- fileName = path.parse(name)
- fileName = fileName.name + fileName.ext
+ fileName = basename(name)
+ } else if (commonPathLength) {
+ fileName = name.substr(commonPathLength)
} else {
fileName = name
}
@@ -102,8 +107,8 @@ module.exports = function (results, options) {
})
})
- const template = fs.readFileSync(
- path.join(__dirname, 'template.html'), 'utf8')
+ const template = readFileSync(
+ join(__dirname, 'template.html'), 'utf8')
const buttonMarkup =
'' +
diff --git a/package.json b/package.json
index 4fbc647..da326e9 100644
--- a/package.json
+++ b/package.json
@@ -34,13 +34,14 @@
"travis-deploy-once": "travis-deploy-once"
},
"dependencies": {
+ "common-path-start": "^0.0.1",
"object.values": "^1.0.4"
},
"devDependencies": {
- "semantic-release": "^15.1.7",
+ "semantic-release": "^15.4.1",
"standard": "^11.0.1",
- "tap": "^11.1.4",
- "travis-deploy-once": "^4.4.1"
+ "tap": "^11.1.5",
+ "travis-deploy-once": "^5.0.0"
},
"keywords": [
"grunt-tasks",
diff --git a/tests/results/common-path.html b/tests/results/common-path.html
new file mode 100644
index 0000000..b6d8d4f
--- /dev/null
+++ b/tests/results/common-path.html
@@ -0,0 +1,1089 @@
+
+
+
+
+ HTML Validation Report
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Start tag seen without seeing a doctype first. Expected “<!DOCTYPE html>”.
+
<html><head>
+
+
+
+
+
+
+
Attribute “gapi_processed” not allowed on element “script” at this point.
The “align” attribute on the “p” element is obsolete. Use CSS instead.
+
+<p></p>
+
+<p align="center"><img s
+
+
+
+
+
+
+
An “img” element must have an “alt” attribute, except under certain conditions. For details, consult guidance on providing text alternatives for images.
+
="center"><img src="downloadwww.gif">
+
+<!--
+
+
+
+
+
+
+
Element “contentxferbho” not allowed as child of element “body” in this context. (Suppressing further errors from this subtree.)
Potentially bad value “copyright” for attribute “rel” on element “link”: The keyword “copyright” for the “rel” attribute should not be used. Consider using “license” instead.
diff --git a/tests/results/report.json b/tests/results/report.json
index 976daff..566e358 100644
--- a/tests/results/report.json
+++ b/tests/results/report.json
@@ -1 +1 @@
-[{"type":"error","lastLine":1,"lastColumn":6,"firstColumn":1,"message":"Start tag seen without seeing a doctype first. Expected “”.","extract":"","hiliteStart":0,"hiliteLength":6,"file":"snapshots/hmpg.net.html"},{"type":"error","lastLine":3,"lastColumn":513,"firstColumn":408,"message":"Attribute “gapi_processed” not allowed on element “script” at this point.","extract":">