@@ -96,7 +96,21 @@ def check_names(self, mds):
9696 if len (fns ) > 1 :
9797 self .emit (f"duplicate stable: { fns } " )
9898
99- def check_front_matter (self , fn , front ):
99+ def _check_front_matter_supplement (self , fn , front , filenames ):
100+ typ = front .get ('type' )
101+ if typ != "Supplement" :
102+ self .emit (f"in { fn } : type must be Supplement, is { typ } " )
103+ if 'status' in front :
104+ self .emit (f"in { fn } : Supplement shouldn't have status field" )
105+ supplements = front .get ("supplements" )
106+ if not isinstance (supplements , list ):
107+ self .emit (f"in { fn } : field 'supplements' must be a list" )
108+ # NOTE could check that each entry refers to a file that exists
109+ for fn2 in supplements :
110+ if fn2 not in filenames :
111+ self .emit ("in {fn}: field 'supplements' refers to unknown {fn2}" )
112+
113+ def check_front_matter (self , fn , front , filenames ):
100114 """Check the dict `front` of front matter
101115
102116 The argument `fn` is mainly for context in error messages, but also to distinguish document types.
@@ -105,6 +119,8 @@ def check_front_matter(self, fn, front):
105119 self .emit (f"in { fn } : is missing front matter altogether" )
106120 return
107121 # so far, only check primary documents, not supplemental ones
122+ if fn [9 ] == 'w' :
123+ return self ._check_front_matter_supplement (fn , front , filenames )
108124 if fn [9 ] != 'v' :
109125 print (f"skipping non-primary { fn } " , file = sys .stderr )
110126 return
@@ -151,7 +167,7 @@ def main(argv):
151167 checker = Checker ()
152168 for fn in mds :
153169 checker .check_name (fn )
154- checker .check_front_matter (fn , _load_front_matter (os .path .join (path , fn )))
170+ checker .check_front_matter (fn , _load_front_matter (os .path .join (path , fn )), mds )
155171 checker .check_names (mds )
156172 return checker .errors
157173
0 commit comments