INNER CODE UNIT · Python
load_markdown_text
crocs-muni/javacard-curated-list · scripts/process_curated_list.py:38
def load_markdown_text(source):
if source.startswith("http://") or source.startswith("https://"):
text = fetch_url(source)
else:
with open(source, encoding="utf-8") as f:
text = f.read()
return text.replace("\r\n", "\n").replace("\r", "\n")
# ---------------------------------------------------------------------------
# Step 2: parse the markdown into individual repository entries
# ---------------------------------------------------------------------------
ENTRY_RE = re.compile(r"^- \[(?P<name>.+?)\]\((?P<link>[^)]+)\)(?P<rest>.*)$")
GITHUB_RE = re.compile(r"github\.com/+([A-Za-z0-9_.\-]+)/+([A-Za-z0-9_.\-]+)")
MANUAL_LASTCOMMIT_RE = re.compile(r"last commit\s+(\d{4})", re.IGNORECASE)
HOST_RE = re.compile(r"https?://(?:www\.)?([a-zA-Z0-9.\-]+)")