Adding special preparser for /b chords

This commit is contained in:
2024-07-08 12:06:41 +02:00
parent d0c7c80616
commit 75a782977f
2 changed files with 11 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
import { get_chord_sheet_html } from "./Editor.js"; import { get_chord_sheet_html } from "./Editor";
window.onload = () => { window.onload = () => {
const chord_sheet_html = get_chord_sheet_html(` const chord_sheet_html = get_chord_sheet_html(`

View File

@@ -48,13 +48,11 @@ function render_sheet_html(sheet: Sheet, renderChord:any): string {
} }
function render_chord(chord: Chord, renderer:any): string { function render_chord(chord: Chord, renderer:any): string {
return "<span class='chord' style='cursor: pointer;'>" + renderer(chord) + "</span>" return "<span class='chord'>" + renderer(chord) + "</span>"
} }
export function get_chord_sheet_html(normalized_txt: string): string { export function get_chord_sheet_html(normalized_txt: string): string {
const parseChord = chordParserFactory(); const parseChord = chordParserFactory( { customFilters : []} );
const renderChord = chordRendererFactory({ useShortNamings: true }); const renderChord = chordRendererFactory({ useShortNamings: true });
const lines = normalized_txt.split("\n") const lines = normalized_txt.split("\n")
@@ -65,11 +63,18 @@ export function get_chord_sheet_html(normalized_txt: string): string {
let sheet_line = new Line(); let sheet_line = new Line();
if (words.length > 1 || words[0] == '') { if (words.length > 1 || words[0] == '') {
let space_before_chord = 0; let space_before_chord = 0;
for (const word of words) { for (let word of words) {
if (word != '') { if (word != '') {
if (space_before_chord > 0 || sheet_line.chords.length > 0) { if (space_before_chord > 0 || sheet_line.chords.length > 0) {
space_before_chord++; space_before_chord++;
} }
//preprocessing for special slash notation
if (word.indexOf('/') > -1) {
const parts = word.split('/')
if (/^(b|#)\d+$/.test(parts[1])) {
word = parts[0] + "(" + parts[1] + ")"
}
}
const chord = parseChord(word); const chord = parseChord(word);
if (chord.error) { if (chord.error) {
sheet_line.lyrics = line; sheet_line.lyrics = line;