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(CodeBlock): recommend using String.raw`` #10307

Merged
merged 1 commit into from
May 8, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,20 @@ propComponents: ['CodeBlock', 'CodeBlockAction', 'CodeBlockCode']
import CopyIcon from '@patternfly/react-icons/dist/esm/icons/copy-icon';
import PlayIcon from '@patternfly/react-icons/dist/esm/icons/play-icon';

**Important note:** to format code exactly as it is, you should use String.raw\`your code here\`.

Using **String.raw\`\`** will keep all the special characters like `\n` or `\t`.

## Examples

### Basic

```ts file="./CodeBlockBasic.tsx"

```

### Expandable

```ts file="./CodeBlockExpandable.tsx"

```
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const BasicCodeBlock: React.FunctionComponent = () => {
setCopied(true);
};

const code = `apiVersion: helm.openshift.io/v1beta1/
const code = String.raw`apiVersion: helm.openshift.io/v1beta1/
kind: HelmChartRepository
metadata:
name: azure-sample-repo0oooo00ooo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,19 @@ export const ExpandableCodeBlock: React.FunctionComponent = () => {
setCopied(true);
};

const copyBlock = `apiVersion: helm.openshift.io/v1beta1/
const copyBlock = String.raw`apiVersion: helm.openshift.io/v1beta1/
kind: HelmChartRepository
metadata:
name: azure-sample-repo
spec:
connectionConfig:
url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs`;

const code = `apiVersion: helm.openshift.io/v1beta1/
const code = String.raw`apiVersion: helm.openshift.io/v1beta1/
kind: HelmChartRepository
metadata:
name: azure-sample-repo`;
const expandedCode = `spec:
const expandedCode = String.raw`spec:
connectionConfig:
url: https://raw.githubusercontent.com/Azure-Samples/helm-charts/master/docs`;

Expand Down
Loading