From 1b75c67bb988f96444bce9a3e02bee8b2182d2c4 Mon Sep 17 00:00:00 2001 From: Sarah Rietkerk <49178322+srietkerk@users.noreply.github.com> Date: Mon, 15 Apr 2024 13:44:44 -0700 Subject: [PATCH] Bug fix: global config snippets in tutorials no longer rendering on docs pages (#9969) * need to escape the '.global' because the dot behaves as a css class selector if not * added renderValidation to renderer to remove validation tags in docs * getting rid of template snippets when rendering docs * break out shared code * move the renderscopedconfig function to be after removesnippet for better grouping --- pxtrunner/renderer.ts | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/pxtrunner/renderer.ts b/pxtrunner/renderer.ts index 652ed21808f5..604f2125b1fb 100644 --- a/pxtrunner/renderer.ts +++ b/pxtrunner/renderer.ts @@ -1254,24 +1254,37 @@ function renderTypeScript(options?: ClientRenderOptions) { }); } -function renderGhost(options: ClientRenderOptions) { - let c = $('code.lang-ghost'); +function removeSnippet(c: JQuery, options: ClientRenderOptions) { if (options.snippetReplaceParent) c = c.parent(); c.remove(); } +function removeScopedConfig(type: string, scope: "local" | "global", options: ClientRenderOptions) { + $(`code.lang-${type}\\.${scope}`).each((i, c) => { + let $c = $(c); + removeSnippet($c, options); + }); +} + +function renderGhost(options: ClientRenderOptions) { + let c = $('code.lang-ghost'); + removeSnippet(c, options); +} + +function renderTemplate(options: ClientRenderOptions) { + let c = $('code.lang-template'); + removeSnippet(c, options); +} + function renderBlockConfig(options: ClientRenderOptions) { - function render(scope: "local" | "global") { - $(`code.lang-blockconfig.${scope}`).each((i, c) => { - let $c = $(c); - if (options.snippetReplaceParent) - $c = $c.parent(); - $c.remove(); - }); - } - render("local"); - render("global"); + removeScopedConfig("blockconfig", "local", options); + removeScopedConfig("blockconfig", "global", options); +} + +function renderValidation(options: ClientRenderOptions) { + removeScopedConfig("validation", "local", options); + removeScopedConfig("validation", "global", options); } function renderSims(options: ClientRenderOptions) { @@ -1313,6 +1326,8 @@ export function renderAsync(options?: ClientRenderOptions): Promise { renderQueue = []; renderGhost(options); renderBlockConfig(options); + renderTemplate(options); + renderValidation(options); renderSims(options); renderTypeScript(options); renderDirectPython(options);