@@ -79,11 +79,34 @@ fn find_all_html_files(dir: &Path) -> (usize, usize) {
7979 ( files_read, errors)
8080}
8181
82+ /// Default `tidy` command for macOS is too old that it does not have `mute-id` and `mute` options.
83+ /// `tidy` on macOS Monterey was released on 31 October 2006, and the same date can be seen seven
84+ /// years ago at <https://stackoverflow.com/questions/22283382/overwrite-osx-tidy>. Accordingly,
85+ /// the macOS environment using pre-installed `tidy` should immediately suspend HTML checker process
86+ /// and show a hint to install a newer one.
87+ #[ cfg( target_os = "macos" ) ]
88+ fn check_tidy_version ( ) -> Result < ( ) , String > {
89+ let output = Command :: new ( "tidy" ) . arg ( "-v" ) . output ( ) . expect ( "failed to run tidy command" ) ;
90+ let version = String :: from_utf8 ( output. stdout ) . expect ( "failed to read version of tidy command" ) ;
91+ if version. contains ( "HTML Tidy for Mac OS X released on 31 October 2006" ) {
92+ eprintln ! ( "The pre-installed HTML Tidy for macOS is not supported." ) ;
93+ eprintln ! ( "Consider installing a newer one and re-running." ) ;
94+ eprintln ! ( "If you're using Homebrew, you can install it by the following command:" ) ;
95+ eprintln ! ( " brew install tidy-html5" ) ;
96+ eprintln ! ( ) ;
97+ Err ( "HTML check failed: 1 error" . to_string ( ) )
98+ } else {
99+ Ok ( ( ) )
100+ }
101+ }
102+
82103fn main ( ) -> Result < ( ) , String > {
83104 let args = env:: args ( ) . collect :: < Vec < _ > > ( ) ;
84105 if args. len ( ) != 2 {
85106 return Err ( format ! ( "Usage: {} <doc folder>" , args[ 0 ] ) ) ;
86107 }
108+ #[ cfg( target_os = "macos" ) ]
109+ check_tidy_version ( ) ?;
87110
88111 println ! ( "Running HTML checker..." ) ;
89112
0 commit comments