Skip to content

[3.0] Theme split (wave 1, part 1) — Emit code blocks as <pre><code> and build their buttons in JS - #9332

Open
albertlast wants to merge 2 commits into
SimpleMachines:release-3.0from
albertlast:3.0/theme-code-bbc
Open

[3.0] Theme split (wave 1, part 1) — Emit code blocks as <pre><code> and build their buttons in JS#9332
albertlast wants to merge 2 commits into
SimpleMachines:release-3.0from
albertlast:3.0/theme-code-bbc

Conversation

@albertlast

@albertlast albertlast commented Aug 1, 2026

Copy link
Copy Markdown
Collaborator

Wave 1, part 1 of breaking up #7933, as requested there. Supersedes #8891, which does the same thing but has gone stale (it still names scripts/jquery.sceditor.smf.js, renamed since to sceditor.plugins.smf.js).

This one changes no theme templates beyond the error log, which is forced — see below.

What changes

The code BBCode wrapped its content in a bare <code class="bbc_code"> and emitted the "Select" and "Expand" links from PHP, even when there was no JavaScript to make them work. Tabs and leading/trailing line breaks then had to be patched up by hand, in both the parser and the editor.

Now the content goes in a <pre>, so the browser preserves the whitespace, and the button labels ride along as data attributes:

<div class="codeheader">Code (php)</div>
<pre data-select-txt="Select" data-shrink-txt="Shrink" data-expand-txt="Expand" class="bbc_code"><code></code></pre>

script.js builds the buttons from those attributes in a new attachBbCodeEvents(parent), which means:

  • they only appear when they can actually do something;
  • "Expand" only appears when the block really is taller than its maximum height, rather than being emitted hidden and unhidden afterwards;
  • the AJAX post preview re-attaches them by calling the same function, instead of rebinding a jQuery handler.

smfSelectText() has no callers left, so it goes. UpgradeTemplate.php used it as its "did script.js load?" probe and now checks for attachBbCodeEvents instead.

Consumers migrated

The old markup had more consumers than just the BBCode, and all of them break if the handlers go. Removing them without these would have left dead buttons behind:

  • Themes/default/Errors.template.php — the error log builds its own code block by hand. This is the one theme template touched, and it is unavoidable.
  • ssi_examples.php — 33 blocks using inline onclick="return smfSelectText(this);".
  • Sources/Tasks/ExportProfileData.php — stripped the <a class="codeoperation"> links out of exports. There are no links now, so it strips the data attributes instead, since an export has no JavaScript to use them.

.codeoperation is gone from index.css along with the ::before/::after that supplied the [ ]; the JS adds those. .reset is added so the generated <button>s can be styled as links.

Two deliberate deviations from #7933 / #8891

  1. [code=php] highlighting is kept. Both branches drop the $add_begin handling, which wraps a snippet lacking <?php so highlight_string() will colour it, then unwraps it again. That is a behaviour change unrelated to the markup, so I have left it in place. It only ever applied to Code2, since Code1 has no attribute to inspect, so Code1 keeps the simplified version.
  2. A pre-existing editor bug is fixed. jquery.sceditor.default.css set an explicit text-align on the code block. SCEditor reads that back as an alignment, so [code]x[/code] round-tripped through the WYSIWYG as [left][code]x[/code][/left]. Dropping the declaration fixes it, and matches what [3.0] Theme #7933 does.

Testing

  • 108/108 unit tests pass.
  • Parser output checked for [code], [code=php] with and without an explicit <?php, and [code=SQL]; PHP colouring and the language title both still work.
  • Topic view: a short block gets "Select" only, a long one gets "Select" and "Expand", and expanding toggles 307px ↔ 753px and back.
  • SSI examples page: all 33 blocks get a working "Select", no console errors.
  • Error log: "Select" and "Expand" both present and working.
  • Editor: [code] and [code=php] round-trip unchanged in both directions, tabs and blank lines survive, and the Code: / Code: (php) label still renders.

🤖 Generated with Claude Code

albertlast and others added 2 commits August 1, 2026 08:04
…and build their buttons in JS

The code BBCode wrapped its content in a bare <code class="bbc_code">, and
emitted the "Select" and "Expand" links from PHP even when JavaScript was
unavailable to make them work. Tabs and leading/trailing line breaks had to
be fixed up by hand, in both the parser and the editor.

Wrap the content in a <pre> instead, so the browser preserves the whitespace,
and pass the button labels along as data attributes. script.js now builds the
buttons from those attributes, which means they only appear when they can
actually do something, and the "Expand" button only appears when the block is
taller than its maximum height.

Migrates every consumer of the old markup: the error log, the SSI examples
page, and the profile export. smfSelectText() has no callers left, so it goes;
UpgradeTemplate.php probes for attachBbCodeEvents() instead to detect whether
script.js loaded.

Wave 1, part 1 of breaking up SimpleMachines#7933. Supersedes SimpleMachines#8891.

Co-Authored-By: John Rayes <live627@gmail.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…eft]

Two things surfaced while testing the previous commit.

[code=php] on a snippet that omits the opening tag used to be wrapped in
<?php ... ?> so highlight_string() would colour it, then unwrapped again.
That is unrelated to the markup change, so restore it. It only ever applied
to Code2, since Code1 has no attribute to inspect.

The editor stylesheet set an explicit text-align on the code block. SCEditor
reads that back as an alignment and round-tripped [code]x[/code] as
[left][code]x[/code][/left]. Dropping the declaration fixes it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@albertlast albertlast changed the title [3.0] Emit code blocks as <pre><code> and build their buttons in JS [3.0] Theme split 1/24 — Emit code blocks as <pre><code> and build their buttons in JS Aug 1, 2026
@albertlast albertlast mentioned this pull request Aug 1, 2026
@albertlast albertlast changed the title [3.0] Theme split 1/24 — Emit code blocks as <pre><code> and build their buttons in JS [3.0] Theme split (wave 1, part 1) — Emit code blocks as <pre><code> and build their buttons in JS Aug 1, 2026
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.

1 participant