"""Glue between the page and Groundline. Runs inside the browser (Pyodide); Groundline's own code is loaded from GitHub.""" import html import json import os from groundline.checks import check_all from groundline.cli import draft_sentences from groundline.report import LABEL, METHOD_HINT, METHOD_TITLE, counts, methodology_body, to_html, to_markdown from groundline.text import passages_from TONE = {"matched": "green", "check": "amber", "no match": "red", "contradicted": "purple"} def run(source_paths_json, names_json, draft_path): e = html.escape paths, names = json.loads(source_paths_json), json.loads(names_json) try: passages = passages_from(paths) except (SystemExit, Exception): return json.dumps({"error": "One of the source files could not be read. Check it opens normally, or paste its text instead."}) if not passages: return json.dumps({"error": "No text was found in the sources. Scanned PDFs need OCR first."}) results = check_all(draft_sentences(draft_path), passages) c = counts(results) out = ['