@@ -167,7 +167,7 @@ def __lt__(self, other):
167167 return affected_package_with_patched_package_objects
168168
169169
170- def split_markdown_front_matter (text : str ) -> Tuple [str , str ]:
170+ def split_markdown_front_matter (lines : str ) -> Tuple [str , str ]:
171171 r"""
172172 Split text into markdown front matter and the markdown body
173173 Return ("", text) for text with non existing front matter
@@ -180,15 +180,19 @@ def split_markdown_front_matter(text: str) -> Tuple[str, str]:
180180 ... # Markdown starts here
181181 ... '''
182182 >>> split_markdown_front_matter(text)
183- ('title: DUMMY-SECURITY-2019-001\ndescription: Incorrect access control.\ncves: [CVE-2042-1337]\n ', '\n # Markdown starts here\n')
183+ ('title: DUMMY-SECURITY-2019-001\ndescription: Incorrect access control.\ncves: [CVE-2042-1337]', '# Markdown starts here\n')
184184 """
185-
186- front_matter = ""
187- body = text
188- text = text .replace ("\r \n " , "\n " )
189- linezero , _ , text = text .partition ("---\n " )
190-
191- if not linezero : # nothing before first ---
192- front_matter , _ , body = text .partition ("---" )
193-
194- return front_matter , body
185+ fmlines = []
186+ mdlines = []
187+ splitter = mdlines
188+
189+ lines = lines .replace ("\r \n " , "\n " )
190+ for index , line in enumerate (lines .split ("\n " )):
191+ if index == 0 and line .strip ().startswith ("---" ):
192+ splitter = fmlines
193+ elif line .strip ().startswith ("---" ):
194+ splitter = mdlines
195+ else :
196+ splitter .append (line )
197+
198+ return "\n " .join (fmlines ), "\n " .join (mdlines )
0 commit comments