mdgriffith / elm-markup

Elm-friendly markup

Home Page:https://package.elm-lang.org/packages/mdgriffith/elm-markup/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

a `oneOf` with just one item fails with an empty error list

BrianHicks opened this issue · comments

Here's the code I'm working with!

module Document exposing (demo, document)

import Browser
import Html
import Mark exposing (Block, Text)


demo =
    String.trim """
| Page
    title = Speak at elm-conf
    slug = speak

text
    """


document =
    Mark.document identity <|
        -- Mark.oneOf [ page ]
        page


type alias Page =
    { title : String
    , slug : String
    , contents : List Content
    }


page : Block Page
page =
    Mark.startWith
        (\( title, slug ) contents -> Page title slug contents)
        (Mark.record2
            "Page"
            Tuple.pair
            (Mark.field "title" Mark.string)
            (Mark.field "slug" Mark.string)
        )
        body


type Content
    = Paragraph (List Text)


body : Block (List Content)
body =
    Mark.manyOf
        [ Mark.map Paragraph
            (Mark.text
                { view = identity
                , inlines = []
                , replacements = []
                }
            )
        ]


main =
    Html.main_
        []
        [ Html.pre [] [ Html.text demo ]
        , case Mark.parse document demo of
            Err problems ->
                Html.div []
                    [ Html.text "Problems!"
                    , problems
                        |> List.map
                            (\problem ->
                                Html.li [] [ Html.text (Debug.toString problem) ]
                            )
                        |> Html.ul []
                    ]

            Ok stuff ->
                Html.div []
                    [ Html.text "Success!"
                    , Html.text (Debug.toString stuff)
                    ]
        ]

If you swap the commented-out and actual lines in document, the document will fail to parse with an empty error list. Not sure what's going on here, or if there is something in the rest of the code here that would cause this, so I haven't minified very much! Let me know if that would be helpful.

fixed in v3! Don't know the cause, but fixed now :)