link title to proposal
This commit is contained in:
@@ -10,6 +10,7 @@ from pathlib import Path
|
||||
|
||||
|
||||
TITLE_RE = re.compile(r'<div id="block-pagetitle".*?<h1 class="page-title"><span[^>]*>(.*?)</span>.*?</h1>', re.DOTALL)
|
||||
CANONICAL_RE = re.compile(r'<link rel="canonical" href="([^"]+)"\s*/?>', re.DOTALL)
|
||||
SESSION_RE = re.compile(
|
||||
r'<details[^>]*id="edit-group-session"[^>]*>.*?<div class="details-wrapper">(.*?)</div>\s*</details>',
|
||||
re.DOTALL,
|
||||
@@ -133,14 +134,22 @@ def extract_title(source: str) -> str:
|
||||
return normalize_text(title_match.group(1))
|
||||
|
||||
|
||||
def extract_canonical_url(source: str) -> str:
|
||||
canonical_match = CANONICAL_RE.search(source)
|
||||
if not canonical_match:
|
||||
raise ValueError('Could not find canonical URL for proposal page')
|
||||
return html.unescape(canonical_match.group(1)).strip()
|
||||
|
||||
|
||||
def extract_markdown(source: str) -> tuple[str, str]:
|
||||
title = extract_title(source)
|
||||
canonical_url = extract_canonical_url(source)
|
||||
session_match = SESSION_RE.search(source)
|
||||
if not session_match:
|
||||
raise ValueError('Could not find session details block by id edit-group-session')
|
||||
|
||||
details_html = session_match.group(1)
|
||||
sections: list[str] = [f'# {title}']
|
||||
sections: list[str] = [f'# [{title}]({canonical_url})']
|
||||
|
||||
for classes, body in extract_field_blocks(details_html):
|
||||
label_match = LABEL_RE.search(body)
|
||||
|
||||
Reference in New Issue
Block a user