Code Monkey home page Code Monkey logo

mithril-template-converter's Introduction

Mithril HTML to JavaScript converter

Online converter

Open online converter

Template Builder

Helper function to create Mithril templates from HTML. Use the output text to copy-paste into your source code.

/**
 * @param {object} opts 
 * @param {string} opts.source - String containing HTML markup
 * @param {("2" | "4" | "tab")} opts.indent - Indent spacing
 * @param {("double" | "single")} opts.quotes - Quotes
 * @param {("attributes" | "selectors")} opts.attrs - Display of attributes
 * @returns {string}
 */
const resultString = templateBuilder(opts)

Usage in modules

import { templateBuilder } from "mithril-template-builder"

const source = `
<p>Mithril website: <a href="http://mithril.js.org">Mithril website</a></p>
`
const output = templateBuilder({
  source
})

Output:

m("p",
  [
    "Mithril website: ",
    m("a", {"href":"http://mithril.js.org"}, 
      "Mithril website"
    )
  ]
)
import { templateBuilder } from "mithril-template-builder"

const source = `
<a href="http://mithril.js.org">Mithril</a>
`
const output = templateBuilder({
  source,
  indent: "4",
  attrs: "selectors",
  quotes: "single",
})

Output:

m('a[href="http://mithril.js.org"]', 
    'Mithril'
)

App

Contains source code for the online converter.

Helper patterns and libraries:

mithril-template-converter's People

Contributors

arthurclemens avatar dependabot[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mithril-template-converter's Issues

JSX flag?

You know, for converting from React ๐Ÿ‘€

please support Mithril 1.0.0

Mithril 1.0.0 (rewrite branch) has a slightly different API. The converter should also be upgraded accordingly

Preserve newlines & whitespace in preformatted text

The HTML code

<pre><code>if (condition) {
    doThis();
} else {
    doThat();
}
</code></pre>

for example is translated to

m("pre", 
  m("code", 
    "if (condition) { doThis(); } else { doThat(); } "
  )
)

and hence rendered as

if (condition) { doThis(); } else { doThat(); } 

instead of

if (condition) { 
    doThis(); 
} else { 
    doThat(); 
} 

Could the content of pre elements be translated without whitespace & newline removal ? At least in theory ?
(Somehow related to #5.)

Cheers,

SB

Whitespace sometimes discarded

When converting the following HTML fragment, the converter discards the whitespace between the two words.

<p>hello <a href="https://example.com/">world</a></p>

Is converted to:

m("p",
  [
    "hello",
    m("a", {"href":"https://example.com/"}, 
      "world"
    )
  ]
)

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.