From: Martin Pitt Date: Wed, 23 Sep 2026 20:45:53 +0000 (+0200) Subject: Recognize directives without argument X-Git-Url: https://piware.de/gitweb/?a=commitdiff_plain;h=587cad100cb6397f21fac9a7c728e4359b4458c1;p=chordpro-web.git Recognize directives without argument Directives like `{start_of_chorus}` or `{eoc}` did not match the directive pattern, so they were rendered literally as lyrics. They now get the same "unknown directive" warning as other unsupported ones. --- diff --git a/chordpro-web.js b/chordpro-web.js index 0d54e55..e818d17 100644 --- a/chordpro-web.js +++ b/chordpro-web.js @@ -1,6 +1,7 @@ import { html, render } from 'https://cdn.jsdelivr.net/gh/lit/dist@3.3.3/core/lit-core.min.js'; -const re_directive = /^{(\w+):\s*([^}]+)}$/; +// {name} or {name: argument} +const re_directive = /^\{(\w+)(?::\s*(.*?))?\s*\}$/; const el_song = document.getElementById('song'); const song = []; @@ -36,13 +37,13 @@ function renderChordpro(text) { if (line.startsWith('#')) continue; - let m; - if ((m = re_directive.exec(line)) !== null) { + const m = re_directive.exec(line); + if (m) { flushVerse(); - const [_, directive, value] = m; + const [, directive, value] = m; const handler = directive_handlers[directive]; if (handler) - handler(value); + handler(value ?? ''); else console.warn('unknown directive:', line); } else if (line === '') {