Skip to content

Add custom playground guide for v0.5 - #3124

Open
dalance wants to merge 1 commit into
rust-lang:mainfrom
dalance:custom-playground-v0.5
Open

dalance wants to merge 1 commit into
rust-lang:mainfrom
dalance:custom-playground-v0.5

Conversation

@dalance

@dalance dalance commented May 22, 2026

Copy link
Copy Markdown
Contributor

This PR documents how to implement custom playgrounds.

This is a successor to PR #2286.
The method described in #2286 is no longer available in v0.5, so it has been rewritten for v0.5, and
it was possible to implement it with fewer patches than the previous version.

Related: #350 #1453 #1759

@rustbot rustbot added the S-waiting-on-review Status: waiting on a review label May 22, 2026
@GuillaumeGomez

Copy link
Copy Markdown
Member

Sorry for the delay, we now have an mdbook team so things should move a bit faster here. This sounds like a very good idea to add an example! Do you mind adding a GUI test to ensure that the code you provided won't become outdated when we make updates?

@GuillaumeGomez GuillaumeGomez left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need a GUI test using the JS code example to ensure it doesn't become outdated.

View changes since this review

@rustbot rustbot added S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author. and removed S-waiting-on-review Status: waiting on a review labels Sep 2, 2026
@rustbot

rustbot commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@dalance

dalance commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

Thank you for your review.
I'm glad the mdBook team has been established.

When I wrote this documentation, I understood that review bandwidth was extremely limited,
so I wrote a procedure which can be implemented without making changes to mdBook itself.

If minor changes are acceptable, I can clean up some of the JavaScript hacks, what do you think?
For example, if we slightly adjusted the condition at

if !is_playground {
,
the section titled "Restrict the .playground selector to <pre>" will no longer be necessary.

@GuillaumeGomez

Copy link
Copy Markdown
Member

If that can make things simpler, then it's worth a try!

@dalance

dalance commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

I wrote 2 issues to improve custome playground support.
If both of them are accepted, the way of this PR is significantly simplified because theme override is not necessary.
Especially it is important that book.js override is not necessary because it causes manual synchronization to mdBook update.

@dalance

dalance commented Sep 9, 2026

Copy link
Copy Markdown
Contributor Author

@GuillaumeGomez
I created #3218.

Regarding #3216, since it would have a bit large impact, such as requiring the addition of a configuration value,
I'd like to prepare it only after reaching a certain level of consensus.
What do you think?

If there is no prospect of it being accepted in the short term, I am also open to rewriting this guide on the assumption that #3216 can't be used.

@dalance

dalance commented Oct 20, 2026

Copy link
Copy Markdown
Contributor Author

I created #3241.

@dalance
dalance force-pushed the custom-playground-v0.5 branch from 5dde35f to 3535c49 Compare November 4, 2026 06:14
@rustbot

rustbot commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@dalance

dalance commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@GuillaumeGomez
Thank you for your review and merge for #3215 and #3216.
I updated the guide and added a GUI test.

"use strict";

// Replace with a call to your runtime.
function example_language_run(source) {

@GuillaumeGomez GuillaumeGomez Nov 4, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we include a file directly? That would allow:

  1. To not duplicate content between here and the GUI test.
  2. Prevent this one to become outdated.

View changes since the review


The final directory structure becomes below:

```

@GuillaumeGomez GuillaumeGomez Nov 4, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```
```text

View changes since the review

Comment on lines +4 to +11
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var Rules = function() {
this.$rules = { start: [{ token: "keyword", regex: "\\bprint\\b" }] };
};
oop.inherits(Rules, TextHighlightRules);
var Mode = function() { this.HighlightRules = Rules; };

@GuillaumeGomez GuillaumeGomez Nov 4, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var oop = require("../lib/oop");
var TextMode = require("./text").Mode;
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
var Rules = function() {
this.$rules = { start: [{ token: "keyword", regex: "\\bprint\\b" }] };
};
oop.inherits(Rules, TextHighlightRules);
var Mode = function() { this.HighlightRules = Rules; };
const oop = require("../lib/oop");
const TextMode = require("./text").Mode;
const TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
const Rules = function() {
this.$rules = { start: [{ token: "keyword", regex: "\\bprint\\b" }] };
};
oop.inherits(Rules, TextHighlightRules);
const Mode = function() { this.HighlightRules = Rules; };

View changes since the review

ace.define("ace/mode/example",
["require", "exports", "ace/lib/oop", "ace/mode/text", "ace/mode/text_highlight_rules"],
function(require, exports) {
var oop = require("../lib/oop");

@GuillaumeGomez GuillaumeGomez Nov 4, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to apply the suggested changes below. One more argument in favour of including a file rather than duplicating content. :)

View changes since the review

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: The marked PR is awaiting some action (such as code changes) from the PR author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants