<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>wxml parser rust</title>
</head>
<body>
<style>
* {
padding: 0;
margin: 0;
}
body {
color: 333;
font-size: 20px;
}
.container {
display: flex;
height: 100vh;
}
.editor,
.output {
flex: 1;
background: rgba(127, 127, 127, .1);
border: 1px solid rgba(127, 127, 127, .5);
margin: 20px;
border-radius: 10px;
padding: 20px;
white-space: pre-wrap;
word-break: break-all;
resize: none;
font-size: 16px;
}
</style>
<div class="container">
<textarea name="" id="" cols="30" rows="10" class="editor"
placeholder="Please input any wxml template..."></textarea>
<pre class="output"></pre>
</div>
<script type="module">
import init, { compile } from './wxml_parser.js';
init().then(() => {
const input = document.querySelector('.editor');
const output = document.querySelector('.output');
input.value = `<view wx:for="{{list}}">\n hello {{item}}!\n <text wx:if="{{a}}">a</text>\n <text wx:elseif="{{b}}">b</text>\n <text wx:else />\n</view>`;
output.textContent = compile(input.value);
input.oninput = (e) => {
const i = e.target.value
const o = compile(i)
output.textContent = o;
}
})
</script>
</body>
</html>