File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2626import re
2727from typing import Optional
2828from typing import List
29+ from typing import Tuple
2930
3031import requests
3132import toml
@@ -164,3 +165,30 @@ def __lt__(self, other):
164165 )
165166
166167 return affected_package_with_patched_package_objects
168+
169+
170+ def split_markdown_front_matter (text : str ) -> Tuple [str , str ]:
171+ r"""
172+ Split text into markdown front matter and the markdown body
173+ Returns ("", text) for text with non existing front matter
174+
175+ >>> text='''---
176+ ... title: DUMMY-SECURITY-2019-001
177+ ... description: Incorrect access control.
178+ ... cves: [CVE-2042-1337]
179+ ... ---
180+ ... # Markdown starts here
181+ ... '''
182+ >>> 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')
184+ """
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
You can’t perform that action at this time.
0 commit comments