vitepress icon indicating copy to clipboard operation
vitepress copied to clipboard

Support error lines in code blocks

Open Newbie012 opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe.

I want to be able to write an error message inside my code block and make it look like it's an error.

Currently, it blends with the code:

image

Describe the solution you'd like

I'm not sure if there's a known syntax for it, but I would like the option to "highlight" a row as an error row:

```typescript{2:error}
client.query(sql`
    SELECT idd FROM comments
           ~~~ <<<< Invalid Query: column "idd" does not exist
`);

 ```.

image

Describe alternatives you've considered

Haven't found any

Additional context

No response

Validations

Newbie012 avatar Sep 09 '22 11:09 Newbie012

As a workaround, add these styles:

.error {
    --vp-code-line-highlight-color: var(--vp-c-red-dimm-2);
}

And in markdown, do something like this:

<div class="error">

```ts{3}
client.query(sql`
    SELECT idd FROM comments
           ~~~ <<<< Invalid Query: column "idd" does not exist
`);
```

</div>

This won't work if you want normal as well as error highlighting in same code block.

Output:

image

brc-dd avatar Sep 09 '22 12:09 brc-dd

That's amazing! thanks!

Newbie012 avatar Sep 09 '22 12:09 Newbie012