Skip to content

Parse shortcode attributes without creating DOM nodes; match names with digits (#11) - #13

Merged
micschk merged 10 commits into
mainfrom
fix/attribute-parsing
Nov 2, 2026
Merged

micschk merged 10 commits into
mainfrom
fix/attribute-parsing

Conversation

@micschk

@micschk micschk commented Nov 2, 2026

Copy link
Copy Markdown
Member

Release 5.2.1.

  • Attributes of a shortcode selected in the editor are parsed in an inert document instead of as an element in the CMS document; placeholdersToShortcodes() uses the same inert document. Values, entities and lower-cased names come out as before (specs/selection.spec.ts).
  • Placeholder pattern matches whole shortcode names, \w+ ending at whitespace or ] (fixes Editor rewrites [name2] to [name 2] on save; names with digits get no placeholder #11, specs/names.spec.ts). Deliberate behaviour change: no trailing space in a no-attribute shortcode's placeholder title and ?sc=; the editor spec's expected title and width are updated in their own commit, citing Editor rewrites [name2] to [name 2] on save; names with digits get no placeholder #11.
  • composer.json licence MIT (matches license.md); UPGRADING corrected on which simpler a Silverstripe 5 install gets; unreferenced docs/screens/*.png removed.
  • CHANGELOG 5.2.1.

Tests first, each failing on the old code (ss5 and ss6) before its fix. Local browser suite: 52/52 on ss5 and ss6.

Closes #11

Pair-programmed with my buddy Claude

A shortcode selected as text when the dialog opens has its attributes read without creating any
element in the CMS document: a handler attribute must never run and a src must never be fetched.
Plus a regression guard that quoted, unquoted, entity and non-ASCII values and lower-cased names
come out as before.

Fails on the current code (ss5 and ss6): the handler runs. The parsing guard passes.

Pair-programmed with my buddy Claude
getCurrentEditorSelectionAsParsedShortcodeData() read a selected shortcode's attributes by
building it as an element with jQuery, which creates that element in the live CMS document. The
attributes are now parsed in an inert document (document.implementation.createHTMLDocument),
under a fixed tag name; values, entities and lower-cased names come out as before.
placeholdersToShortcodes() rewrites the editor HTML in the same inert document instead of a live
wrapper. dist rebuilt.

Browser suite 48/48 on ss5 and ss6, including the new selection specs.

Pair-programmed with my buddy Claude
[scb_year2] must stay [scb_year2] on save (not become [scb_year 2]), a registered name with a
digit (h2_title) gets a placeholder, [button-large] does not match button, and a shortcode
without attributes has no trailing space in its placeholder title.

Fails on the current code (ss5 and ss6): [scb_year2] gets the scb_year placeholder, h2_title gets
none, titles are "scb_year 2", "button -large" and "scb_year ".

Pair-programmed with my buddy Claude
shortcodesToPlaceholders() now matches names as ShortcodeParser does, \w+ ending at whitespace or
']': /\[(\w+)(?:\s+([^\]]*))?\]/g. [year2] is no longer taken for [year] and saved back as
[year 2], [button-large] no longer matches button, and a registered name with a digit gets its
placeholder. A shortcode without attributes has no trailing space in its placeholder title and
?sc= any more ([year] rather than [year ]), so its default placeholder is one character narrower.
dist rebuilt.

The editor spec that expects title "scb_year " and a 157 px placeholder now fails on purpose; its
expected values are updated in the next commit.

Pair-programmed with my buddy Claude
)

Deliberate behaviour change, decided in issue #11 (which named this spec): a shortcode without
attributes is now "[scb_year]" in the placeholder, not "[scb_year ]". Expected title "scb_year"
(was "scb_year ") and width 60 + floor(16 / 1.8 * 10) = 148 px (was 157 px for 11 characters).
Nothing else in the spec changes. Suite 52/52 on ss5 and ss6.

Pair-programmed with my buddy Claude
simpler 1.0.0 requires framework ^5 || ^6, so the ~0.2 || ^1 constraint resolves to 1.x on a fresh install or an update that includes simpler; ~0.2 only lets an existing 0.2/0.3 install stay. The README already says so.

Pair-programmed with my buddy Claude
button.png and dialog.png are no longer used by the README, which has its own generated screenshots in docs/images. Only a commented-out rule in shortcodable.scss still names button.png; it is left as it is.

Pair-programmed with my buddy Claude
Pair-programmed with my buddy Claude
The selection specs (added in this branch) selected with ControlOrMeta+A. On CI (Linux) Control+A
selects the whole <p>, whose content does not start with '[', so nothing was parsed: the
attribute spec failed and the probe spec passed without testing anything. The text node is now
selected with TinyMCE's selection API, the probe spec first asserts the shortcode was parsed, and
the handler and fetch probes are separate cases (one shortcode per selection; a second one only
added junk attributes, so its src could never be fetched).

Must-fail re-checked on the pre-fix client code (66aa785): both probe cases fail on ss5 and ss6
(handler ran; src fetched). With the fix: 54/54.

Pair-programmed with my buddy Claude
@micschk
micschk merged commit 1e3174c into main Nov 2, 2026
9 checks passed
@micschk
micschk deleted the fix/attribute-parsing branch November 2, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Editor rewrites [name2] to [name 2] on save; names with digits get no placeholder

1 participant