Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiline strings and #[leptosfmt::skip] #93

Open
SV-97 opened this issue Nov 4, 2023 · 2 comments
Open

Multiline strings and #[leptosfmt::skip] #93

SV-97 opened this issue Nov 4, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@SV-97
Copy link

SV-97 commented Nov 4, 2023

I have a multiline string embedded in my code that gets modified by leptosfmt. Something like this:

    view! {
        <button>
        <div class="ascii-art">r#"
,--.                               ,--.   
`--',--,--,  ,---.  ,---. ,--.--.,-'  '-. 
,--.|      \(  .-' | .-. :|  .--''-.  .-' 
|  ||  ||  |.-'  `)\   --.|  |     |  |   
`--'`--''--'`----'  `----'`--'     `--'  
"#
        </div>
        </button>

that gets turned into something like this

    view! {
        <button>
            <div class="ascii-art">
                r#"
                ,--.                               ,--.   
                `--',--,--,  ,---.  ,---. ,--.--.,-'  '-. 
                ,--.|      \(  .-' | .-. :|  .--''-.  .-' 
                |  ||  ||  |.-'  `)\   --.|  |     |  |   
                `--'`--''--'`----'  `----'`--'     `--'  
                "#
            </div>
        </button>
    }

Importantly the two strings aren't the same because of the prepended spaces and they render differently. The only workaround I could think of (short of extracting the string out of the view macro) was to use indoc and do something like

    view! {
        <button>
            <div class="ascii-art">
                {
                    indoc! {
                        r#"
                ,--.                               ,--.   
                `--',--,--,  ,---.  ,---. ,--.--.,-'  '-. 
                ,--.|      \(  .-' | .-. :|  .--''-.  .-' 
                |  ||  ||  |.-'  `)\   --.|  |     |  |   
                `--'`--''--'`----'  `----'`--'     `--'  
                "#
                    }
                }
            </div>
        </button>
    }

which renders correctly - but isn't the best solution imo (and still formats a bit weirdly).

Since this changes the behaviour of the formatted code it should probably be considered a bug?

I couldn't find something similar to #[rustfmt::skip] that I could use to simply skip the formatting of the string - does leptosfmt already support such a feature?

@bram209 bram209 added the bug Something isn't working label Nov 27, 2023
@bram209
Copy link
Owner

bram209 commented Nov 27, 2023

Since this changes the behaviour of the formatted code it should probably be considered a bug?

Yes, it should. I will see if I can take a look later this week.
For now, indeed you can extract the multi line string out of the macro.

@n1tranquilla
Copy link

I'm also having the same issues and am eagerly looking for a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants