#Highlights line with Code component

12 messages · Page 1 of 1 (latest)

stiff siren
#

I have the following code

export const highlights = [1, 4, 7 - 8]
<Code code={giteaEnv} lang="toml" title=".gitea.env" mark={highlights} />

And the following error:
Plugin "TextMarkers" caused an error in its "preprocessMetadata" hook. Error message: Line index must be a non-negative number
It's seem like it's evaluate 7-8 = -1, is it possible to highlight range of line?

vernal sun
#

why not just export const highlights = [1, 4, 7, 8] ? This is just a javascript array so a dash will indicate a subtraction operation

#

If you really need to specify a long range then you can generate it yourself, for example

export const highlights = [1, 4, ...[...Array(5).keys()].map((key) => key + 7)]
// [1, 4, 7, 8, 9, 10, 11]
vernal sun
#

But again, it's probably easiest to hard code the highlighted range unless they get really long

stiff siren
stiff siren
vernal sun
stiff siren
#

With you're exemple, it's highlight line 1 and 4, and plaintext search for 7-8

vernal sun
#

The array also accepts an object of the shape { range: string; label?: string | undefined }

const highlights = [1, 4, {range: "7-8"}]

Does this work?

stiff siren
#

ohhh I didn't know about range object, yes it's work

#

thank's