Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: remove "Open in Playground" buttons for removed rules #17791

Merged
merged 1 commit into from Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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