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

strings with explicit \n characters in TomlTable should convert to multi-line TOML Strings #78

Open
varon opened this issue Jan 4, 2024 · 1 comment
Labels
enhancement New feature or request PR welcome User contribution/PR is welcome

Comments

@varon
Copy link

varon commented Jan 4, 2024

Currently, if we take this example:

[<Fact>]
let ``Multi-line string should serialize properly to multi-line toml entry``() =
    let table = TomlTable()
    let newLineString = "Hello\nNewline"
    table.Add("Example", newLineString)
    
    let result = Toml.FromModel(table)
    // we expect a triple-quoted string here for the multi-line text entry.
    Assert.Contains("\"\"\"", result)
    ()

This fails - we would expect nicely triple-quoted strings to be present here - as that's one of the major features of TOML over JSON!

I looked through the options and could not find a way to do this.

As a suggestion, I would suggest detecting if the string is actually multi-line (i.e. contains at least one \n - if it is, render with triple-quoted strings when we output it.

Thanks for creating this very useful Library.

@xoofx xoofx added enhancement New feature or request PR welcome User contribution/PR is welcome question Further information is requested and removed enhancement New feature or request PR welcome User contribution/PR is welcome question Further information is requested labels Jan 31, 2024
@xoofx
Copy link
Owner

xoofx commented Feb 1, 2024

This fails - we would expect nicely triple-quoted strings to be present here - as that's one of the major features of TOML over JSON!

Your test is failing because you expect a triple-quoted string but the generated TOML is valid: ☺️

Example = "Hello\nNewline"

It would require more a e.g configuration TomlModelOptions option to change the default behavior.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request PR welcome User contribution/PR is welcome
Projects
None yet
Development

No branches or pull requests

2 participants