Simplify simplehtml_validity.py

This commit is contained in:
Thibaut Cuvelier 2023-01-09 04:16:34 +01:00
parent 6093e7d661
commit fa5b08e24d

View File

@ -12,17 +12,14 @@
# Run: # Run:
# pip install html5validator>=0.4.2 # pip install html5validator>=0.4.2
import collections
import glob
import sys import sys
import tempfile
import os import os
import html5validator import html5validator
if len(sys.argv) != 2: if len(sys.argv) != 2:
print('Expecting one argument, the path to the LyX-create xhtml file') print('Expecting one argument, the path to the LyX-created XHTML file')
sys.exit(-1) sys.exit(-1)
if not os.path.exists(sys.argv[1]): if not os.path.exists(sys.argv[1]):
print('The given path does not point to an existing file') print('The given path does not point to an existing file')
@ -35,19 +32,9 @@ xhtml_list = [xhtml_file_name]
validator = html5validator.Validator(format='text') validator = html5validator.Validator(format='text')
error_count = validator.validate(xhtml_list) error_count = validator.validate(xhtml_list)
n_invalid = 0
n_valid = 0
if error_count == 0: if error_count == 0:
n_valid += 1 print('> Found no validation error!')
print(f'> Found no validation error!')
sys.exit(0) sys.exit(0)
else: else:
n_invalid += 1 print('> Found a validation error!')
print(f'> Found {error_count} validation error{"" if error_count == 1 else "s"}!')
sys.exit(-2) sys.exit(-2)
if n_invalid == 0:
print("That's excellent! Give yourself a pat on the back!")
sys.exit(0)
else:
sys.exit(-3)