File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919# for any legal advice.
2020# VulnerableCode is a free software from nexB Inc. and others.
2121# Visit https://github.com/nexB/vulnerablecode/ for support and download.
22-
2322import json
2423import re
24+ from typing import Tuple
2525
2626import requests
2727import toml
@@ -106,3 +106,30 @@ def contains_alpha(string):
106106 """
107107
108108 return any ([c .isalpha () for c in string ])
109+
110+
111+ def split_markdown_front_matter (text : str ) -> Tuple [str , str ]:
112+ r"""
113+ Split text into markdown front matter and the markdown body
114+ Returns ("", text) for text with non existing front matter
115+
116+ >>> text='''---
117+ ... title: DUMMY-SECURITY-2019-001
118+ ... description: Incorrect access control.
119+ ... cves: [CVE-2042-1337]
120+ ... ---
121+ ... # Markdown starts here
122+ ... '''
123+ >>> split_markdown_front_matter(text)
124+ ('title: DUMMY-SECURITY-2019-001\ndescription: Incorrect access control.\ncves: [CVE-2042-1337]\n', '\n# Markdown starts here\n')
125+ """
126+
127+ front_matter = ""
128+ body = text
129+ text = text .replace ("\r \n " , "\n " )
130+ linezero ,_ , text = text .partition ("---\n " )
131+
132+ if not linezero : # nothing before first ---
133+ front_matter ,_ , body = text .partition ("---" )
134+
135+ return front_matter , body
You can’t perform that action at this time.
0 commit comments