Skip to content

Commit

Permalink
Bug fix: global config snippets in tutorials no longer rendering on d…
Browse files Browse the repository at this point in the history
…ocs 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
  • Loading branch information
srietkerk authored Apr 15, 2024
1 parent 61c7a6c commit 1b75c67
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions pxtrunner/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1254,24 +1254,37 @@ function renderTypeScript(options?: ClientRenderOptions) {
});
}

function renderGhost(options: ClientRenderOptions) {
let c = $('code.lang-ghost');
function removeSnippet(c: JQuery<HTMLElement>, 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) {
Expand Down Expand Up @@ -1313,6 +1326,8 @@ export function renderAsync(options?: ClientRenderOptions): Promise<void> {
renderQueue = [];
renderGhost(options);
renderBlockConfig(options);
renderTemplate(options);
renderValidation(options);
renderSims(options);
renderTypeScript(options);
renderDirectPython(options);
Expand Down

0 comments on commit 1b75c67

Please sign in to comment.