Git Product home page Git Product logo

Comments (2)

mnil avatar mnil commented on May 4, 2024 1

You are indeed correct! With scan_folded_as_literal: true in my real example seems to give the correct output. Thanks a lot for the quick help!

from yamlfmt.

braydonk avatar braydonk commented on May 4, 2024

Thanks for making an issue and the kind words!

This appears to be a strange edge case of scanning folded block scalars, something that's been a hassle. There's two bits of weirdness, one of which yamlfmt has a workaround for, and one that probably needs investigation in the library.

The one with a workaround is that the underlying yaml library cuts out lines for folded block scalars. This actually kind of makes sense, since that's a correct interpretation of folded block scalars from the spec, however it's really uncool for a tool like this where we want to maintain that form. For that, I've implemented a feature in the yaml library that forces re-encoding folded block scalars to retain the line breaks. I added a boolean option in the formatter config called scan_folded_as_literal to enable this. See the config docs for a bit more info there. With scan_folded_as_literal enabled, the first example in the issue remains the same after format.

The second weirdness is something I actually discovered just now while reproducing the issue. If a line in a folded block scalar ends with space characters, the encoder throws a fit and dumps the raw string value instead of producing a folded block scalar as intended. If whitespace is left at the end of a folded block scalar, you get output like this:

Foobar:
  baz: "Lorem Ipsum is simply dummy text of the printing_and_typesetting industry.
    \n#magic___^_^___line\n"
Foobaz:
  baz: "foobar"

This is a really annoying consequence, and I'll start tackling it soon.

That being said, hopefully scan_folded_as_literal will work for your issue! If it does, I will close this issue; I'll be starting the new investigation for folded block scalar lines ending with whitespace in a new issue dedicated to it.

from yamlfmt.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.