MaybeJustJames / yaml

Work with YAML in Elm.
BSD 3-Clause "New" or "Revised" License
9 stars 5 forks source link

List of records add empty line at each list item #29

Closed RDBModel closed 1 year ago

RDBModel commented 1 year ago

Another case that, perhaps, can be improved https://ellie-app.com/k5NYB5sL7zDa1 image If there is a list of records, each record will be rendered at a new line: image It seems like the following looks better: image

RDBModel commented 1 year ago

I was able to fix such behavior by modifying condeList in Encode.elm:

encodeList : (a -> Encoder) -> EncoderState -> List a -> String
encodeList encode state l =
    let
        internalString val =
            (internalConvertToString
                { state | col = state.col + state.indent, prefix = True }
                << encode
            )
            val

        listElement : a -> String
        listElement val =
            "-" ++ (if internalString val |> String.startsWith "\n" then
                    internalString val |> String.trimLeft |> (++) " "
                else
                    internalString val)

        prefix : String
        prefix =
            if state.prefix then
                "\n"

            else
                ""

        indentAfter : String -> String
        indentAfter s =
            s ++ String.repeat state.col " "
    in
    List.map listElement l
        |> String.join (indentAfter "\n")
        |> String.append (indentAfter prefix)
MaybeJustJames commented 1 year ago

Seems reasonable. Would you like to submit a PR?

MaybeJustJames commented 1 year ago

@RDBModel I've just released 2.1.4 which fixes this. Thanks for your help :)

RDBModel commented 1 year ago

just checked the changes from 2.1.4 on https://rdbmodel.github.io/ and it is working well. Thanks!