Coder Social home page Coder Social logo

html-elm's Introduction

html-elm

Convert HTML and SVG to Elm code

Install

$ npm install html-elm

Usage

import htmlElm from 'html-elm'

const htmlString = '<div class="wrapper"><h1 id="title">Hello World</h1></div>'

// htmlElm returns a Promise
htmlElm(htmlString, {
  indent: 2,
  htmlAlias: 'Html',
  htmlAttributeAlias: 'H',
  svgAlias: 'Svg',
  svgAttributeAlias: 'S',
  imports: true,
}).then(console.log)

// Result will be a string with valid Elm code:
//
// import Html
// import Html.Attributes as H
//
// Html.div
//   [ H.class "wrapper" ]
//   [ Html.h1
//     [ H.id "title" ]
//     [ Html.text "Hello World" ]
//   ]

// All options are optional
htmlElm(html)

CLI

Install it globally

$ npm install -g html-elm

Usage:

$ html-elm '<div class="container"><h1>Hello all</h1><p>Lorem ipsum dolor</p></div>'

div
    [ class "container" ]
    [ h1
        []
        [ text "Hello all" ]
    , p
        []
        [ text "Lorem ipsum dolor" ]
    ]

To see all available options use:

$ html-elm -h

License

MIT

html-elm's People

Contributors

dependabot[bot] avatar hendriklammers avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

promax204

html-elm's Issues

parsing issue (with class?)

Running
$ html-elm $(echo $(cat nav.tmp.html) ) > nav.tmp.elm

where the nav.tmp.html files is:

> <ul class="nav justify-content-center">
>   <li class="nav-item">
>     <a class="nav-link active" href="#">Active</a>
>   </li>
>   <li class="nav-item">
>     <a class="nav-link" href="#">Link</a>
>   </li>
>   <li class="nav-item">
>     <a class="nav-link" href="#">Link</a>
>   </li>
>   <li class="nav-item">
>     <a class="nav-link disabled" href="#">Disabled</a>
>   </li>
> </ul>
> 

gives:

ulclass="navjustify-content-center"
[]
[ liclass="nav-item"
[]
[ aclass="nav-linkactive"href="#"
[]
[ text "Active"
, liclass="nav-item"
[]
[ aclass="nav-link"href="#"
[]
[ text "Link"
, liclass="nav-item"
[]
[ aclass="nav-link"href="#"
[]
[ text "Link"
, liclass="nav-item"
[]
[ aclass="nav-linkdisabled"href="#"
[]
[ text "Disabled" ]
]
]
]
]
]
]
]
]

Version:
$ html-elm -V
3.1.1

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.