import re


def parse_release_notes(version: str, content: str) -> str:
	"""
	Parses Go version release notes.

	>>> raw = '''<html lang="en-US"><head><title>test</title></head><body>
	... <h1>Big Title</h1>
	... <script>"use strict";</script>
	... <div><section><p>
	... 	go4.15.5 text before
	... </p></section></div>
	... <div><section><p>
	... 	go4.15.6 The expected release notes
	... </p></section></div>
	... <div><section><p>
	... 	go4.15.7 text after
	... </p><section></div>
	... <style>* { display: none; }</style>
	... </body></html>'''
	>>> parse_release_notes("4.15.6", raw)
	'<p> go4.15.6 The expected release notes </p>'
	>>> raw = '''<html lang="en-US"><head><title>test</title></head><body>
	... go4.15.6 is mentioned earlier
	... go4.15.6 before on the same line as the opening tag <p>
	... go4.15.6 the actual notes.
	... </p>go4.15.6 later on the same line as the closing tag
	... go4.15.6 in a later context
	... </body></html>'''
	>>> parse_release_notes("4.15.6", raw)
	'<p> go4.15.6 the actual notes. </p>'
	"""
	go_version_pattern = version.replace('.', r"\.")
	release_notes_pattern = re.compile(
		r"<p>\s*\n\s*go" + go_version_pattern + r".*?</p>",
		re.MULTILINE | re.DOTALL
	)
	matches = release_notes_pattern.search(content)
	if not matches:
		raise Exception(f'could not find release notes for Go {version}')
	return " ".join(matches.group(0).split())