Giter VIP home page Giter VIP logo

miso-from-html's Introduction

miso-from-html

Hackage Haskell Programming Language BSD3 LICENSE Build Status

Convert HTML into miso View syntax.

Features

  • Strips comments
  • Pretty prints style tags as a Haskell Map from Data.Map

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" ]
		]
	    ]
	]
    ]

Test

$ nix-shell --run 'runghc Main.hs < index.html'

miso-from-html's People

Contributors

dmjio avatar itsrachelfish avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

itsrachelfish

miso-from-html's Issues

Checkboxes should be converted to `checked_`

Currently checkbox elements are converted into textProp "checked" "", but it is actually more convenient to use checked_ True as this allows you to change the boolean value of the checkbox.

<input type="checkbox" checked>
[ input_
   [ type_ "checkbox"
   , textProp "checked" ""
   ]
]

Add more robust error handling

When encountered ill-formed HTML. It would be nice is miso-from-html emitted an error like:

"error expected </div> on line 344"

Data attributes converted to Miso despite not being supported

Miso does not support all HTML attributes, but miso-from-html will happily turn any HTML you give it into miso syntax.

For example data attributes are converted into Miso, but it does not appear that Miso actually supports hyphenated element names

    parse error on input ‘data’
    |
    |   , data-toggle_ "dropdown"
    |     ^^^^

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.