Skip to content

Commit

Permalink
feat: improve chords regexps
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Chodur <[email protected]>
  • Loading branch information
FUSAKLA committed Apr 6, 2024
1 parent 4b0b086 commit 82c9a33
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
5 changes: 2 additions & 3 deletions src/chords/images.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ function SaveUserInstrument(instrument: string) {
}

function loadUserInstrument() {
const instrument = PropertiesService.getUserProperties().getProperty(
"userInstrument"
);
const instrument =
PropertiesService.getUserProperties().getProperty("userInstrument");
if (instrument === null) {
return supportedInstruments[0];
}
Expand Down
4 changes: 2 additions & 2 deletions src/chords/utils.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
function getDocumentChordsParagraphs(doc: GoogleAppsScript.Document.Document) {
const body = doc.getBody();
const chordsRe =
/^\s*(?:[A-Za-z]+\:\s*)?(?:\(?([A-Z][a-zA-Z0-9#!/]{0,6})\)?\s*)+\s*$/;
/^\s*(?:[A-Za-z]+\:\s*)?(?:[\[\|\/\(]*([A-Z][a-zA-Z0-9#!/]{0,6})[\|\/\(\]]*\s*)+\s*$/;
const paragraphs = body.getParagraphs();
const chordsParagraphs: GoogleAppsScript.Document.Paragraph[] = [];
for (let i = 0; i < paragraphs.length; i++) {
Expand All @@ -16,7 +16,7 @@ function getDocumentChordsParagraphs(doc: GoogleAppsScript.Document.Document) {
function getChords(doc: GoogleAppsScript.Document.Document) {
const chords: string[] = [];
for (const p of getDocumentChordsParagraphs(doc)) {
for (const chord of p.getText().split(/\s+/)) {
for (const chord of p.getText().split(/\s+|[\|\/\(\)\[\]]+/)) {
if (chord.trim() === "") {
continue;
}
Expand Down

0 comments on commit 82c9a33

Please sign in to comment.