| | |
| |
|
| | var parseCommon = require('./abc_common'); |
| |
|
| | var bookParser = function(book) { |
| | "use strict"; |
| |
|
| | var directives = ""; |
| | var initialWhiteSpace = book.match(/(\s*)/) |
| | book = parseCommon.strip(book); |
| | var tuneStrings = book.split("\nX:"); |
| | |
| | for (var i = 1; i < tuneStrings.length; i++) |
| | tuneStrings[i] = "X:" + tuneStrings[i]; |
| | |
| | var pos = initialWhiteSpace ? initialWhiteSpace[0].length : 0; |
| | var tunes = []; |
| | tuneStrings.forEach(function(tune) { |
| | tunes.push({ abc: tune, startPos: pos}); |
| | pos += tune.length + 1; |
| | }); |
| | if (tunes.length > 1 && !parseCommon.startsWith(tunes[0].abc, 'X:')) { |
| | |
| | |
| | |
| | var dir = tunes.shift(); |
| | var arrDir = dir.abc.split('\n'); |
| | arrDir.forEach(function(line) { |
| | if (parseCommon.startsWith(line, '%%')) |
| | directives += line + '\n'; |
| | }); |
| | } |
| | var header = directives; |
| |
|
| | |
| | tunes.forEach(function(tune) { |
| | var end = tune.abc.indexOf('\n\n'); |
| | if (end > 0) |
| | tune.abc = tune.abc.substring(0, end); |
| | tune.pure = tune.abc; |
| | tune.abc = directives + tune.abc; |
| |
|
| | |
| | tune.title = ""; |
| | var title = tune.pure.split("T:"); |
| | if (title.length > 1) { |
| | title = title[1].split("\n"); |
| | tune.title = parseCommon.strip(title[0]); |
| | } |
| |
|
| | |
| | var id = tune.pure.substring(2, tune.pure.indexOf("\n")); |
| | tune.id = parseCommon.strip(id); |
| | }); |
| |
|
| | return { |
| | header: header, |
| | tunes: tunes |
| | }; |
| | }; |
| |
|
| | module.exports = bookParser; |
| |
|
| |
|