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

Higher level structure

danfishgold opened this issue · comments

I'd like to be able to enforce some global structure:

-- title : Block (Html msg)
-- description : Block (Html msg)
-- photo : Block (Html msg)

document : Block (List (Html msg))
document =
    title
    |> Mark.followedBy description
    |> Mark.followedBy (Mark.manyOf [ photo ])

This would parse a document such as this one:

|> Title
    Greece 2016

|> Description
    These are photos I took in Greece in 2016

|> Photo
    url = https://whatever.com/hotel.jpg
    description = Our hotel

|> Photo
    url = https://whatever.com/beach.jpg
    description = The beach

but would fail for documents that, for example, don't have a description or that have the title appear after the description.

This could be implemented by making a record block that has fields for title, description, and photos that takes care of rendering them in the correct order, but that feels less readable than using top level blocks for each (title, description, photo.)

I think these functions could be useful:

  • followedBy
  • optional (like ? in regex)
  • oneOrMore (like +)

Right now you can use documentWith which requires a starting block.

|> Metadata
    title = Greece 2016
    description =
        These are photos I took in Greece in 2016

|> Photo
    url = https://whatever.com/hotel.jpg
    description = Our hotel

|> Photo
    url = https://whatever.com/beach.jpg
    description = The beach