"""colorlock.py -- keep a page's own colours inside a wiki whose theme forces its own. Both XWikis carry a high-contrast theme (skins/flamingo/cssVariablesInit.css on the server) that sets every element black on white with !important. On our pages the design's colours win instead (Captain Bob, 2026-11-07), and on those pages only; the rest of the wiki keeps the theme: - every colour an element states in its style="" is made !important -- an inline !important beats any stylesheet's; - a stylesheet scoped to the page's root (class "ssos") covers the elements that state no colour: ".ssos *" outranks the theme's "*" (both !important, the more specific wins). """ import re ROOT_CLASS = "ssos" STYLE = """""" COLOUR_PROPS = re.compile(r"^\s*(color|background|background-color|border|border-(top|right|bottom|left)|" r"border-color|border-(top|right|bottom|left)-color|accent-color|fill)\s*:", re.I) def _lock_style(m): decls = [] for d in m.group(1).split(";"): if d.strip() and COLOUR_PROPS.match(d) and "!important" not in d: d = d.rstrip() + " !important" decls.append(d) return 'style="%s"' % ";".join(decls) def lock(html, root_marker): """root_marker: the opening text of the page's root element, e.g. '