Skip to content

Commit

Permalink
Demo: take advantage of selector option
Browse files Browse the repository at this point in the history
  • Loading branch information
slevithan committed May 17, 2024
1 parent 4143fe1 commit b4b2e81
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ <h3>Quoted string, allowing escaped quotes and backslashes</h3>
<pre class="regex">(["'])(?:\\?.)*?\1</pre>

<h2>Try it</h2>
<p><textarea id="input" placeholder="Type a regex pattern" spellcheck="false" oninput="colorizeInput(); autoGrow(this)"></textarea></p>
<p><textarea placeholder="Type a regex pattern" spellcheck="false" oninput="showOutput(this.value || this.placeholder); autoGrow(this)"></textarea></p>
<figure>
<pre id="output" class="regex">Type a regex pattern</pre>
<figcaption>
<label>
<input id="flag-u" type="checkbox" onchange="colorizeInput()">
<input type="checkbox" onchange="setFlagsFor('output', this.checked ? 'u' : '')">
Flag <code>u</code> <small>(<code>unicode</code>)</small>
</label>
</figcaption>
Expand Down Expand Up @@ -152,14 +152,12 @@ <h2>Usage</h2>
<script>
RegexColorizer.colorizeAll();

function colorizeInput() {
const pattern = document.getElementById('input').value || 'Type a regex pattern';
const unicodeOn = document.getElementById('flag-u').checked;
const flags = unicodeOn ? 'u' : '';
const html = RegexColorizer.colorizePattern(pattern, {
flags,
function showOutput(pattern) {
document.getElementById('output').innerHTML = pattern;
RegexColorizer.colorizeAll({
selector: '#output',
});
document.getElementById('output').innerHTML = html;
// Alternatively, could use `RegexColorizer.colorizePattern` and assign to `innerHTML`
}

function autoGrow(el) {
Expand Down

0 comments on commit b4b2e81

Please sign in to comment.