Skip to content

Repository files navigation

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:

About

Mithril HTML to JavaScript converter

Topics

Resources

Stars

96 stars

Watchers

2 watching

Forks

Releases

Packages

Used by

Contributors

Languages