* renders the given HEML string with the config provided * @param {String} HEML the heml to render * @param {Object} options the options * @return {Object} { metadata, html, errors }
(contents, options = {})
| 15 | * @return {Object} { metadata, html, errors } |
| 16 | */ |
| 17 | async function heml (contents, options = {}) { |
| 18 | const results = {} |
| 19 | const { |
| 20 | beautify: beautifyOptions = {}, |
| 21 | validate: validateOption = 'soft' |
| 22 | } = options |
| 23 | |
| 24 | options.elements = flattenDeep(toArray(coreElements).concat(options.elements || [])) |
| 25 | |
| 26 | /** parse it ✂️ */ |
| 27 | const $heml = parse(contents, options) |
| 28 | |
| 29 | /** validate it 🕵 */ |
| 30 | const errors = validate($heml, options) |
| 31 | if (validateOption.toLowerCase() === 'strict' && errors.length > 0) { throw errors[0] } |
| 32 | if (validateOption.toLowerCase() === 'soft') { results.errors = errors } |
| 33 | |
| 34 | /** render it 🤖 */ |
| 35 | const { |
| 36 | $: $html, |
| 37 | metadata |
| 38 | } = await render($heml, options) |
| 39 | |
| 40 | /** inline it ✍️ */ |
| 41 | inline($html, options) |
| 42 | |
| 43 | /** beautify it 💅 */ |
| 44 | results.html = condition.replace(beautify($html.html(), { |
| 45 | indent_size: 2, |
| 46 | indent_inner_html: true, |
| 47 | preserve_newlines: false, |
| 48 | extra_liners: [], |
| 49 | ...beautifyOptions })) |
| 50 | |
| 51 | /** final touches 👌 */ |
| 52 | metadata.size = `${(byteLength(results.html) / 1024).toFixed(2)}kb` |
| 53 | results.metadata = metadata |
| 54 | |
| 55 | /** send it back 🎉 */ |
| 56 | return results |
| 57 | } |
| 58 | |
| 59 | /** module.exports for commonjs */ |
| 60 | module.exports = heml |
no test coverage detected