Skip to content

Commit

Permalink
Added new option for validation: --extended-validation
Browse files Browse the repository at this point in the history
--extended-validation=value
    Comma-separated list of extended validation checks
     Possible values:
       all|ALL: shortcut for all checks listed below
       ids:     checks for IDs that are not SEO friendly
       images:  checks for missing and duplicated  images
       inlines: checks for empty inline elements
       tables:  checks for invalid tables
     Example: --extended-validation="ids,tables"
     Default: unset

In a DC-file these options can be activated by setting the variable
EXTENDED_VALIDATION, for example

EXTENDED_VALIDATION="ids,tables"
(the "ALL" shortcut works here as well)

Whenever one of the activated extended validation options fails, DAPS exits
with error.

This option is available for the following subcommands

* epub
* html
* locdrop
* man
* package-html
* package-pdf
* package-src
* pdf
* text
* validate
* webhelp

NOTE:
Previously, once a successful validation was done, the code was only
re-validated when the sources had changed. With the introduction of this
option the code is always re-validated (for the subcommands mentioned above).
  • Loading branch information
fsundermeyer committed Mar 8, 2024
1 parent c8956e8 commit 0a8804f
Show file tree
Hide file tree
Showing 20 changed files with 95 additions and 63 deletions.
92 changes: 53 additions & 39 deletions lib/daps_functions
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ function parse_args {
# variables accordingly.

local SHORT_OPTS LONG_OPTS SUB_CMD
local _EXTVAL_VALUES
SHORT_OPTS=$1
LONG_OPTS=$2
SUB_CMD=$3
Expand Down Expand Up @@ -108,6 +109,11 @@ function parse_args {
export EPUB3=1
shift
;;
--extended-validation)
# validate: activate extended validation
EXTENDED_VALIDATION=(${2//,/ })
shift 2
;;
--export-dir)
# locdrop: export directory
sanitize_path "$2" "EXPORT_DIR"
Expand Down Expand Up @@ -253,10 +259,6 @@ function parse_args {
sanitize_path "$2" "P_NOTRANS_DIR"
shift 2
;;
--not-validate-tables)
export NOT_VALIDATE_TABLES=1
shift
;;
--novalid)
# bigfile: Do not validate profiled sources
export NOVALID=1
Expand Down Expand Up @@ -371,14 +373,6 @@ function parse_args {
P_TRANS_FILES="$2"
shift 2
;;
--validate-ids)
export VALIDATE_IDS=1
shift
;;
--validate-images)
export VALIDATE_IMAGES=1
shift
;;
--viewer)
# getimages: specify image viewer
# no need to export (not passed to make)
Expand Down Expand Up @@ -506,6 +500,33 @@ function init_env {
COLOR=0
fi

# Set values for extended validation
#
for _opt in "${EXTENDED_VALIDATION[@]}"; do
case $_opt in
all|ALL)
export VALIDATE_IDS=1
export VALIDATE_IMAGES=1
export VALIDATE_INLINES=1
export VALIDATE_TABLES=1
;;
ids)
export VALIDATE_IDS=1
;;
images)
export VALIDATE_IMAGES=1
;;
inlines)
export VALIDATE_INLINES=1
;;
tables)
export VALIDATE_TABLES=1
;;
*)
exit_on_error "Wrong value \"$_opt\" for --extended-validation"
esac
done

