""" Renderer module that generates an HTML/iframe component embedding conllu.js from simon-clematide/conllu.js. Supports: - Interactive dependency visualization with brat - Download SVG and Download PNG buttons (from simon-clematide work journal) - Clean, self-contained iframe to prevent any script collision """ import html from pathlib import Path from visualizer.ud_help import render_ud_help from visualizer.grew_links import render_grew_word_links PARSER_REVISION = "e46fe3cb6b1a02190c17c1b792f1f1ded42ddd2f" RENDERER_REVISION = "e8fc85df554a50338b68d1920d7414980a5d0c11" ASSET_ROOT = f"https://cdn.jsdelivr.net/gh/simon-clematide/conllu.js@{RENDERER_REVISION}/" PARSER_URL = f"https://cdn.jsdelivr.net/gh/simon-clematide/conllu.js@{PARSER_REVISION}/conllu.js" def build_visualizer_document( conllu_text: str, title: str = "", show_help: bool = False, model_id: str = None ) -> str: """ Returns the standalone HTML document that renders one CoNLL-U input. The UI embeds it as iframe srcdoc; the exporter loads it in a headless browser. """ adapter_js = ( Path(__file__).with_name("embed.js").read_text(encoding="utf-8") .replace("__PARSER_URL__", PARSER_URL) .replace("__RENDERER_ROOT__", ASSET_ROOT) ) escaped_conllu = html.escape(conllu_text) title_escaped = html.escape(title) word_links = render_grew_word_links(conllu_text, model_id, as_column=show_help) help_html = render_ud_help(conllu_text, word_links) if show_help else "" grew_html = "" if show_help else word_links stylesheets = "\n".join( f'' for path in ("css/jquery-ui-redmond.css", "css/style-vis.css") ) iframe_doc = """
""" + stylesheets + """Loading visualization…
""" return iframe_doc def render_conllu_visualizer_html( conllu_text: str, vis_id: str = "vis-main", title: str = "", min_height: int = 280, show_help: bool = False, model_id: str = None ) -> str: """ Renders an HTML iframe hosting the conllu.js visualizer. Using an iframe ensures zero CSS/JS namespace contamination with Gradio. """ if not conllu_text or not conllu_text.strip(): return "