Skip to content

Commit

Permalink
➕ Add support for fd tag in OpenLyrics XML exports
Browse files Browse the repository at this point in the history
  • Loading branch information
devmount committed Jun 14, 2024
1 parent b3730f2 commit bacd960
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
9 changes: 6 additions & 3 deletions frontend/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ const browserPrefersDark = () => {
const mailto = (address) => window.location.href = 'mailto:' + address;

// build OpenLyrics XML for given song
// see https://manual.openlp.org/display_tags.html#configuring-formatting-tags
const openLyricsXML = (song, version, translatedSong = null, locales = [], allTags = null) => {
const timestamp = (new Date()).toISOString().slice(0, -5);
const title = `<title>${song.title}</title>`;
Expand All @@ -345,16 +346,18 @@ const openLyricsXML = (song, version, translatedSong = null, locales = [], allTa
: '';
const tags = song.tags && locales && allTags
? '<themes>' + song.tags.map(
tag => locales.map(l =>`<theme lang="${l}">${allTags[tag][l] ?? tag.key}</theme>`).join('')
tag => locales.map(l =>`<theme lang='${l}'>${allTags[tag][l] ?? tag.key}</theme>`).join('')
).join('') + '</themes>'
: '';
const format = translatedSong ? `<format><tags application='OpenLP'><tag name='it'><open>&lt;em&gt;</open><close>&lt;/em&gt;</close><hidden>False</hidden></tag><tag name='gr'><open>&lt;span style='-webkit-text-fill-color:#c2c2a3'&gt;</open><close>&lt;/span&gt;</close><hidden>False</hidden></tag></tags></format>` : '';
const format = translatedSong
? `<format><tags application='OpenLP'><tag name='it'><open><![CDATA[<em>]]></open><close><![CDATA[</em>]]></close><hidden><![CDATA[False]]></hidden></tag><tag name='gr'><open><![CDATA[<span style='-webkit-text-fill-color:grey'>]]></open><close><![CDATA[</span>]]></close><hidden><![CDATA[True]]></hidden></tag><tag name='fd'><open><![CDATA[<small>]]></open><close><![CDATA[</small>]]></close><hidden><![CDATA[True]]></hidden></tag></tags></format>`
: '';
const tParts = translatedSong ? parsedContent(translatedSong.content, 0, false, false) : [];
const lyrics = parsedContent(song.content, 0, false, false).map((p, i) => {
const type = p.type ? p.type.toUpperCase() : 'V';
const num = p.number > 0 ? p.number : '1';
const tContent = (i in tParts)
? `<br/><br/><tag name='it'><tag name='gr'>${tParts[i].content.replace(/\n/g, "<br />")}</tag></tag>`
? `<br/><br/><tag name='it'><tag name='gr'><tag name='fd'>${tParts[i].content.replace(/\n/g, "<br />")}</tag></tag></tag>`
: '';
return `<verse name='${type}${num}'><lines>${p.content.replace(/\n/g, "<br />")}${tContent}</lines></verse>`;
}).join('');
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/SetlistShow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -994,7 +994,7 @@ const exportOsz = async () => {
const tParts = tSong ? parsedContent(tSong.content, 0, false, false) : [];
parts.forEach((part, i) => {
itemData.push({
'raw_slide': (i in tParts) ? part.content + "\n\n" + tParts[i].content : part.content,
'raw_slide': (i in tParts) ? `${part.content}\n\n{it}{gr}{fd}${tParts[i].content}{/fd}{/it}{/gr}` : part.content,
'verseTag': (part.type ? part.type.toUpperCase() : 'V') + (part.number > 0 ? part.number.toString() : '1'),
});
});
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/views/SongShow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -524,8 +524,15 @@ const exportSng = () => {
};
// export song in OpenLyrics XML format
const exportXml = () => {
// check for translations
const lang = !('lang' in localStorage) ? locale.value : localStorage.getItem('lang');
let tSong = null;
if (lang !== song.value.language && song.value.translations.length > 0) {
const tKey = song.value.translations.find((t) => t.endsWith(`-${lang}`));
tSong = props.songs[tKey];
}
// start download
download(openLyricsXML(song.value, version, null, availableLocales, props.tags), songId + '.xml');
download(openLyricsXML(song.value, version, tSong, availableLocales, props.tags), songId + '.xml');
// toast success message
notify({
title: t('toast.exportedXml'),
Expand Down

0 comments on commit bacd960

Please sign in to comment.