@@ -22,12 +22,14 @@ def parse(s: str) -> Iterator[Tuple[str, str]]:
22
22
"""Parse an AWS docs page in Markdown format, yielding each property."""
23
23
# Prevent from parsing return values accidentally
24
24
with suppress (ValueError ):
25
- s = s [: s .index ("Return Values" )]
25
+ s = s [: s .index ("# Return Value" )]
26
+ with suppress (ValueError ):
27
+ s = s [: s .index ("# Return value" )]
26
28
parts = s .split ("\n \n " )
27
29
for part in parts :
28
30
match = re .match (r"^\s*`(\w+)`\s+<a" , part )
29
31
if match :
30
- yield match .group (1 ), part . strip ()
32
+ yield match .group (1 ), part
31
33
32
34
33
35
# TODO: Change in the docs instead?
@@ -64,14 +66,13 @@ def main() -> None:
64
66
parser = argparse .ArgumentParser ()
65
67
parser .add_argument ("dir" , type = Path )
66
68
parser .add_argument ("--cfn" , action = "store_true" )
67
- parser .add_argument ("--with-title" , help = "use doc title instead of filename as key" , action = "store_true" )
68
69
args = parser .parse_args ()
69
70
70
71
props : Dict [str , Dict [str , str ]] = {}
71
72
for path in args .dir .glob ("*.md" ):
72
73
text = path .read_text ()
73
74
title = stringbetween (text , "# " , "<a" )
74
- page = title if args .with_title else path .stem
75
+ page = title if args .cfn else path .stem
75
76
for name , description in parse (text ):
76
77
if page not in props :
77
78
props [page ] = {}
@@ -83,7 +84,10 @@ def main() -> None:
83
84
else "https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/"
84
85
)
85
86
description = convert_to_full_path (description , prefix )
86
- props [page ][name ] = description
87
+ # Assume properties (what we care about) at top, so skip if already exists
88
+ if name in props [page ]:
89
+ continue
90
+ props [page ][name ] = description .strip ()
87
91
88
92
print (
89
93
json .dumps (
0 commit comments