Open ypyl opened 1 year ago
I was able to add such support by modifying multilineStep
and postProcessString
in Util.elm file:
multilineStep : Int -> List String -> P.Parser (P.Step (List String) String)
multilineStep indent lines =
let
multilineString : List String -> String
multilineString lines_ =
String.join "\n" (List.reverse lines_)
conclusion line indent_ =
let
intendedLine =
if List.isEmpty lines then
line
else
String.repeat (indent + 1) " " ++ line
in
if indent_ > indent then
P.Loop (intendedLine :: lines)
else
P.Done (multilineString (intendedLine :: lines))
in
P.oneOf
[ P.succeed conclusion
|= characters (not << isNewLine)
|. P.chompIf isNewLine
|. spaces
|= P.getCol
, P.succeed (P.Done <| multilineString lines)
]
postProcessString : String -> String
postProcessString str =
-- let
-- regexFromString : String -> Regex
-- regexFromString =
-- Regex.fromString >> Maybe.withDefault Regex.never
-- in
str
-- |> Regex.replace (regexFromString "\\s\\s+")
-- (\match ->
-- if String.contains "\n\n" match.match then
-- "\n"
-- else
-- " "
-- )
I will be happy to prepare PR if my change makes sense.
As I am basically removing postProcessString
and I am not sure that it is correct.
If it passes the tests then I'm happy to accept it
I need some time to understand how to write/run and check unit tests in Elm. As for Elm, unfortunately I am following the next principle at least for now:
An improvement has been proposed in https://github.com/MaybeJustJames/yaml/pull/36 to parse literal multi-line strings, with tests ;-).
it seems the parser converts multiline string to simple string, e.g.
will be saved internally as
My assumption is that it should be like