mosaic-headless 1.34.2 → 1.34.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/SKILL.md +18 -1
- package/assets/templates/platforms/claude-ai.json +1 -1
- package/assets/templates/platforms/claude-code.json +1 -1
- package/assets/templates/platforms/codex-cli.json +1 -1
- package/assets/templates/platforms/copilot.json +1 -1
- package/assets/templates/platforms/gemini-cli.json +1 -1
- package/package.json +1 -1
- package/tools/fix_inline_tags.py +161 -0
- package/tools/scan_inline_tags.py +87 -0
package/README.md
CHANGED
|
@@ -303,6 +303,8 @@ and heading level — and it earned its place at once: it caught the converter l
|
|
|
303
303
|
| `theme_export.php` / `theme_import.php` | a whole theme as JSON rows over WP-CLI, ids intact |
|
|
304
304
|
| `prune_unbound.php` | clears the templates and masters that page rebuilds leave bound to nothing, with their nodes; dry run unless `--apply` |
|
|
305
305
|
| `fix_text_runs.py` | makes buttons built before v1.34.1 editable in the Mosaic editor by wrapping their text the way the editor does; dry run unless `--apply` |
|
|
306
|
+
| `scan_inline_tags.py` | read only: finds text that holds HTML tags, which Mosaic 1.0.11+ prints as visible `<p>` / `<br>` on the page |
|
|
307
|
+
| `fix_inline_tags.py` | fixes what `scan_inline_tags.py` finds, turning the tags into real inline nodes; dry run unless `--apply` |
|
|
306
308
|
| `theme_zip.py` / `theme_zip_compare.php` / `theme_delete.php` | Mosaic's own ZIP export/import from outside the editor, the copy held against the source, and a clean delete that refuses the live theme |
|
|
307
309
|
| `list_fields.php` | every `@VAR` / `@LOOP` name a post's custom fields register, with values |
|
|
308
310
|
| `verify_dialog.py` | the 1.0.9 modal, triggers, run rules and memory, driven in a browser |
|
package/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: |
|
|
|
5
5
|
license: "MIT"
|
|
6
6
|
metadata:
|
|
7
7
|
author: "moksa (https://moksaweb.com)"
|
|
8
|
-
version: "1.34.
|
|
8
|
+
version: "1.34.4"
|
|
9
9
|
homepage: "https://github.com/Moksa1123/mosaic-headless"
|
|
10
10
|
---
|
|
11
11
|
|
|
@@ -879,6 +879,21 @@ with `tools/prune_unbound.php` (dry run by default) after a batch of rebuilds.
|
|
|
879
879
|
`inline_html.py` maps `<strong>`/`<em>` to styled `wysiwyg-span`s instead.
|
|
880
880
|
Through 1.0.10 the run was raw HTML instead, where a tag name in prose swallowed
|
|
881
881
|
the rest of the paragraph; `build_page.py` refuses any tag in a run either way.
|
|
882
|
+
**So a site built on 1.0.10 or earlier can start showing tags overnight**: the
|
|
883
|
+
plugin updates itself, the data does not change, and every `<p>`, `<br>` or
|
|
884
|
+
`<span>` written into a run now prints. Run `tools/scan_inline_tags.py` (read only)
|
|
885
|
+
before or after the update, on any site not built by `build_page.py` (another
|
|
886
|
+
converter, hand edits, an older helper). On the test theme it listed 179 runs on
|
|
887
|
+
the Elementor-converted `el-*` pages, and each listed page printed `<p>` while
|
|
888
|
+
the rest printed none. `tools/fix_inline_tags.py` then rewrites them in place
|
|
889
|
+
(dry run, then `--apply`): 179 fixed, 0 skipped, a second run found nothing, no
|
|
890
|
+
page printed a tag afterwards, and every page's visible text was identical.
|
|
891
|
+
One layout change to expect: a run that was `<p>…</p>` used to put a real `<p>`
|
|
892
|
+
inside the text node, and that `<p>` picked up the WordPress theme's own `p` rule
|
|
893
|
+
(here `margin:24px 0 0; font-size:16px; line-height:24px`), overriding the node's
|
|
894
|
+
own font size and line height. After the fix the node's own style applies, so
|
|
895
|
+
each such block lost 8-49px of height. Giving the node `tagName: p` does not
|
|
896
|
+
bring it back: Mosaic zeroes the margin on its own `p.m-text`.
|
|
882
897
|
- **`menu-link` is `width: fit-content` by default** (`.m-menu-link{display:flex;gap:4px;
|
|
883
898
|
padding:4px 8px;width:fit-content;…}`). Used as a cell of a button row or a grid -
|
|
884
899
|
a phone contact bar on `2fr 1fr 1fr` - its background hugs the text and the cell
|
|
@@ -950,6 +965,8 @@ with `tools/prune_unbound.php` (dry run by default) after a batch of rebuilds.
|
|
|
950
965
|
| `prune_unbound.php` | delete the templates no post is bound to, the masters no kept template uses, their nodes, then orphan nodes pass after pass - one theme, dry run unless `--apply`, `assign="auto"` templates kept |
|
|
951
966
|
| `theme_delete.php` | remove a theme completely through the plugin's own routine; refuses the live one |
|
|
952
967
|
| `fix_text_runs.py` | wrap text runs that sit directly under a button, menu-link or other non-text element (built before v1.34.1) in an Inherited text `text` node, so the editor can edit them - every master, template and component, through each document's own commit; dry run unless `--apply`, idempotent, component overrides kept |
|
|
968
|
+
| `scan_inline_tags.py` | read only: list every `wysiwyg-text` run whose text holds HTML tags (printed literally on 1.0.11+), with the nearest attrID above it, across every master, template and component - run it before or after a site updates from 1.0.10 |
|
|
969
|
+
| `fix_inline_tags.py` | rewrite those runs in place as `wysiwyg-span` / `-link` / `-linebreak` nodes (inline_html.py's mapping); a run that is one `<p>`/`<hN>` gives its tag to a text node that has none; lists, tables, images and mixed block/inline runs are skipped and listed; dry run unless `--apply`, idempotent |
|
|
953
970
|
| `verify_slider.py` | the slider in a real browser: does it advance, do the arrows and bullets drive it, does the keyboard, does it stop when motion is not wanted - `--label`/`--append` put several sliders in one table, which is where a carousel and a plain slider can be held against each other |
|
|
954
971
|
| `verify_navigation.py` | a multi-page site: is every menu item a real `<a href>`, does every page answer 200 (a template that was never bound answers 406 with an empty body, which only a logged-out visitor sees), and with `--viewports` does any page scroll SIDEWAYS - the one question no per-page checker asks - and whether every in-page `#fragment` resolves ON THE PAGE THAT CARRIES IT, which an HTTP check cannot see: a bare `#services` in a SHARED header fetches the current page, answers 200 everywhere, and does nothing on every page but the one that has that section |
|
|
955
972
|
| `verify_dialog.py` | the modal in a real browser (1.0.9 and 1.0.10 alike: open is read as `:popover-open` or `dialog.open`): does it open, close, answer Esc, remember, cap - and does an OpenStreetMap carry the coordinates it was given |
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"description": "Build and modify Mosaic Pro (Nextend) sites by writing the underlying data model directly - no visual editor, no DOM. Query the real surface (122 node types, 181 node properties, 101 style properties, 53 style states, 151 element classes, 74 dynamic variables, 114 REST routes, 23 tables) instead of guessing, with every node type placed on a live site one at a time and asserted against the delivered HTML, every style and node property swept against the compiled CSS and markup, and 569 responsive declarations checked against the stylesheet the site actually served.",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"author": "moksa (https://moksaweb.com)",
|
|
23
|
-
"version": "1.34.
|
|
23
|
+
"version": "1.34.4"
|
|
24
24
|
},
|
|
25
25
|
"loaderBehaviour": "Upload via Settings -> Skills -> Upload. Claude.ai parses SKILL.md frontmatter and surfaces the skill in your library. The extraction tool (extract-block-schema.php) needs a live WP-CLI connection and won't run in the sandbox; use it from a local terminal against your own site instead.",
|
|
26
26
|
"uploadSteps": [
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"description": "Build and modify Mosaic Pro (Nextend) sites by writing the underlying data model directly - no visual editor, no DOM. Query the real surface (122 node types, 181 node properties, 101 style properties, 53 style states, 151 element classes, 74 dynamic variables, 114 REST routes, 23 tables) instead of guessing, with every node type placed on a live site one at a time and asserted against the delivered HTML, every style and node property swept against the compiled CSS and markup, and 569 responsive declarations checked against the stylesheet the site actually served.",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"author": "moksa (https://moksaweb.com)",
|
|
23
|
-
"version": "1.34.
|
|
23
|
+
"version": "1.34.4"
|
|
24
24
|
},
|
|
25
25
|
"loaderBehaviour": "Auto-loads on session start when SKILL.md frontmatter parses successfully.",
|
|
26
26
|
"verified": true,
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"description": "Build and modify Mosaic Pro (Nextend) sites by writing the underlying data model directly - no visual editor, no DOM. Query the real surface (122 node types, 181 node properties, 101 style properties, 53 style states, 151 element classes, 74 dynamic variables, 114 REST routes, 23 tables) instead of guessing, with every node type placed on a live site one at a time and asserted against the delivered HTML, every style and node property swept against the compiled CSS and markup, and 569 responsive declarations checked against the stylesheet the site actually served.",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"author": "moksa (https://moksaweb.com)",
|
|
23
|
-
"version": "1.34.
|
|
23
|
+
"version": "1.34.4"
|
|
24
24
|
},
|
|
25
25
|
"loaderBehaviour": "Confirmed (2026-07-11): Codex CLI natively supports the SKILL.md spec. Place SKILL.md under .codex/skills/<name>/ (project) or ~/.codex/skills/<name>/ (personal) and Codex loads the name+description at session start, then the full body on demand. A parallel, broader convention .agents/skills/ (searched from cwd up to repo root, then ~/.agents/skills/) also exists across multiple tools - if your Codex CLI version prioritizes that path instead, mirror the same SKILL.md there.",
|
|
26
26
|
"verified": true,
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"description": "Build and modify Mosaic Pro (Nextend) sites by writing the underlying data model directly - no visual editor, no DOM. Query the real surface (122 node types, 181 node properties, 101 style properties, 53 style states, 151 element classes, 74 dynamic variables, 114 REST routes, 23 tables) instead of guessing, with every node type placed on a live site one at a time and asserted against the delivered HTML, every style and node property swept against the compiled CSS and markup, and 569 responsive declarations checked against the stylesheet the site actually served.",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"author": "moksa (https://moksaweb.com)",
|
|
23
|
-
"version": "1.34.
|
|
23
|
+
"version": "1.34.4"
|
|
24
24
|
},
|
|
25
25
|
"loaderBehaviour": "CHANGED as of 2026-07-11: GitHub Copilot added a proper '.github/skills/' Agent Skills directory (December 2025), alongside the older single-file .github/copilot-instructions.md convention. This config targets the new skills-directory form. If your Copilot version predates this (pre Dec 2025), use the instructions-append fallback instead (see fallback below).",
|
|
26
26
|
"fallback": {
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"description": "Build and modify Mosaic Pro (Nextend) sites by writing the underlying data model directly - no visual editor, no DOM. Query the real surface (122 node types, 181 node properties, 101 style properties, 53 style states, 151 element classes, 74 dynamic variables, 114 REST routes, 23 tables) instead of guessing, with every node type placed on a live site one at a time and asserted against the delivered HTML, every style and node property swept against the compiled CSS and markup, and 569 responsive declarations checked against the stylesheet the site actually served.",
|
|
21
21
|
"license": "MIT",
|
|
22
22
|
"author": "moksa (https://moksaweb.com)",
|
|
23
|
-
"version": "1.34.
|
|
23
|
+
"version": "1.34.4"
|
|
24
24
|
},
|
|
25
25
|
"loaderBehaviour": "CHANGED as of 2026-07-11: Gemini CLI now natively supports the same SKILL.md standard as Claude Code and Codex CLI - the same directory-based skill works unmodified. Gemini CLI discovers skills in this precedence order: built-in, extension skills, ~/.gemini/skills/ (personal), .gemini/skills/ (project, shared via version control). At session start Gemini injects each discovered skill's name+description into the system prompt and calls activate_skill when a task matches.",
|
|
26
26
|
"verified": true,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mosaic-headless",
|
|
3
|
-
"version": "1.34.
|
|
3
|
+
"version": "1.34.4",
|
|
4
4
|
"description": "AI-agent skill: build Mosaic Pro (Nextend) WordPress sites by writing the underlying data model directly - 23 custom tables, no visual editor, no DOM. Every node type, style property and node property swept against a live install and asserted on the delivered HTML and compiled CSS. Installs into Claude Code, Cursor, Codex CLI, Gemini CLI, Copilot, Continue, Windsurf and Claude.ai.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wordpress",
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""Rewrite text runs that hold HTML tags as the inline nodes Mosaic 1.0.11 renders.
|
|
3
|
+
|
|
4
|
+
python fix_inline_tags.py --config site.json # dry run: lists each change
|
|
5
|
+
python fix_inline_tags.py --config site.json --apply # commit, document by document
|
|
6
|
+
|
|
7
|
+
Why this exists
|
|
8
|
+
---------------
|
|
9
|
+
scan_inline_tags.py finds the runs; this fixes them in place. A run like
|
|
10
|
+
`<p>Call <a href="tel:1">us</a><br>today</p>` printed fine through 1.0.10 and prints
|
|
11
|
+
its tags as text on 1.0.11. Here it becomes
|
|
12
|
+
|
|
13
|
+
text (tagName p) > wysiwyg-text "Call " , wysiwyg-link(url) > wysiwyg-text "us",
|
|
14
|
+
wysiwyg-linebreak , wysiwyg-text "today"
|
|
15
|
+
|
|
16
|
+
using inline_html.py's mapping (strong/em/u/s -> styled wysiwyg-span, a -> link,
|
|
17
|
+
br -> linebreak, other inline tags unwrapped). When the whole run is one block
|
|
18
|
+
(`<p>...</p>`, `<h2>...</h2>`) and the text node around it has no tagName of its
|
|
19
|
+
own, that tag moves onto the text node, so the page keeps the element it had.
|
|
20
|
+
Several blocks in one run (`<p>a</p><p>b</p>`) are joined with a blank line
|
|
21
|
+
(two linebreaks): the text stays in one node, the paragraph margins do not.
|
|
22
|
+
|
|
23
|
+
Skipped and listed, never guessed: runs holding a list (`<ul>`/`<ol>`), a table, or
|
|
24
|
+
an image; runs under a component instance's override; runs whose parent is not a
|
|
25
|
+
`text` node. Those need a rebuild from source.
|
|
26
|
+
|
|
27
|
+
Every document on the theme is covered - masters, templates, components - through
|
|
28
|
+
each document's own commit, never SQL. Back up the wp_mosaic_* tables first.
|
|
29
|
+
"""
|
|
30
|
+
import mosaic_config
|
|
31
|
+
import argparse
|
|
32
|
+
import os
|
|
33
|
+
import sys
|
|
34
|
+
|
|
35
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
36
|
+
import inline_html # noqa: E402
|
|
37
|
+
from build_page import Surface, flatten # noqa: E402
|
|
38
|
+
from fix_text_runs import documents # noqa: E402
|
|
39
|
+
from scan_inline_tags import scan # noqa: E402
|
|
40
|
+
from sweep_node_types import Client, envelopes, exceptions_of # noqa: E402
|
|
41
|
+
|
|
42
|
+
# fractional-index digits; a key may not end in "0", so suffixes skip it
|
|
43
|
+
DIGITS = "123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
|
|
44
|
+
UNSUPPORTED = {"ul", "ol", "li", "table", "img", "picture", "video", "iframe", "svg",
|
|
45
|
+
"script", "style", "form", "input", "select", "textarea"}
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def _tags(nodes):
|
|
49
|
+
for n in nodes:
|
|
50
|
+
if isinstance(n, list):
|
|
51
|
+
yield n[0]
|
|
52
|
+
yield from _tags(n[2])
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def convert(text):
|
|
56
|
+
"""(inline spec children, block tag to give the parent or None) or (None, reason)."""
|
|
57
|
+
top = [n for n in inline_html._parse(text) if not (isinstance(n, str) and not n.strip())]
|
|
58
|
+
bad = sorted(set(_tags(top)) & UNSUPPORTED)
|
|
59
|
+
if bad:
|
|
60
|
+
return None, "holds " + ", ".join("<%s>" % t for t in bad)
|
|
61
|
+
blocks = [n for n in top if isinstance(n, list) and n[0] in inline_html.BLOCK]
|
|
62
|
+
if blocks and len(blocks) == len(top):
|
|
63
|
+
nested = [t for b in blocks for t in _tags(b[2]) if t in inline_html.BLOCK]
|
|
64
|
+
if nested:
|
|
65
|
+
return None, "nested blocks"
|
|
66
|
+
parts = [inline_html._inline(b[2]) for b in blocks]
|
|
67
|
+
out = []
|
|
68
|
+
for p in parts:
|
|
69
|
+
if out and p:
|
|
70
|
+
out += [{"type": "wysiwyg-linebreak", "data": {}},
|
|
71
|
+
{"type": "wysiwyg-linebreak", "data": {}}]
|
|
72
|
+
out += p
|
|
73
|
+
tag = blocks[0][0] if len(blocks) == 1 and blocks[0][0] in inline_html.TEXT_TAGS else None
|
|
74
|
+
return out, tag
|
|
75
|
+
if blocks:
|
|
76
|
+
return None, "block and inline content mixed"
|
|
77
|
+
return inline_html._inline(top), None
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def plan(nodes, surface):
|
|
81
|
+
"""Revision records for every fixable run, plus (run, reason) for the rest."""
|
|
82
|
+
live = {n["ID"]: n for n in nodes if n.get("status") != "delete"}
|
|
83
|
+
kids = {}
|
|
84
|
+
for n in live.values():
|
|
85
|
+
kids.setdefault(n.get("parentID"), []).append(n)
|
|
86
|
+
records, skipped, fixed = [], [], []
|
|
87
|
+
for run, _anchor, _tags_found in scan(nodes):
|
|
88
|
+
parent = live.get(run.get("parentID"))
|
|
89
|
+
if run.get("parentType") != "node" or not parent or parent["type"] != "text":
|
|
90
|
+
skipped.append((run, "parent is not a text node"))
|
|
91
|
+
continue
|
|
92
|
+
children, extra = convert(run["data"]["text"])
|
|
93
|
+
if children is None:
|
|
94
|
+
skipped.append((run, extra))
|
|
95
|
+
continue
|
|
96
|
+
base = run.get("ordering") or "a0"
|
|
97
|
+
if len(children) > len(DIGITS) or any(
|
|
98
|
+
s is not run and (s.get("ordering") or "").startswith(base)
|
|
99
|
+
for s in kids.get(parent["ID"], [])):
|
|
100
|
+
skipped.append((run, "no room in the sibling ordering"))
|
|
101
|
+
continue
|
|
102
|
+
new = []
|
|
103
|
+
for i, child in enumerate(children):
|
|
104
|
+
flatten(child, parent["ID"], run.get("documentID"), surface, False,
|
|
105
|
+
ordering=base + DIGITS[i], parent_type="text", out=new)
|
|
106
|
+
for r in new:
|
|
107
|
+
r["documentType"], r["documentID"] = run.get("documentType"), run.get("documentID")
|
|
108
|
+
records.append({"newRevisionRecord": r, "originalRevisionRecord": None})
|
|
109
|
+
records.append({"newRevisionRecord": dict(run, status="delete"),
|
|
110
|
+
"originalRevisionRecord": run})
|
|
111
|
+
pdata = parent.get("data") or {}
|
|
112
|
+
if extra and not pdata.get("tagName"):
|
|
113
|
+
records.append({"newRevisionRecord": dict(parent, data=dict(pdata, tagName=extra)),
|
|
114
|
+
"originalRevisionRecord": parent})
|
|
115
|
+
fixed.append((run, len(children), extra))
|
|
116
|
+
return records, fixed, skipped
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def main():
|
|
120
|
+
ap = argparse.ArgumentParser()
|
|
121
|
+
ap.add_argument("--config",
|
|
122
|
+
help="JSON with base/cookie/nonce/themeID; omit it and the MOSAIC_* environment variables supply them")
|
|
123
|
+
ap.add_argument("--apply", action="store_true", help="commit; without it nothing is written")
|
|
124
|
+
a = ap.parse_args()
|
|
125
|
+
sys.stdout.reconfigure(errors="replace")
|
|
126
|
+
client = Client(mosaic_config.load(a.config))
|
|
127
|
+
surface = Surface()
|
|
128
|
+
|
|
129
|
+
n_fixed = n_skipped = 0
|
|
130
|
+
for instance, key, label in documents(client):
|
|
131
|
+
resp = client.get(instance)
|
|
132
|
+
if "_httperror" in resp or "response" not in resp:
|
|
133
|
+
print(" skip %-40s (could not read)" % label)
|
|
134
|
+
continue
|
|
135
|
+
doc = resp["response"]
|
|
136
|
+
records, fixed, skipped = plan(doc.get(key) or [], surface)
|
|
137
|
+
if not fixed and not skipped:
|
|
138
|
+
continue
|
|
139
|
+
print("%s: %d fixed, %d skipped" % (label, len(fixed), len(skipped)))
|
|
140
|
+
for run, count, tag in fixed:
|
|
141
|
+
print(" fix %s -> %d node(s)%s" % (run["ID"][:8], count,
|
|
142
|
+
", parent tagName %s" % tag if tag else ""))
|
|
143
|
+
for run, why in skipped:
|
|
144
|
+
text = " ".join(run["data"]["text"].split())
|
|
145
|
+
print(" SKIP %s %s: %s" % (run["ID"][:8], why, text[:80]))
|
|
146
|
+
n_fixed += len(fixed)
|
|
147
|
+
n_skipped += len(skipped)
|
|
148
|
+
if a.apply and records:
|
|
149
|
+
err = exceptions_of(client.commit(instance, envelopes(doc), {key: records}))
|
|
150
|
+
if err:
|
|
151
|
+
sys.exit("commit failed on %s: %s" % (label, err[:400]))
|
|
152
|
+
|
|
153
|
+
print("%s %d run(s), skipped %d" % ("fixed" if a.apply else "would fix", n_fixed, n_skipped))
|
|
154
|
+
if n_fixed and not a.apply:
|
|
155
|
+
print("dry run - nothing written. Add --apply to commit.")
|
|
156
|
+
elif n_fixed:
|
|
157
|
+
print("purge the page cache, then re-run scan_inline_tags.py: it should list only the skipped runs.")
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
if __name__ == "__main__":
|
|
161
|
+
main()
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""List text runs that carry HTML tags - the runs Mosaic 1.0.11 prints as literal
|
|
3
|
+
`<span>` / `<br>` / `<a href=...>` on the page. Read only.
|
|
4
|
+
|
|
5
|
+
python scan_inline_tags.py --config site.json
|
|
6
|
+
|
|
7
|
+
Why this exists
|
|
8
|
+
---------------
|
|
9
|
+
Through 1.0.10 a `wysiwyg-text` run was output as raw HTML, so a site could carry
|
|
10
|
+
`<span class=...>`, `<a href=...>` or `<br>` inside its text and look right. 1.0.11
|
|
11
|
+
escapes the run (WysiwygTextNodeMResource::getEscapedText), and the plugin updates
|
|
12
|
+
itself, so those tags appear on the live page as visible text the moment the site
|
|
13
|
+
updates - with nothing in the data changing. build_page.py refuses tags in a run, so
|
|
14
|
+
pages it builds are clean; sites written by another builder, by hand, or by an older
|
|
15
|
+
converter may not be.
|
|
16
|
+
|
|
17
|
+
Run it before updating a site to 1.0.11, or after, to find what already shows tags.
|
|
18
|
+
Rebuild the listed nodes with inline nodes (wysiwyg-span / -link / -linebreak, see
|
|
19
|
+
inline_html.py) - the scan points at them; it does not rewrite anything.
|
|
20
|
+
"""
|
|
21
|
+
import mosaic_config
|
|
22
|
+
import argparse
|
|
23
|
+
import os
|
|
24
|
+
import sys
|
|
25
|
+
|
|
26
|
+
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
|
|
27
|
+
from build_page import PROSE_TAG # noqa: E402
|
|
28
|
+
from fix_text_runs import documents # noqa: E402
|
|
29
|
+
from sweep_node_types import Client # noqa: E402
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def scan(nodes):
|
|
33
|
+
"""(run, nearest ancestor with an attrID or None, tags found) for each tagged run."""
|
|
34
|
+
live = {n["ID"]: n for n in nodes if n.get("status") != "delete"}
|
|
35
|
+
out = []
|
|
36
|
+
for n in live.values():
|
|
37
|
+
if n["type"] != "wysiwyg-text":
|
|
38
|
+
continue
|
|
39
|
+
text = (n.get("data") or {}).get("text")
|
|
40
|
+
if not isinstance(text, str):
|
|
41
|
+
continue
|
|
42
|
+
tags = PROSE_TAG.findall(text)
|
|
43
|
+
if not tags:
|
|
44
|
+
continue
|
|
45
|
+
anchor, p = None, live.get(n.get("parentID"))
|
|
46
|
+
while p is not None and anchor is None:
|
|
47
|
+
if (p.get("data") or {}).get("attrID"):
|
|
48
|
+
anchor = p
|
|
49
|
+
p = live.get(p.get("parentID"))
|
|
50
|
+
out.append((n, anchor, tags))
|
|
51
|
+
return out
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def main():
|
|
55
|
+
ap = argparse.ArgumentParser()
|
|
56
|
+
ap.add_argument("--config",
|
|
57
|
+
help="JSON with base/cookie/nonce/themeID; omit it and the MOSAIC_* environment variables supply them")
|
|
58
|
+
a = ap.parse_args()
|
|
59
|
+
# page text goes to the console as-is; a cp950/cp1252 console must not end the scan
|
|
60
|
+
sys.stdout.reconfigure(errors="replace")
|
|
61
|
+
client = Client(mosaic_config.load(a.config))
|
|
62
|
+
|
|
63
|
+
total = 0
|
|
64
|
+
for instance, key, label in documents(client):
|
|
65
|
+
resp = client.get(instance)
|
|
66
|
+
if "_httperror" in resp or "response" not in resp:
|
|
67
|
+
print(" skip %-40s (could not read)" % label)
|
|
68
|
+
continue
|
|
69
|
+
hits = scan(resp["response"].get(key) or [])
|
|
70
|
+
if not hits:
|
|
71
|
+
continue
|
|
72
|
+
total += len(hits)
|
|
73
|
+
print("%s: %d run(s)" % (label, len(hits)))
|
|
74
|
+
for n, anchor, tags in hits:
|
|
75
|
+
where = "#%s" % anchor["data"]["attrID"] if anchor else "(no attrID above)"
|
|
76
|
+
text = " ".join(n["data"]["text"].split())
|
|
77
|
+
print(" %s %-24s %s" % (n["ID"][:8], where, text[:100] + ("..." if len(text) > 100 else "")))
|
|
78
|
+
print(" tags: %s" % " ".join(sorted(set(t.split()[0].rstrip(">") + ">" for t in tags))))
|
|
79
|
+
|
|
80
|
+
print("%d run(s) with HTML tags%s" % (total, "" if total else " - nothing prints a literal tag"))
|
|
81
|
+
if total:
|
|
82
|
+
print("On 1.0.11+ these print the tags as text. Rebuild them as wysiwyg-span / -link / "
|
|
83
|
+
"-linebreak nodes (inline_html.py turns an HTML fragment into those).")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
main()
|