from typing import List
from typing import Dict


def _parseMarkdownSections(text: str, sectionNames: List[str]) -> 'Dict[str, str]':
	"""
	Splits apart markdown into blocks with titles using level 2 headers (`## Foo`)
	:return: dict of title -> body. There may be an empty title for the first section.
	"""
	text = text and text.strip()
	if not text:
		return {}
	if '## ' not in text:
		return {'': text}
	sections = []
	title = ''
	body = ''
	for line in text.splitlines(keepends=True):
		if line.startswith('## ') and line[3:].strip() in sectionNames:
			if body:
				sections.append((title, body.strip()))
			title = line[3:].strip()
			body = ''
		else:
			body += line
	if body:
		sections.append((title, body.strip()))
	return {
		section[0]: section[1]
		for section in sections
	}