fix(docs-infra): preserve shell class for multifile code blocks

The ExampleViewer component was extracting only innerHTML from code
blocks in multifile examples, which lost the shell class applied by
the formatCode function. This caused the $ prompt to not appear for
shell commands in multifile blocks even when language="shell" was set.

Modified the Snippet interface to track shell language state and
updated getCodeSnippetsFromMultifileWrapper and getStandaloneCodeSnippet
methods to preserve the shell class. Updated example-viewer template
to conditionally apply the shell class to the code wrapper element.

Fixes inconsistency between standalone and multifile shell code blocks.

(cherry picked from commit 27e183330e)
This commit is contained in:
Shuaib Hasan Akib 2025-10-26 14:47:42 +06:00 committed by Kristiyan Kostadinov
parent 9b3574b9b9
commit 14b5590f80
5 changed files with 11 additions and 2 deletions

View file

@ -221,6 +221,7 @@ export class DocViewer {
name: tab.getAttribute('path') ?? tab.getAttribute('header') ?? '',
sanitizedContent: this.sanitizer.bypassSecurityTrustHtml(tab.innerHTML),
visibleLinesRange: tab.getAttribute('visibleLines') ?? undefined,
shell: tab.classList.contains('shell'),
}));
}
@ -243,6 +244,7 @@ export class DocViewer {
? this.sanitizer.bypassSecurityTrustHtml(content.outerHTML)
: '',
visibleLinesRange: visibleLines,
shell: element.classList.contains('shell'),
};
}

View file

@ -97,6 +97,7 @@
class="docs-example-viewer-code-wrapper"
[class.docs-example-viewer-snippet]="view() === CodeExampleViewMode.SNIPPET"
[class.docs-example-viewer-multi-file]="view() === CodeExampleViewMode.MULTI_FILE"
[class.shell]="snippetCode()?.shell"
>
<button docs-copy-source-code></button>
@if (snippetCode()?.sanitizedContent; as content) {

View file

@ -25,6 +25,8 @@ export interface Snippet {
sanitizedContent: SafeHtml;
/** Text in following format `start-end`. Start and end are numbers, based on them provided range of lines will be displayed in collapsed mode */
visibleLinesRange?: string;
shell?: boolean;
}
export interface ExampleMetadata {

View file

@ -26,7 +26,7 @@ export interface CodeToken extends Tokens.Generic {
path?: string;
/* The example display header */
header?: string;
/* Whether stling should include line numbers */
/* Whether styling should include line numbers */
linenums?: boolean;
/* The example path to determine diff (lines added/removed) */
diff?: string;
@ -41,7 +41,7 @@ export interface CodeToken extends Tokens.Generic {
/* The lines to display highlighting on */
highlight?: string;
/** The generated diff metadata if created in the code formating process. */
/** The generated diff metadata if created in the code formatting process. */
diffMetadata?: DiffMetadata;
// additional classes for the element

View file

@ -35,21 +35,25 @@ Open a terminal (if you're using [Visual Studio Code](https://code.visualstudio.
<docs-code-multifile>
<docs-code
header="npm"
language="shell"
>
npm install -g @angular/cli
</docs-code>
<docs-code
header="pnpm"
language="shell"
>
pnpm install -g @angular/cli
</docs-code>
<docs-code
header="yarn"
language="shell"
>
yarn global add @angular/cli
</docs-code>
<docs-code
header="bun"
language="shell"
>
bun install -g @angular/cli
</docs-code>