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

How do I deal with inline Svg with type-of-html? #5

Open
tonyalaribe opened this issue May 14, 2021 · 8 comments
Open

How do I deal with inline Svg with type-of-html? #5

tonyalaribe opened this issue May 14, 2021 · 8 comments

Comments

@tonyalaribe
Copy link

It seems there are no svg elements or attributes defined. Is there any recommended workaround?

I also tried creating custom attributes, but couldn't get it to work. It just says the bool constructors are not in scope:
image

@knupfer
Copy link
Owner

knupfer commented May 15, 2021

Well, it seams you don't have the Prelude imported.
You can import Data.Bool if you wish to avoid the Prelude, Data.Type.Bool isn't needed in this snippet.
Please make also sure, that you use the DataKinds language pragma.
Just as you tried, you can define your custom attributes and your custom elements just fine. For custom elements, you'll need probably as well TypeOperators language pragma.

Please report if this works for you. Perhaps I'll add natively svg stuff in the coming weeks (pr welcome).
Greets

@tonyalaribe
Copy link
Author

That's true. Simply importing the Prelude fixed it. Thanks!!!
I'm still new to haskell, so I was mostly following the examples from the repository. But it seems to work now. Or at least, I get a different set of errors now. Mostly related to the custom elements which I will try.

About Svg, I'm happy to make a PR for that. Thanks!

@tonyalaribe
Copy link
Author

tonyalaribe commented May 15, 2021

Just on the topic of making a pr for Svg support, How would you recommend implementing this?
I feel Svg would be better in a different file/namespace. Then we could do something like import Html.Svg or something similar, because the Svg elements and attributes list is quite large as well, so maybe we can benefit from keeping it separate from HTML?

Also, I imagine just doing this via Custom elements (CustomElement and CustomA) is not really clean, or what do you think?
How can I extend the attributes and elements list from a different module?

-- | 4 The elements of HTML
data Element (name :: Symbol) (categories :: [ContentCategory]) (contentModel :: ContentCategory) (contentAttributes :: [Symbol]) where

  DOCTYPE
    :: Element
    "!DOCTYPE html"
    '[]
    None
    '[]

  -- | \ 4.1 The document element
  --     4.1.1
  Html
    :: Element
    "html"
    '[]
    -- A head element followed by a body element.
    (Elements ["head", "body"])
    (ManifestA & '[])

Sorry I'm really new to haskell, so I don't have a good grasp of type level things. But if you point me in the right direction, this should be doable. The bulk of the work is mostly the manual work of listing out the elements and the attributes.

https://developer.mozilla.org/en-US/docs/Web/SVG/Element
https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute

@tonyalaribe
Copy link
Author

Hi, gentle reminder about this. I know this issue is closed, but it would be nice to get a heads-up, which will help me work on the svg support or. :)

@tonyalaribe tonyalaribe reopened this May 29, 2021
@knupfer
Copy link
Owner

knupfer commented Jun 7, 2021

Hi, sorry for the late answer.
There are at least some options to implement this.

Just put it all into data Element and export everything, or put everything into data Element and make a handcrafted exportlist of constructors. The second option is a headache for maintenance, but allows for an Html.SVG module...

I'll think a bit more, but it seems to me, that svg is widely used and therefore well put into data Element.

@knupfer
Copy link
Owner

knupfer commented Jun 7, 2021

Thinking more about it, perhaps a data family would be a good extensible fit...

@tonyalaribe
Copy link
Author

tonyalaribe commented Jun 7, 2021 via email

@knupfer
Copy link
Owner

knupfer commented Jun 9, 2021

Just pushed a new version to github, look at the Html.Aria module for examples for attributes and at the Html.Obsolete module for examples for elements. If your stuck, just write a message

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