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

Feature request: optional blocks

BrianHicks opened this issue · comments

Problem

I am writing templates to render instructions for our students. Right now it's done using naive string replacement, and so I'm using elm-markup to make something a little more robust. A sample template might start like Good job, {{NAME}}!, which I've translated to Good job, []{studentName}!.

One reason I'm doing this is because we want to give our curriculum department the ability to insert links to more detailed lessons in the middle of the instruction text. I've got that working ([See an example]{lesson|id=2}.)

While I was doing this, I wanted to add a way to optionally set an icon in the button link. That doesn't look like it's possible right now! It seems like there are no optional fields in records. I'd like to be able to do that for some other things I have planned, so I thought I'd open an issue and ask.

Suggestion

I would like something like:

optionalField : String -> Block value -> Record (Maybe value -> result) -> Record result

which, for annotation "x" identity |> optionalField "field" int, would mean:

input output
[]{x|field=1} Success (Just 1)
[]{x} Success Nothing
[]{x|field=foo} Failure …

verify would only run if the value is present, and would cause failure normally.