const re_directive = /^\{(\w+)(?::\s*(.*?))?\s*\}$/;
const el_song = document.getElementById('song');
-const song = [];
// The chord span is emitted even when empty, so that lyrics before the first
// chord of a line still end up in the lyrics row; see chordpro.css.
const segment = (chord, text) => html`<span class="seg"><span class="chord">${chord}</span>${text}</span>`;
+// Handlers return the song content to render for the directive, if any
const directive_handlers = {
title: value => {
document.getElementById('title').textContent = value;
document.title = `${value} - ChordPro Web`;
},
- subtitle: value => document.getElementById('artist').textContent = value,
- comment: value => song.push(html`<p class="comment">${value}</p>`),
+ subtitle: value => {
+ document.getElementById('artist').textContent = value;
+ },
+ comment: value => html`<p class="comment">${value}</p>`,
};
function renderChordpro(text) {
+ const song = [];
let verseLines = [];
let verseHasChords = false;
- song.length = 0;
const flushVerse = () => {
if (verseLines.length === 0)
const [, directive, value] = m;
const handler = directive_handlers[directive];
if (handler)
- handler(value ?? '');
+ song.push(handler(value ?? ''));
else
console.warn('unknown directive:', line);
} else if (line === '') {