]> git.lyx.org Git - lyx.git/blob - development/autotests/simplehtml_validity.py
Adding binary path for Homebrew on MacOS-arm64 (bug 12619).
[lyx.git] / development / autotests / simplehtml_validity.py
1 # Stricter version of the export tests: validate the XHTML code produced by
2 # LyX' lyxhtml output as HTML5. It also validates the CSS and MathML parts.
3 # Validation errors usually are mistakes in the generator.
4 #
5 # Call:
6 #     python simplehtml_validity.py PATH_TO_HTML5_SOURCE
7 #
8 # Written with Python 3.8.8.
9 # Requirements:
10 # - Python package: html5validator: at least v0.4.2
11 # - Java runtime engine (JRE): at least v8 (depending on html5validator)
12 # Run:
13 #     pip install html5validator>=0.4.2
14
15 import sys
16 import os
17
18 import html5validator
19
20
21 if len(sys.argv) != 2:
22     print('Expecting one argument, the path to the LyX-created XHTML file')
23     sys.exit(-1)
24 if not os.path.exists(sys.argv[1]):
25     print('The given path does not point to an existing file')
26     sys.exit(-1)
27
28
29 xhtml_file_name = sys.argv[1]
30 xhtml_list = [xhtml_file_name]
31
32 validator = html5validator.Validator(format='text')
33 error_count = validator.validate(xhtml_list)
34
35 if error_count == 0:
36     sys.exit(0)
37 else:
38     print('> Found a validation error!')
39     sys.exit(-2)