E2E Tests GitBook Open
  • Welcome
  • Text page
    • Long text thisisaveryyyylonnnnngwordthatisnotrealisic butit'sok
  • Empty page
  • Page options
    • Page no index
      • Descendant of page no index
    • Page no robots index
      • Descendant of page no robots index
    • Page without TOC
    • Page with description
    • Page with cover
    • Page with cover and no TOC
    • Page with hero cover
    • 🌍Page with emoji
    • Page with icon
      • Cake
      • Ice cream
      • Burger
      • Food
  • Blocks
    • Code
    • Annotations
    • Tabs
    • Hints
    • Integrations
    • Tables
    • Cards
    • Headings
    • Expandables
    • Inline Images
    • Block Images
    • Marks
    • Emojis
    • Links
    • Page links
    • API blocks
    • Math
    • Files
    • Embeds
    • Lists
    • Stepper
Powered by GitBook
On this page
Export as PDF

Last updated 1 year ago

Code block with lines and no wrapping

Code block with line numbers and wrapping

Code block with wrapping but no line numbers

Code block with full-width option

function CodeHighlightLine(props: {
    block: DocumentBlockCode;
    line: HighlightLine;
    lineIndex: number;
    isLast: boolean;
    withLineNumbers: boolean;
    withWrap: boolean;
    context: ContentRefContext;
}) {
    const { block, line, isLast, withLineNumbers, context } = props;

    return (
        <span
            className={tcls(
                'flex',
                'flex-row',
                'px-4',
                line.highlighted ? 'bg-slate-200' : null,
                withLineNumbers
                    ? [
                          'before:shrink-0',
                          'before:absolute',
                          'before:left-0',
                          'before:pl-4',
                          line.highlighted ? 'before:bg-slate-200' : 'before:bg-slate-100',
                          'before:text-slate-400',
                          'before:content-[counter(line)]',
                          '[counter-increment:line]',
                          getLineNumberGutterWidth(block),
                      ]
                    : [],
            )}
        >
            <span className="flex-1">
                <CodeHighlightTokens tokens={line.tokens} context={context} />
                {isLast ? null : !withLineNumbers && line.tokens.length === 0 && 0 ? (
                    <span className="ew">{'\u200B'}</span>
                ) : (
                    '\n'
                )}
            </span>
        </span>
    );
}
function CodeHighlightLine(props: {
    block: DocumentBlockCode;
    line: HighlightLine;
    lineIndex: number;
    isLast: boolean;
    withLineNumbers: boolean;
    withWrap: boolean;
    context: ContentRefContext;
}) {
    const { block, line, isLast, withLineNumbers, context } = props;

    return (
        <span
            className={tcls(
                'flex',
                'flex-row',
                'px-4',
                line.highlighted ? 'bg-slate-200' : null,
                withLineNumbers
                    ? [
                          'before:shrink-0',
                          'before:absolute',
                          'before:left-0',
                          'before:pl-4',
                          line.highlighted ? 'before:bg-slate-200' : 'before:bg-slate-100',
                          'before:text-slate-400',
                          'before:content-[counter(line)]',
                          '[counter-increment:line]',
                          getLineNumberGutterWidth(block),
                      ]
                    : [],
            )}
        >
            <span className="flex-1">
                <CodeHighlightTokens tokens={line.tokens} context={context} />
                {isLast ? null : !withLineNumbers && line.tokens.length === 0 && 0 ? (
                    <span className="ew">{'\u200B'}</span>
                ) : (
                    '\n'
                )}
            </span>
        </span>
    );
}
function CodeHighlightLine(props: {
    block: DocumentBlockCode;
    line: HighlightLine;
    lineIndex: number;
    isLast: boolean;
    withLineNumbers: boolean;
    withWrap: boolean;
    context: ContentRefContext;
}) {
    const { block, line, isLast, withLineNumbers, context } = props;

    return (
        <span
            className={tcls(
                'flex',
                'flex-row',
                'px-4',
                line.highlighted ? 'bg-slate-200' : null,
                withLineNumbers
                    ? [
                          'before:shrink-0',
                          'before:absolute',
                          'before:left-0',
                          'before:pl-4',
                          line.highlighted ? 'before:bg-slate-200' : 'before:bg-slate-100',
                          'before:text-slate-400',
                          'before:content-[counter(line)]',
                          '[counter-increment:line]',
                          getLineNumberGutterWidth(block),
                      ]
                    : [],
            )}
        >
            <span className="flex-1">
                <CodeHighlightTokens tokens={line.tokens} context={context} />
                {isLast ? null : !withLineNumbers && line.tokens.length === 0 && 0 ? (
                    <span className="ew">{'\u200B'}</span>
                ) : (
                    '\n'
                )}
            </span>
        </span>
    );
}
// Some code
  1. Blocks

Code

PreviousBlocksNextAnnotations
  • Code block with lines and no wrapping
  • Code block with line numbers and wrapping
  • Code block with wrapping but no line numbers
  • Code block with full-width option