Skip to content

Commit a8e7561

Browse files
Use correct metadata separator in TextFormatter (#1603)
1 parent b4c929a commit a8e7561

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
"debug:chords-over-words": "yarn build && tsx script/debug_parser.ts chords_over_words --include-chord-grammar",
6969
"eslint": "node_modules/.bin/eslint",
7070
"lint": "yarn unibuild lint",
71+
"lint:fix": "yarn unibuild lint --fix",
7172
"prepare": "yarn install && yarn build",
7273
"release": "yarn unibuild release",
7374
"test": "yarn unibuild lint && yarn unibuild test",

src/formatter/text_formatter.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Formatter from './formatter';
22
import ChordLyricsPair from '../chord_sheet/chord_lyrics_pair';
33
import Tag from '../chord_sheet/tag';
44
import { renderChord } from '../helpers';
5-
import { hasTextContents, renderSection } from '../template_helpers';
5+
import { evaluate, hasTextContents, renderSection } from '../template_helpers';
66
import Song from '../chord_sheet/song';
77
import { hasRemarkContents, isEmptyString, padLeft } from '../utilities';
88
import Paragraph from '../chord_sheet/paragraph';
@@ -169,7 +169,7 @@ class TextFormatter extends Formatter {
169169
}
170170

171171
if ('evaluate' in item) {
172-
return item.evaluate(metadata, this.configuration.metadataSeparator);
172+
return evaluate(item, metadata, this.configuration);
173173
}
174174

175175
return '';

test/formatter/text_formatter.test.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { GRID } from '../../src/constants';
66
import { ContentType } from '../../src/serialized_types';
77

88
import {
9-
ABC, LILYPOND, TAB, TextFormatter,
9+
ABC, ChordProParser, LILYPOND, TAB, TextFormatter,
1010
} from '../../src';
1111

1212
import {
@@ -237,6 +237,24 @@ Let it be, let it be, let it be, let it be`;
237237
expect(formatted).toEqual('Asus2\nLet it be');
238238
});
239239

240+
it('can use a custom metadata separator', () => {
241+
const song = new ChordProParser().parse(heredoc`
242+
{composer: John}
243+
{composer: Jane}
244+
245+
Composers: %{composer}
246+
`);
247+
248+
const rendered = new TextFormatter({
249+
metadata: {
250+
separator: ' and ',
251+
},
252+
})
253+
.format(song);
254+
255+
expect(rendered).toEqual('Composers: John and Jane');
256+
});
257+
240258
describe('delegates', () => {
241259
[ABC, GRID, LILYPOND, TAB].forEach((type) => {
242260
describe(`for ${type}`, () => {

0 commit comments

Comments
 (0)