carta icon indicating copy to clipboard operation
carta copied to clipboard

Multi line coloration

Open Wyrdix opened this issue 1 year ago • 2 comments

I would like to add coloration to a syntax like so :

<MD>

<SEPARATOR>

<MD>

Where <MD> can be replaced by any markdown part and <SEPARATOR> is a predefined string

In the end i tried to modify the coloration to have it only works if the SEPARATOR is present in its own paragraph (which means with empty line before and after).

But it seems like it's not possible to have a coloration around multiple lines ?

As an example heres what i've tried :

grammarRules: [
			{
				name: 'question',
				type: 'inline',
				definition: {
					match: '(\n *\n#\\?#( +|\n))',
					name: 'markup.inline.question',
					captures: {
						'1': { name: 'marker.definition.question.inline' }
					}
				}
			}
		],

(with the corresponding colors options that works when it's not multiline regex)

Don't know if it's a bug or a features

Wyrdix avatar Jan 21 '25 13:01 Wyrdix

Hello, sorry for the late reply but I'm currently very busy and I don't have much time to dedicate to open-source at the moment.

Anyway, I'm not sure I understood what you trying to achieve: do you want to change the color of the separator, or what else? Writing complex grammar / highlight rules is not an easy thing to do, and I'm not the right person to help you with that. You can find some info here, but I suggest you also look into some languages examples.

Another thing: only providing a grammar rule is not enough: grammar rules are used to parse the text into tokens, but they do not specify how they should be colored. You also need a highlighting rule that targets that specific token. Here is an example from the emoji plugin, which highlights text like :emoji::

https://github.com/BearToCode/carta/blob/983c1874b927f39035d3b2df97f79ca205679113/packages/plugin-emoji/src/lib/index.ts#L64-L86

BearToCode avatar Jan 24 '25 18:01 BearToCode

Hi, don't worry for the delay for now i removed the rules as it wasn't working properly

Yes I want to color the separator when it's between two empty lines (because in other cases it would be a paragraph and "harder" to parse)

And yeah i knew for the coloration it was what i meant at the end of my message with "color options" being put

I'll check your link, maybe there some shiki thing i didn't know about

Wyrdix avatar Jan 25 '25 16:01 Wyrdix