[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
Open
Conversation
…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>
Open
albertlast
force-pushed
the
3.0/theme-code-bbc
branch
from
August 1, 2026 07:28
3f3d848 to
8fb4765
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 tosceditor.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:script.jsbuilds the buttons from those attributes in a newattachBbCodeEvents(parent), which means:smfSelectText()has no callers left, so it goes.UpgradeTemplate.phpused it as its "did script.js load?" probe and now checks forattachBbCodeEventsinstead.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 inlineonclick="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..codeoperationis gone fromindex.cssalong with the::before/::afterthat supplied the[]; the JS adds those..resetis added so the generated<button>s can be styled as links.Two deliberate deviations from #7933 / #8891
[code=php]highlighting is kept. Both branches drop the$add_beginhandling, which wraps a snippet lacking<?phpsohighlight_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 toCode2, sinceCode1has no attribute to inspect, soCode1keeps the simplified version.jquery.sceditor.default.cssset an explicittext-alignon 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
[code],[code=php]with and without an explicit<?php, and[code=SQL]; PHP colouring and the language title both still work.[code]and[code=php]round-trip unchanged in both directions, tabs and blank lines survive, and theCode:/Code: (php)label still renders.🤖 Generated with Claude Code