Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What should the behavior be for unhandled HTML attributes? #21

Open
dillonkearns opened this issue Jan 14, 2020 · 2 comments
Open

What should the behavior be for unhandled HTML attributes? #21

dillonkearns opened this issue Jan 14, 2020 · 2 comments

Comments

@dillonkearns
Copy link
Owner

Right now, if you have an HTML handler like this:

Markdown.Html.tag "Bio"
    (\avatar name children -> Bio.view avatar name)
    |> Markdown.Html.withAttribute "avatar"
    |> Markdown.Html.withOptioanlAttribute "name"

You may experience confusing behavior if you pass in arguments that are not handled. For example, this will successfully render, but will completely ignore first and last

<Bio first="Dillon" last="Kearns" avatar="https://avatars3.githubusercontent.com/u/1384166?s=460&v=4 />

Pros and Cons

There are tradeoffs either way. By being explicit, it's less confusing when you are passing something with the wrong argument names. Or if you are building something with a CMS like Netlify CMS, you can cause the build to fail with something like elm-pages, for example, if you pass invalid arguments, so you can get early feedback.

But on the other side, there's the question of compatibility if you are trying to inter-operate with other custom elements that may have some arguments you're not handling yet. It may be reasonable to just have an error here and then let you handle it. But worth considering.

@matheus23
Copy link
Contributor

matheus23 commented Feb 19, 2020

I understand it is possible to lose power by forcing all attributes to be handled, but I would love to have typos be checked!

Maybe there is something with the best of both worlds? Wouldn't it be possible to implement some function like Markdown.Html.withAllAttributes that gives the list of key-value attribute pairs of all attributes. If it is included, there can't be an error with missing attributes. If it isn't included, any attribute that's not handled causes an error.

What do you think?

withAllAttributes :
    Renderer (List { key : String, value : String } -> view)
    -> Renderer view

@dillonkearns
Copy link
Owner Author

@matheus23 yeah, I agree, I think that's a nice balance.

Maybe something like

catchUnhandledAttributes :
    Renderer (List { key : String, value : String } -> view)
    -> Renderer view

And it would only give you the unhandled ones, not all attributes. Seems pretty nice, what do you think of that idea?

I like the term catch because it gives a clear indication that it changes the behavior from potentially giving an error to catching that error case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants