Skip to content

Commit

Permalink
docs: remove "Open in Playground" buttons for removed rules (#17791)
Browse files Browse the repository at this point in the history
  • Loading branch information
fasttime committed Nov 26, 2023
1 parent a6d9442 commit fffca5c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
7 changes: 6 additions & 1 deletion docs/.eleventy.js
Expand Up @@ -195,7 +195,12 @@ module.exports = function(eleventyConfig) {

// markdown-it plugin options for playground-linked code blocks in rule examples.
const ruleExampleOptions = markdownItRuleExample({
open(type, code, parserOptions) {
open({ type, code, parserOptions, env }) {
const isRuleRemoved = !Object.prototype.hasOwnProperty.call(env.rules_meta, env.title);

if (isRuleRemoved) {
return `<div class="${type}">`;
}

// See https://github.com/eslint/eslint.org/blob/ac38ab41f99b89a8798d374f74e2cce01171be8b/src/playground/App.js#L44
const state = encodeToBase64(
Expand Down
3 changes: 2 additions & 1 deletion docs/src/assets/scss/docs.scss
Expand Up @@ -113,7 +113,8 @@ div.incorrect {
offset-block-start: -22px;
}

pre.line-numbers-mode {
// Add space to the bottom if there is a Playground button.
.c-btn.c-btn--playground ~ pre.line-numbers-mode {
padding-bottom: 4.5rem;
}
}
Expand Down
16 changes: 9 additions & 7 deletions docs/tools/markdown-it-rule-example.js
Expand Up @@ -5,10 +5,12 @@
/**
* A callback function to handle the opening of container blocks.
* @callback OpenHandler
* @param {"correct" | "incorrect"} type The type of the example.
* @param {string} code The example code.
* @param {ParserOptions} parserOptions The parser options to be passed to the Playground.
* @param {Object} codeBlockToken The `markdown-it` token for the code block inside the container.
* @param {Object} data Callback data.
* @param {"correct" | "incorrect"} data.type The type of the example.
* @param {string} data.code The example code.
* @param {ParserOptions} data.parserOptions The parser options to be passed to the Playground.
* @param {Object} data.codeBlockToken The `markdown-it` token for the code block inside the container.
* @param {Object} data.env Additional Eleventy metadata, if available.
* @returns {string | undefined} If a text is returned, it will be appended to the rendered output
* of `markdown-it`.
*/
Expand Down Expand Up @@ -43,7 +45,7 @@
*
* markdownIt()
* .use(markdownItContainer, "rule-example", markdownItRuleExample({
* open(type, code, parserOptions, codeBlockToken) {
* open({ type, code, parserOptions, codeBlockToken, env }) {
* // do something
* }
* close() {
Expand All @@ -58,7 +60,7 @@ function markdownItRuleExample({ open, close }) {
validate(info) {
return /^\s*(?:in)?correct(?!\S)/u.test(info);
},
render(tokens, index) {
render(tokens, index, options, env) {
const tagToken = tokens[index];

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

const text = open(type, code, parserOptions, codeBlockToken);
const text = open({ type, code, parserOptions, codeBlockToken, env });

// Return an empty string to avoid appending unexpected text to the output.
return typeof text === "string" ? text : "";
Expand Down
2 changes: 1 addition & 1 deletion tools/check-rule-examples.js
Expand Up @@ -50,7 +50,7 @@ async function findProblems(filename) {
const text = await readFile(filename, "UTF-8");
const problems = [];
const ruleExampleOptions = markdownItRuleExample({
open(type, code, parserOptions, codeBlockToken) {
open({ code, parserOptions, codeBlockToken }) {
const languageTag = codeBlockToken.info;

if (!STANDARD_LANGUAGE_TAGS.has(languageTag)) {
Expand Down

0 comments on commit fffca5c

Please sign in to comment.