@@ -42,17 +42,27 @@ def process_file(path: Path) -> str:
4242 with path .open () as f :
4343 data = yaml .safe_load (f )
4444
45- info = data ["title" ]
46- if desc := data .get ("description" , "" ):
47- info = f"{ add_full_stop (info )} { desc } "
48- out += f"{ add_full_stop (info )} \n \n "
45+ out += f"{ add_full_stop (data ['title' ])} \n \n "
4946
5047 try :
51- out += fields2table (data ["fields" ])
48+ table_str , notes_str = fields2table (data ["fields" ])
49+ out += table_str
5250 except KeyError :
5351 print (f"MISSING VALUE IN { path } " )
5452 raise
5553
54+ desc = data .get ("description" , "" )
55+ if not desc and not notes_str :
56+ return out
57+
58+ out += "\n #### Notes\n \n "
59+
60+ if desc :
61+ out += f"{ add_full_stop (desc )} \n \n "
62+
63+ if notes_str :
64+ out += notes_str
65+
5666 return out
5767
5868
@@ -64,20 +74,30 @@ def add_full_stop(s: str) -> str:
6474 return f"{ s } ."
6575
6676
67- def fields2table (fields : list [dict [str , str ]]) -> str :
77+ def fields2table (fields : list [dict [str , str ]]) -> tuple [str , str ]:
78+ data = []
79+ notes = []
80+ for f in fields :
81+ row = {"Field" : f"`{ f ['name' ]} `" , "Description" : f ["title" ]}
82+ data .append (row )
83+
84+ if desc := f .get ("description" , "" ):
85+ # MarkdownTable can't handle newlines, so replace with HTML equivalent
86+ desc = desc .replace ("\n \n " , "<br /><br />" ).replace ("\n " , " " )
87+ row = {"Field" : f"`{ f ['name' ]} `" , "Notes" : desc }
88+ notes .append (row )
89+
6890 data = [
6991 {
7092 "Field" : f"`{ f ['name' ]} `" ,
71- "Title" : f ["title" ],
72- # MarkdownTable can't handle newlines, so replace with HTML equivalent
73- "Description" : add_full_stop (f .get ("description" , "" ))
74- .replace ("\n \n " , "<br /><br />" )
75- .replace ("\n " , " " ),
93+ "Description" : f ["title" ],
7694 }
7795 for f in fields
7896 ]
7997
80- return str (MarkdownTable .from_dicts (data ))
98+ table_str = str (MarkdownTable .from_dicts (data ))
99+ notes_str = str (MarkdownTable .from_dicts (notes )) if notes else ""
100+ return table_str , notes_str
81101
82102
83103if __name__ == "__main__" :
0 commit comments