Skip to content

Commit fffca5c

Browse files
authored
docs: remove "Open in Playground" buttons for removed rules (#17791)
1 parent a6d9442 commit fffca5c

File tree

4 files changed

+18
-10
lines changed

4 files changed

+18
-10
lines changed

docs/.eleventy.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,12 @@ module.exports = function(eleventyConfig) {
195195

196196
// markdown-it plugin options for playground-linked code blocks in rule examples.
197197
const ruleExampleOptions = markdownItRuleExample({
198-
open(type, code, parserOptions) {
198+
open({ type, code, parserOptions, env }) {
199+
const isRuleRemoved = !Object.prototype.hasOwnProperty.call(env.rules_meta, env.title);
200+
201+
if (isRuleRemoved) {
202+
return `<div class="${type}">`;
203+
}
199204

200205
// See https://github.com/eslint/eslint.org/blob/ac38ab41f99b89a8798d374f74e2cce01171be8b/src/playground/App.js#L44
201206
const state = encodeToBase64(

docs/src/assets/scss/docs.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ div.incorrect {
113113
offset-block-start: -22px;
114114
}
115115

116-
pre.line-numbers-mode {
116+
// Add space to the bottom if there is a Playground button.
117+
.c-btn.c-btn--playground ~ pre.line-numbers-mode {
117118
padding-bottom: 4.5rem;
118119
}
119120
}

docs/tools/markdown-it-rule-example.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
/**
66
* A callback function to handle the opening of container blocks.
77
* @callback OpenHandler
8-
* @param {"correct" | "incorrect"} type The type of the example.
9-
* @param {string} code The example code.
10-
* @param {ParserOptions} parserOptions The parser options to be passed to the Playground.
11-
* @param {Object} codeBlockToken The `markdown-it` token for the code block inside the container.
8+
* @param {Object} data Callback data.
9+
* @param {"correct" | "incorrect"} data.type The type of the example.
10+
* @param {string} data.code The example code.
11+
* @param {ParserOptions} data.parserOptions The parser options to be passed to the Playground.
12+
* @param {Object} data.codeBlockToken The `markdown-it` token for the code block inside the container.
13+
* @param {Object} data.env Additional Eleventy metadata, if available.
1214
* @returns {string | undefined} If a text is returned, it will be appended to the rendered output
1315
* of `markdown-it`.
1416
*/
@@ -43,7 +45,7 @@
4345
*
4446
* markdownIt()
4547
* .use(markdownItContainer, "rule-example", markdownItRuleExample({
46-
* open(type, code, parserOptions, codeBlockToken) {
48+
* open({ type, code, parserOptions, codeBlockToken, env }) {
4749
* // do something
4850
* }
4951
* close() {
@@ -58,7 +60,7 @@ function markdownItRuleExample({ open, close }) {
5860
validate(info) {
5961
return /^\s*(?:in)?correct(?!\S)/u.test(info);
6062
},
61-
render(tokens, index) {
63+
render(tokens, index, options, env) {
6264
const tagToken = tokens[index];
6365

6466
if (tagToken.nesting < 0) {
@@ -77,7 +79,7 @@ function markdownItRuleExample({ open, close }) {
7779
.replace(/\n$/u, "")
7880
.replace(/(?=\n)/gu, "");
7981

80-
const text = open(type, code, parserOptions, codeBlockToken);
82+
const text = open({ type, code, parserOptions, codeBlockToken, env });
8183

8284
// Return an empty string to avoid appending unexpected text to the output.
8385
return typeof text === "string" ? text : "";

tools/check-rule-examples.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ async function findProblems(filename) {
5050
const text = await readFile(filename, "UTF-8");
5151
const problems = [];
5252
const ruleExampleOptions = markdownItRuleExample({
53-
open(type, code, parserOptions, codeBlockToken) {
53+
open({ code, parserOptions, codeBlockToken }) {
5454
const languageTag = codeBlockToken.info;
5555

5656
if (!STANDARD_LANGUAGE_TAGS.has(languageTag)) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy