How to keep rich text formatting when syntax highlighting

Hey, I hope this is the right place to ask

From other articles here, I have gathered that to create a code block with custom syntax highlighting, I have to create a dedicated CodeBlock slice.
My slice has a langauge input & a RichText input with only code enabled. I am using Shiki to do the syntax highlighting.

If I syntax highlight the code wrapped in asText() it looses its multi-line formatting. How can I keep the lines and tabs but also pass it in as a string to shiki?

Hi @avaneeshsamsi,

This is the right place to ask :slight_smile:

asText() will indeed remove all formatting including multi-lines. Have you tried using asText() with a new line separator '\n', like the example in the documentation here?

Let me know if that works!

Awesome! That fixed it.

I seem to have missed that when I was checking the as functions. Thanks again

1 Like