# export PARAMS and STRINGPARAMS
[[ -n "$P_PARAMS" ]] && export PARAMS="$P_PARAMS"
[[ -n "$P_STRINGPARAMS" ]] && export STRINGPARAMS="$P_STRINGPARAMS"
Expand Down Expand Up @@ -809,7 +830,7 @@ function call_make {
#
# Generic BUILD function
#
# Subcommands: all commands that does not fit elsewhere
# Subcommands: all commands that do not fit elsewhere
#
###########################################################################
function build_generic {
Expand Down Expand Up @@ -892,19 +913,17 @@ function validate {
shift

SHORT_OPTS="h"
LONG_OPTS="help,norefcheck,not-validate-tables,remarks,validate-ids,validate-images"
LONG_OPTS="help,extended-validation:,norefcheck,not-validate-tables,remarks,validate-ids,validate-images"

parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@"
eval set -- "$P_REMAIN_ARGS"

#------ Computing the values returned from the parser -----
if [[ 1 -eq $P_HELP ]]; then
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}"
help_extended-validation
help_norefcheck
help_not-validate-tables
help_remarks
help_validate-ids
help_validate-images
echo
exit 0
fi
Expand Down Expand Up @@ -1215,6 +1234,23 @@ function help_epub3 {
Default: ePUB version 2
EOF
}
function help_extended-validation {
cat <<EOF
--extended-validation=value Comma-separated list of extended validation
checks
Possible values:
all|ALL: shortcut for all checks listed
below
ids: checks for IDs that are not SEO
friendly
images: checks for missing and duplicated
images
inlines: checks for empty inline elements
tables: checks for invalid tables
Example: --extended-validation="ids,tables"
Default: unset
EOF
}
function help_extra-dict {
cat <<EOF
--extra-dict=filename Specify a path to an additional custom
Expand Down Expand Up @@ -1431,13 +1467,6 @@ function help_nostatic {
with CSS and Javascript.
EOF
}
function help_not-validate-tables {
cat <<EOF
--not-validate-tables Disable checking for tables that contain
structural errors (e.g. missing cells).
Default: unset (table check is performed)
EOF
}
function help_novalid {
cat <<EOF
--novalid Do not perform a validation check on the
Expand Down Expand Up @@ -1569,21 +1598,6 @@ function help_target {
Default: same as daps subcommand
EOF
}
function help_validate-ids {
cat <<EOF
--validate-ids Also check IDs to include no other
characters than '[-a-zA-Z0-9].
Default: unset
EOF
}
function help_validate-images {
cat <<EOF
--validate-images Also check for missing and duplicated images.
Missing images cause an error, duplicated
imnages a warning only.
Default: unset
EOF
}
function help_viewer {
cat <<EOF
--viewer=VIEWER Image viewer to be used.
Expand Down
3 changes: 2 additions & 1 deletion lib/epub
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function build_epub {
shift

SHORT_OPTS="h"
LONG_OPTS="check,css:,epub3,help,name:,norefcheck,not-validate-tables,param:,remarks,rootid:,statdir:,stringparam:"
LONG_OPTS="check,css:,epub3,extended-validation:,help,name:,norefcheck,not-validate-tables,param:,remarks,rootid:,statdir:,stringparam:"

parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@"
eval set -- "$P_REMAIN_ARGS"
Expand All @@ -29,6 +29,7 @@ function build_epub {
help_check
help_css_epub
help_epub3
help_extended-validation
help_help
help_name
help_norefcheck
Expand Down
3 changes: 2 additions & 1 deletion lib/html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function build_html {
shift

SHORT_OPTS="h"
LONG_OPTS="clean,css:,draft,help,html5,name:,norefcheck,nostatic,not-validate-tables,meta,param:,remarks,rootid:,single,statdir:,static,stringparam:,xsltparam:"
LONG_OPTS="clean,css:,draft,extended-validation:,help,html5,name:,norefcheck,nostatic,not-validate-tables,meta,param:,remarks,rootid:,single,statdir:,static,stringparam:,xsltparam:"

parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@"
eval set -- "$P_REMAIN_ARGS"
Expand All @@ -29,6 +29,7 @@ function build_html {
help_clean
help_css
help_draft
help_extended-validation
help_help
help_html5
help_meta
Expand Down
3 changes: 2 additions & 1 deletion lib/locdrop
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function build_locdrop {
shift

SHORT_OPTS="h"
LONG_OPTS="def-file:,export-dir:,help,name:,nopdf,not-validate-tables,optipng,rootid:"
LONG_OPTS="def-file:,export-dir:,extended-validation:,help,name:,nopdf,not-validate-tables,optipng,rootid:"

parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@"
eval set -- "$P_REMAIN_ARGS"
Expand All @@ -28,6 +28,7 @@ function build_locdrop {
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}"
help_def-file
help_export-dir
help_extended-validation
help_help
help_name
help_nopdf
Expand Down
3 changes: 2 additions & 1 deletion lib/man
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ function build_man {
shift

SHORT_OPTS="h"
LONG_OPTS="help,nogzip,norefcheck,not-validate-tables,param,rootid:,stringparam:,subdirs"
LONG_OPTS="extended-validation:,help,nogzip,norefcheck,not-validate-tables,param,rootid:,stringparam:,subdirs"

parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@"
eval set -- "$P_REMAIN_ARGS"

#------ Computing the values returned from the parser -----
if [[ 1 -eq $P_HELP ]]; then
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}"
help_extended-validation
help_help
help_nogzip
help_norefcheck
Expand Down
3 changes: 2 additions & 1 deletion lib/package-html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function package-html {
shift

SHORT_OPTS="h"
LONG_OPTS="css:,desktopfiles,documentfiles,help,html5,name:,not-validate-tables,pagefiles,param:,rootid:,set-date:,single,statdir:,stringparam:,xsltparam:"
LONG_OPTS="css:,desktopfiles,documentfiles,extended-validation:,help,html5,name:,not-validate-tables,pagefiles,param:,rootid:,set-date:,single,statdir:,stringparam:,xsltparam:"

parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@"
eval set -- "$P_REMAIN_ARGS"
Expand All @@ -29,6 +29,7 @@ function package-html {
help_css
help_desktopfiles
help_documentfiles
help_extended-validation
help_help
help_html5
help_name
Expand Down
3 changes: 2 additions & 1 deletion lib/package-pdf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function package-pdf {
shift

SHORT_OPTS="h"
LONG_OPTS="cropmarks,desktopfiles,documentfiles,formatter:,grayscale,help,name:,not-validate-tables,pagefiles,param:,rootid:,set-date:,stringparam:,xsltparam:"
LONG_OPTS="cropmarks,desktopfiles,documentfiles,extended-validation:,formatter:,grayscale,help,name:,not-validate-tables,pagefiles,param:,rootid:,set-date:,stringparam:,xsltparam:"

parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@"
eval set -- "$P_REMAIN_ARGS"
Expand All @@ -29,6 +29,7 @@ function package-pdf {
help_cropmarks
help_desktopfiles
help_documentfiles
help_extended-validation
help_formatter
help_grayscale_pdf
help_help
Expand Down
3 changes: 2 additions & 1 deletion lib/package-src
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function package-src {
shift

SHORT_OPTS="h"
LONG_OPTS="def-file:,help,locdrop,name:,not-validate-tables,optipng,set-date:"
LONG_OPTS="def-file:,extended-validation:,help,locdrop,name:,not-validate-tables,optipng,set-date:"

parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@"
eval set -- "$P_REMAIN_ARGS"
Expand All @@ -27,6 +27,7 @@ function package-src {
if [[ 1 -eq $P_HELP ]]; then
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}"
help_def-file
help_extended-validation
help_help
help_locdrop
help_name
Expand Down
3 changes: 2 additions & 1 deletion lib/pdf
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function build_pdfs {
shift

SHORT_OPTS="h"
LONG_OPTS="cropmarks,draft,formatter:,help,grayscale,lean,meta,name:,norefcheck,not-validate-tables,param:,remarks,rootid:,stringparam:,xsltparam:"
LONG_OPTS="cropmarks,draft,extended-validation:,formatter:,help,grayscale,lean,meta,name:,norefcheck,not-validate-tables,param:,remarks,rootid:,stringparam:,xsltparam:"

parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@"
eval set -- "$P_REMAIN_ARGS"
Expand All @@ -28,6 +28,7 @@ function build_pdfs {
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}"
help_cropmarks
help_draft
help_extended-validation
help_formatter
help_grayscale_pdf
help_help
Expand Down
3 changes: 2 additions & 1 deletion lib/text
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ function build_text {
shift

SHORT_OPTS="h"
LONG_OPTS="ignore-styleroot,help,name:,norefcheck,not-validate-tables,param:,rootid:,stringparam:"
LONG_OPTS="extended-validation:,ignore-styleroot,help,name:,norefcheck,not-validate-tables,param:,rootid:,stringparam:"

parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@"
eval set -- "$P_REMAIN_ARGS"

#------ Computing the values returned from the parser -----
if [[ 1 -eq $P_HELP ]]; then
help_scmd_head "$SUB_CMD" "${HELP_SUBCOMMAND[$SUB_CMD]}"
help_extended-validation
help_ignore-styleroot
help_help
help_name
Expand Down
3 changes: 2 additions & 1 deletion lib/webhelp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function webhelp {
shift

SHORT_OPTS="h"
LONG_OPTS="clean,css:,draft,help,name:,norefcheck,nosearch,nostatic,not-validate-tables,param:,remarks,rootid:,static,stringparam:,xsltparam:"
LONG_OPTS="clean,css:,draft,extended-validation:,help,name:,norefcheck,nosearch,nostatic,not-validate-tables,param:,remarks,rootid:,static,stringparam:,xsltparam:"

parse_args "$SHORT_OPTS" "$LONG_OPTS" "$SUB_CMD" "$@"
eval set -- "$P_REMAIN_ARGS"
Expand All @@ -29,6 +29,7 @@ function webhelp {
help_clean
help_css
help_draft
help_extended-validation
help_help
help_name
help_not-validate-tables
Expand Down
2 changes: 1 addition & 1 deletion make/epub.mk
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ $(EPUB_DIRECTORIES):
#--------------
# generate EPUB-bigfile
#
$(EPUB_BIGFILE): $(PROFILES) $(PROFILEDIR)/.validate
$(EPUB_BIGFILE): $(PROFILES) validate
ifeq "$(VERBOSITY)" "2"
@ccecho "info" " Generating EPUB-bigfile"
endif
Expand Down
2 changes: 1 addition & 1 deletion make/html.mk
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ copy_inline_images_html: $(COLOR_IMAGES)
ifdef METASTRING
$(HTML_RESULT): $(PROFILEDIR)/METAFILE
endif
$(HTML_RESULT): $(PROFILES) $(PROFILEDIR)/.validate $(DOCFILES)
$(HTML_RESULT): $(PROFILES) $(DOCFILES) validate
ifeq "$(VERBOSITY)" "2"
@ccecho "info" "Creating HTML pages"
ifdef HTML_CSS_INFO
Expand Down
2 changes: 1 addition & 1 deletion make/locdrop.mk
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ endif
ifneq "$(NOPDF)" "1"
locdrop: pdf
endif
locdrop: $(SRCFILES) $(MANIFEST_TRANS) $(MANIFEST_NOTRANS) $(USED_ALL) $(PROFILES) $(PROFILEDIR)/.validate
locdrop: $(SRCFILES) $(MANIFEST_TRANS) $(MANIFEST_NOTRANS) $(USED_ALL) $(PROFILES) validate
ifeq "$(strip $(TO_TRANS_FILES))" ""
$(error $(shell ccecho "error" "Fatal error: Could not find any files to translate"))
endif
Expand Down
2 changes: 1 addition & 1 deletion make/man.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ MAN_RESULTS = $(shell $(XSLTPROC) $(MANSTRINGS) $(PARAMS) $(STRINGPARAMS) \
#
.PHONY: man
man: | $(MAN_DIR)
man: $(PROFILES) $(PROFILEDIR)/.validate
man: $(PROFILES) validate
man: $(BIGFILE)
# only checking firstword, because if $MAN_RESULTS is very long,
# the test expression will throw an error
Expand Down
2 changes: 1 addition & 1 deletion make/packaging.mk
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ifdef IS_LOCDROP
package-src: MFT_TRANS := $(wildcard $(addprefix $(PRJ_DIR)/,$(notdir $(MANIFEST_TRANS))))
package-src: MFT_NOTRANS := $(wildcard $(addprefix $(PRJ_DIR)/,$(notdir $(MANIFEST_NOTRANS))))
endif
package-src: $(PROFILES) $(PROFILEDIR)/.validate
package-src: $(PROFILES) validate
ifneq "$(strip $(MISSING_IMG))" ""
@ccecho "error" "Fatal error: The following images are missing:"
@echo -e "$(subst $(SPACE),\n,$(sort $(MISSING_IMG)))"
Expand Down
2 changes: 1 addition & 1 deletion make/pdf.mk
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ endif
ifeq "$(VERBOSITY)" "1"
$(FOFILE): FONTDEBUG := --param "debug.fonts=0"
endif
$(FOFILE): $(PROFILES) $(PROFILEDIR)/.validate $(DOCFILES) $(STYLEFO)
$(FOFILE): $(PROFILES) $(DOCFILES) $(STYLEFO) validate
ifeq "$(VERBOSITY)" "2"
@ccecho "info" " Creating fo-file..."
endif
Expand Down
Loading

0 comments on commit 0a8804f

Please sign in to comment.