mtb

mithril-template-builder

Mithril HTML to JavaScript converter

Showing:

Popularity

Downloads/wk

2

GitHub Stars

83

Maintenance

Last Commit

1mo ago

Contributors

2

Package

Dependencies

0

License

MIT

Type Definitions

Tree-Shakeable

Yes?

Categories

Readme

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:

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100