How to get escaping in a custom string macro to work?

I have a little string macro as follows

macro Q_str(p)
	esc(:(println(Crayon(foreground = :light_cyan ), $p)))
end

Basically I can just write

Q"""
This is a multi-line string. Printed in light cyan
"""

It’s nice cause I can get a note-book-like workflow with very low effort and keep the REPL etc.

Problem, string escaping behaves differently in my Q_str macro

julia> x = Q"""
       The value of x is 
       
       $(x)
       """
The value of x is 

$(x)

Does anyone know how I can get all the string escaping for normal multi-line strings to behave the same?

This is the same issue as handling escaping in expressions as well, no? Basically the macro runs pre-substitution, so it falls on you to replicate the logic AFAICT.

2 Likes

Ah darn, I guess @Q md""" as a shorthand is gooe enought.