How to convert a multiline string into a single-line script?

Hello. I have a site description written in the config.toml file and divided into several lines. Like this one:

[params]
    description = """
        This description 
        is divided into 
        several lines.
        """

In the layouts/partials/head.html I need to write that description on the site header.
If I write:

<meta name="description" content="{{ .Site.Params.Description }}" />

The description includes tabs, new lines and return carriages, like so:

<meta name="description" content="        This description 
        is divided into 
        several lines." />

Instead, I’d like to remove every tab, new line and carriage return and print it as a one-line string. Like this:

<meta name="description" content="This description is divided into several lines." />

How can I achieve this? Do I have to use regular expressions, or maybe is there anything else I can use?

Thank you and best regards

I think you can get the result you want with Chomp or another function of the kind. strings.Chomp | Hugo

1 Like

To clarify, you need to do this:

[params]
    description = """\
        This description \
        is divided into \
        several lines.\
        """

Please read the TOML spec and search for “Powerful Strings”.

1 Like

Thank you :heart:

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.