Я пытаюсь использовать JavaScript для преобразования форматирования Ultimate Guitar.com в AcrognableTools/chordPro, поскольку я собираюсь использовать код JavaScript в GDEVELT5, чтобы сделать веб -приложение для моей церкви для использования
Я пытался написать его много способов, но он точно не вкладывает текст встроенный, но мои кодовые выходы только
[G] [D] [Em]
Amazing grace, how sweet the sound
[G] [D] [C]
That saved a wretch like me
< /code>
Я попробовал это < /p>
function convertUltimateGuitarToWorshipTools(ultimateGuitarText) {
// Split input text into lines (songs may have multiple lines of chords/lyrics)
const lines = ultimateGuitarText.split('\n');
const worshipToolsText = lines.map(line => {
// This pattern finds the chords, which are typically words in uppercase or lowercase
const chordPattern = /\b([A-G][#b]?(m|maj|min|sus|dim|aug)?)\b/g;
// Replace each found chord with the WorshipTools format (i.e., [chord] )
return line.replace(chordPattern, (match, chord) => {
return `[${chord}]`;
});
}).join('\n'); // Join the lines back into a single string
return worshipToolsText;
}
// Example Ultimate Guitar input (with chords above the lyrics)
const ultimateGuitarText = `
G D Em
Amazing grace, how sweet the sound
G D C
That saved a wretch like me
`;
// Convert the Ultimate Guitar text to WorshipTools format
const worshipToolsText = convertUltimateGuitarToWorshipTools(ultimateGuitarText);
// Output the converted text
console.log(worshipToolsText);
< /code>
Но мне нужно, чтобы это было выходом < /p>
[G]Amazing grac[D]e, how swee[Em]t the sound
[G]That saved [D]a wretch lik[C]e me
Подробнее здесь: https://stackoverflow.com/questions/795 ... javascript