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

Keep line breaks, remove indentation #52

Open
jtmueller opened this issue Jul 17, 2024 · 2 comments
Open

Keep line breaks, remove indentation #52

jtmueller opened this issue Jul 17, 2024 · 2 comments

Comments

@jtmueller
Copy link

jtmueller commented Jul 17, 2024

This is very handy, but it would be nice in some cases to have the option to preserve line breaks, but condense consecutive white-space characters after each line break. That would allow the creation of multi-line strings that are indented in the code, but not in the output.

function generateLetter() {
    return `Dear Sir or Madam,
                 
            We are writing to inform you that this example will clearly show that as of
            ${new Date().toLocaleString()} line breaks are preserved, but leading space from
            each line is stripped away.

            Sincerely,
            Us`;
}
@iansan5653
Copy link
Owner

iansan5653 commented Jul 17, 2024

This is possible now, by using \n as the linebreak character (see the documentation). For example:

function generateLetter() {
    return c`Dear Sir or Madam,\n
            \n
            We are writing to inform you that this example will clearly show that as of 
            ${new Date().toLocaleString()} line breaks are preserved, but leading space from 
            each line is stripped away. 
            \n
            Sincerely, \n
            Us`;
}

It's not as pretty, but it does allow you to pick specifically which newlines to preserve. Does that solve your problem?

@jtmueller
Copy link
Author

It's a workaround for sure, and in fact it's pretty much exactly what I ended up doing. It would still be nice to have the option of not needing explicit line-break notation.

For example, if I were to share a block of text from code to a non-technical person who wants to revise the text, I have to either remove all the \n and then put them back in manually, or explain to a non-technical person what \n is and where it belongs. In such a case it would be less-tedious to simply copy the text and shift-tab to remove leading spaces, and then paste in the revised text and indent it appropriately, without having to manually deal with explicit line-break characters.

Not a deal breaker, and thanks for this handy utility, but I do think it would be a useful option in some cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants