runway

Runway

Code Block

A code block component for displaying code snippets


python

1def hello_world():
2    print("Hello, World!")

The CodeBlock component is a customizable code block that can be used to display code snippets. It supports syntax highlighting, line numbers, and copy-to-clipboard functionality.

Want different themes? Check out React Syntax Highlighter Demo and tweak the /components/atoms/CodeBlock component.




Usage

javascript

1import CodeBlock from "@/components/atoms/CodeBlock";
2
3<CodeBlock language="javascript">
4    {console.log("Hello, World!");}
5</CodeBlock>

You have to wrap the code inside curly braces to pass it as a child to the CodeBlock component.




Props

The CodeBlock component accepts the following props:

PropTypeDefaultDescription
childrenReactNode-The code to be displayed inside the code block
languagestring-The language of the code snippet for syntax highlighting
showLineNumbersbooleanfalseWhether to display line numbers for the code snippet
startingLineNumbernumber1The starting line number for the code snippet
copybooleanfalseWhether to display a copy-to-clipboard button
wrapLinesbooleanfalseWhether to wrap long lines of code
wrapLongLinesbooleantrueWhether to wrap long lines of code
showLanguagebooleanfalseWhether to display the language name at the top of the code block
borderbooleanfalseWhether to display a border around the code block

The CodeBlock component uses the react-syntax-highlighter library to provide syntax highlighting for code snippets. You can customize the appearance and behavior of the code block by passing the appropriate props.


Usage Examples

Basic Code Block

print("Hello, World!")

Code Block with Line Numbers

5function add(a, b) {
6    return a + b;
7}

Code Block with Copy Button

interface User {
    name: string;
    age: number;
}

Code Block with Language Name

java

public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello, World!");
    }
}

Code Block with Everything

javascript

1function add(a, b) {
2    return a + b;
3}