/* * Copyright 2019 Adobe. All rights reserved. * This file is licensed to you under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. You may obtain a copy * of the License at http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software distributed under * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS * OF ANY KIND, either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ /* eslint-disable */ const { JSDOM } = require('jsdom'); const { Compiler, Runtime } = require('@adobe/htlengine'); const code = '' + '' + '' + '${doc.title}\n' + '\n' + '

Table of Contents

\n' + '\n' + '' + ''; const html = '' + '

JSDOM Example

' + 'This example shows how t use JSDOM with the HTL Engine.' + '

Install

' + 'foo bar...' + '

Run

' + 'npm test' + '

Development

' + 'contributions welcome'; async function run() { // setup the HTL compiler const compiler = new Compiler().withRuntimeVar('document'); const template = await compiler.compileToFunction(code, __dirname, require); // generate the input data using JSDOM const document = new JSDOM(html).window.document; // create a dom factory, providing a document implementation const domFactory = new Runtime.VDOMFactory(document.implementation); // create the HTL runtime const runtime = new Runtime() .withDomFactory(domFactory) .setGlobal({ document }); // finally, execute the template. the result is a Document. const result = await template(runtime); return `${result.documentElement.outerHTML}`; } run().then(console.log).catch(console.error);