Skip to content

haskell-miso/miso-from-html

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

31 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿœ miso-from-html

Use live from your browser.

Convert HTML into miso View syntax.

Usage

Given some HTML

<nav class="navbar" role="navigation">
  <div class="navbar-brand">
    <a class="navbar-item" href="https://bulma.io">
      <img src="https://bulma.io/images/bulma-logo.png" width="112" height="28" />
      <a>ok<p>hey</p></a>
    </a>
  </div>
</nav>

Convert it to miso View syntax.

$ cabal run miso-from-html < index.html

Result

nav_
    [ class_ "navbar"
    , role_ "navigation"
    ]
    [ div_ [ class_ "navbar-brand" ]
	[ a_
	    [ class_ "navbar-item"
	    , href_ "https://bulma.io"
	    ]
	    [ img_
		[ src_ "https://bulma.io/images/bulma-logo.png"
		, width_ "112"
		, height_ "28"
		]
	    , a_ []
		[ "ok"
		, p_ [][ "hey" ]
		]
	    ]
	]
    ]

Limitations

Currently operates on a single top-level node, not on a list of nodes.

This is invalid since there is no single top-level parent node.

<div>
    foo
</div>
<div>
   bar
</div>

This is valid

<div>
  <div>
      foo
  </div>
  <div>
     bar
  </div>
</div>

Also, if your HTML isn't parsing, make sure it's valid, like <img /> needs to be closed for example.

When in doubt, check the W3C validation service.

Test

nix develop --command bash -c cabal run < index.html'

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •