@@ -167,10 +167,10 @@ def __lt__(self, other):
167167 return affected_package_with_patched_package_objects
168168
169169
170- def split_markdown_front_matter (lines : str ) -> Tuple [str , str ]:
170+ def split_markdown_front_matter (text : str ) -> Tuple [str , str ]:
171171 r"""
172- Split text into markdown front matter and the markdown body
173- Return ("", text) for text with non existing front matter
172+ Return a tuple of ( front matter, markdown body) strings split from ``text``.
173+ Each can be an empty string.
174174
175175 >>> text='''---
176176 ... title: DUMMY-SECURITY-2019-001
@@ -180,19 +180,13 @@ def split_markdown_front_matter(lines: 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]', '# Markdown starts here\n ')
183+ ('title: DUMMY-SECURITY-2019-001\ndescription: Incorrect access control.\ncves: [CVE-2042-1337]', '# Markdown starts here')
184184 """
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 )
185+ lines = text .splitlines ()
186+ if lines [0 ] == "---" :
187+ lines = lines [1 :]
188+ text = "\n " .join (lines )
189+ frontmatter , _ , markdown = text .partition ("\n ---\n " )
190+ return frontmatter , markdown
191+
192+ return "" , text
0 commit comments