diff --git a/src/stylemacro.jl b/src/stylemacro.jl index b0305690..f6b551fa 100644 --- a/src/stylemacro.jl +++ b/src/stylemacro.jl @@ -84,9 +84,11 @@ inheritval = whitespace, ':'?, symbol ; ``` """ macro styled_str(raw_content::String) - #------------------ - # Helper functions - #------------------ + # First undo the transforms of the parser, (assuming the input was entered + # with single `styled""` markers so this transform is unambiguously + # reversible and not as `@styled_str "."` or `styled"""."""`), since the + # `unescape_string` transforms will be a superset of those transforms + raw_content = Base.escape_raw_string(raw_content) # If this were a module, I'd define the following struct. @@ -128,6 +130,10 @@ macro styled_str(raw_content::String) "grey", "gray", "bright_black", "bright_red", "bright_green", "bright_yellow", "bright_blue", "bright_magenta", "bright_cyan", "bright_white") + #------------------ + # Helper functions + #------------------ + function styerr!(state, message, position::Union{Nothing, Int}=nothing, hint::String="around here") if !isnothing(position) && position < 0 position = prevind( diff --git a/test/runtests.jl b/test/runtests.jl index c0a44107..f5a7a4d9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -207,6 +207,14 @@ end @macroexpand styled"{(foreground=$color):val}" end + # Trailing (and non-trailing) Backslashes + @test String(styled"\\") == "\\" + @test String(styled"\\\\") == "\\\\" + @test String(styled"\\\\\\") == "\\\\\\" + @test String(styled".\\") == ".\\" + @test String(styled".\\\\") == ".\\\\" + @test String(styled".\\\\\\") == ".\\\\\\" + # newlines normal = "abc\ def"