Files
LithosAnanke/site/colorlock.py
T
Claude 3bd81097e1 chore(license): an SPDX header on every source file that had none (LicenseRef-Starship-1.0) [skip ci]
The header scan (Captain Bob, 2026-11-10): 788 source files -- 351 with the
SL-1.0 header, 12 with the old name (docs/working/experiments, kept by
ruling), 31 under someone else's licence (tools/kconfig, Linux's, GPL-2.0:
kept), and 394 with none. Ruled: the SPDX form; capsules (.4th, .f18) and
proofs (.thy) left for a ruling of their own (mkcapsule's 64x16 block format,
content-addressed capsules).

253 files now begin
    SPDX-License-Identifier: LicenseRef-Starship-1.0
    Copyright (c) 2023-2026 Robert A. James
as a /* */ block (C, headers, assembly, linker scripts) or # lines (scripts,
Makefiles, Kconfig; below a shebang or a coding line); tools/mkcapsule.c,
which had the copyright line, gets the SPDX line only.

Not touched: docs/working/ (archive and old campaign material, as the
ruling kept the experiments); v4/system/post_cases.c (generated by
v4/tools/mkpost.py, "do not edit" -- the generator has the header).

Comments only: the kernel builds on amd64, aarch64, riscv64; make -C v4
test-32: 39 programs, 0 failures; every changed script parses.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GE3SDvQn5EoxdGufk84zz2
2026-11-10 04:12:49 +00:00

67 lines
3.5 KiB
Python

# SPDX-License-Identifier: LicenseRef-Starship-1.0
# Copyright (c) 2023-2026 Robert A. James
"""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 = """<style>
.ssos, .ssos *, .ssos *::before, .ssos *::after { background-color: transparent !important; color: inherit !important; border-color: #22324D !important; }
.ssos a, .ssos a * { color: #F5891F !important; }
.ssos a:hover { color: #FFB061 !important; }
.ssos input, .ssos textarea, .ssos select { background-color: #0A1222 !important; color: #EEF2F7 !important; border-color: #34486A !important; }
.ssos ::placeholder { color: #A3AEC2 !important; opacity: 1 !important; }
.ssos img { background-color: transparent !important; }
</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. '<div style="background: #0A1222'."""
assert html.count(root_marker) >= 1, root_marker
html = html.replace(root_marker, root_marker.replace("<div ", '<div class="%s" ' % ROOT_CLASS, 1), 1)
html = re.sub(r'style="([^"]*)"', _lock_style, html)
return STYLE + "\n" + html
# For visitors (guests) only, the page is the design alone: XWiki's own chrome -- the top bar with
# Register and Log-in, the breadcrumb, the title and "Last modified", the page menu, the side panels,
# the footer and the welcome tour -- is hidden, and the design runs the full width. Logged in, the
# wiki is all there, to edit with. (Captain Bob, 2026-11-07: "Menu bar".)
GUEST_CHROME = """{{velocity}}
#if ($isGuest)
#[[{{html clean="false"}}<style>
#menuview, #hierarchy_breadcrumb, .document-header, #xdocFooter, #footerglobal, #leftPanels, #rightPanels,
#leftPanelsToggle, #rightPanelsToggle, .tour, .tour-backdrop, #bootstrap_tour_restart, .xtour-restart,
#xwikimaincontainerinner > a.btn { display: none !important; }
html, body, #xwikimaincontainer, #xwikimaincontainerinner, #contentcontainer, #contentcolumn, .main,
#mainContentArea, #xwikicontent, #mainContentArea .row { background-color: #0A1222 !important; }
#contentcontainer, #contentcolumn, .main, #mainContentArea, #xwikicontent, #mainContentArea .row {
width: 100% !important; max-width: none !important; margin: 0 !important; padding: 0 !important; border: 0 !important; float: none !important; }
#xwikicontent > .ssos { border: 0 !important; }
#xwikimaincontainer { padding: 0 !important; }
.main hr:not(.ssos hr), #xwikicontent > :not(.ssos) { display: none !important; }
</style>{{/html}}]]#
#end
{{/velocity}}
"""