From c4d0c0e9daa49a9c742a6000cfe231965b247444 Mon Sep 17 00:00:00 2001 From: Julian Stirling Date: Tue, 10 Mar 2026 15:25:04 +0000 Subject: [PATCH] Explicit header, text and bullet blocks rather than one HTML block in ui spec --- .../things/scan_workflows.py | 9 ++- src/openflexure_microscope_server/ui.py | 60 +++++++++++-------- .../data/html_sanitisation_test_cases.md | 13 +++- tests/unit_tests/test_scan_workflows.py | 29 +++++---- .../serverSpecifiedInterface.vue | 12 +++- 5 files changed, 82 insertions(+), 41 deletions(-) diff --git a/src/openflexure_microscope_server/things/scan_workflows.py b/src/openflexure_microscope_server/things/scan_workflows.py index 7679207a..1bf5b826 100644 --- a/src/openflexure_microscope_server/things/scan_workflows.py +++ b/src/openflexure_microscope_server/things/scan_workflows.py @@ -42,7 +42,8 @@ from openflexure_microscope_server.things.stage import BaseStage from openflexure_microscope_server.ui import ( UI_ELEMENT_RESPONSE, Accordion, - HTMLBlock, + HeaderBlock, + TextBlock, UIElementList, action_button_for, property_control_for, @@ -642,7 +643,8 @@ class HistoScanWorkflow(RectGridWorkflow[HistoScanSettingsModel]): return UIElementList( [ - HTMLBlock(html=f"

{self.display_name}

{self.ui_blurb}

"), + HeaderBlock(text=self.display_name, level=4), + TextBlock(text=self.ui_blurb), Accordion(title="Background Detect", children=background_ui), Accordion( title="Scan Settings", @@ -750,7 +752,8 @@ class RegularGridWorkflow(RectGridWorkflow[RegularGridSettingsModel]): ) return UIElementList( [ - HTMLBlock(html=f"

{self.display_name}

{self.ui_blurb}

"), + HeaderBlock(text=self.display_name, level=4), + TextBlock(text=self.ui_blurb), Accordion( title="Scan Settings", children=scan_settings, diff --git a/src/openflexure_microscope_server/ui.py b/src/openflexure_microscope_server/ui.py index b6692785..2524515e 100644 --- a/src/openflexure_microscope_server/ui.py +++ b/src/openflexure_microscope_server/ui.py @@ -5,24 +5,12 @@ from html.parser import HTMLParser from typing import Annotated, Any, Literal, Optional from urllib.parse import urlparse -from pydantic import BaseModel, BeforeValidator, RootModel +from pydantic import BaseModel, BeforeValidator, Field, RootModel import labthings_fastapi as lt -ALLOWED_TAGS = { - "p", - "i", - "b", - "h1", - "h2", - "h3", - "h4", - "h5", - "h6", - "ul", - "li", - "a", -} +# Only allowed tags are italic, bold, and link. Also allows self closing br tags. +ALLOWED_TAGS = {"i", "b", "a"} ALLOWED_SCHEMES = {"http", "https"} @@ -116,8 +104,7 @@ class SafeHTMLParser(HTMLParser): def sanitise_html(html: str) -> str: """Santitise HTML to only have a small list of allowed tags. - Tags allowed without attrs: ``

, , ,

,

,

,

,

,
,`` - ``