1
1
import Formatter from './formatter' ;
2
- import Configuration from './configuration' ;
2
+ import Configuration , { ConfigurationProperties } from './configuration' ;
3
3
import Song from '../chord_sheet/song' ;
4
4
import { scopeCss } from '../utilities' ;
5
5
import Paragraph from '../chord_sheet/paragraph' ;
6
6
7
+ export interface HtmlTemplateCssClasses {
8
+ annotation : string ,
9
+ chord : string ,
10
+ chordSheet : string ,
11
+ column : string ,
12
+ comment : string ,
13
+ emptyLine : string ,
14
+ label : string ,
15
+ labelWrapper : string ,
16
+ line : string ,
17
+ literal : string ,
18
+ literalContents : string ,
19
+ lyrics : string ,
20
+ paragraph : string ,
21
+ row : string ,
22
+ subtitle : string ,
23
+ title : string ,
24
+ }
25
+
7
26
export interface HtmlTemplateArgs {
8
27
configuration : Configuration ;
9
28
song : Song ;
10
29
renderBlankLines ?: boolean ;
11
30
bodyParagraphs : Paragraph [ ] ,
31
+ cssClasses : HtmlTemplateCssClasses ,
12
32
}
13
33
14
34
export type Template = ( _args : HtmlTemplateArgs ) => string ;
15
35
export type CSS = Record < string , Record < string , string > > ;
16
36
37
+ export const defaultCssClasses : HtmlTemplateCssClasses = {
38
+ annotation : 'annotation' ,
39
+ chord : 'chord' ,
40
+ chordSheet : 'chord-sheet' ,
41
+ column : 'column' ,
42
+ comment : 'comment' ,
43
+ emptyLine : 'empty-line' ,
44
+ label : 'label' ,
45
+ labelWrapper : 'label-wrapper' ,
46
+ line : 'line' ,
47
+ literal : 'literal' ,
48
+ literalContents : 'contents' ,
49
+ lyrics : 'lyrics' ,
50
+ paragraph : 'paragraph' ,
51
+ row : 'row' ,
52
+ subtitle : 'subtitle' ,
53
+ title : 'title' ,
54
+ } ;
55
+
17
56
/**
18
57
* Acts as a base class for HTML formatters
19
58
*/
20
59
abstract class HtmlFormatter extends Formatter {
60
+ cssClasses : HtmlTemplateCssClasses ;
61
+
62
+ /**
63
+ * Instantiate the formatter. For all options see {@link Formatter}
64
+ * @param {Object } [configuration={}] options
65
+ * @param {object } [configuration.cssClasses={}] CSS classes to use in the HTML output. The default classes are
66
+ * defined in {@link defaultCssClasses}. You can override them by providing your own classes here:
67
+ * @example
68
+ * ```javascript
69
+ * {
70
+ * cssClasses: {
71
+ * annotation: 'my-annotation',
72
+ * chord: 'my-chord',
73
+ * chordSheet: 'my-chord-sheet',
74
+ * column: 'my-column',
75
+ * comment: 'my-comment',
76
+ * emptyLine: 'my-empty-line',
77
+ * label: 'my-label',
78
+ * labelWrapper: 'my-label-wrapper',
79
+ * line: 'my-line',
80
+ * literal: 'my-literal',
81
+ * literalContents: 'my-contents',
82
+ * lyrics: 'my-lyrics',
83
+ * paragraph: 'my-paragraph',
84
+ * row: 'my-row',
85
+ * subtitle: 'my-subtitle',
86
+ * title: 'my-title',
87
+ * }
88
+ * }
89
+ * ```
90
+ */
91
+ constructor ( configuration : ConfigurationProperties & { cssClasses ?: Partial < HtmlTemplateCssClasses > } = { } ) {
92
+ super ( configuration ) ;
93
+ this . cssClasses = { ...defaultCssClasses , ...configuration . cssClasses } ;
94
+ }
95
+
21
96
/**
22
97
* Formats a song into HTML.
23
98
* @param {Song } song The song to be formatted
@@ -31,6 +106,7 @@ abstract class HtmlFormatter extends Formatter {
31
106
song,
32
107
configuration : this . configuration ,
33
108
bodyParagraphs : this . configuration . expandChorusDirective ? expandedBodyParagraphs : bodyParagraphs ,
109
+ cssClasses : this . cssClasses ,
34
110
} ,
35
111
) ;
36
112
}
@@ -48,7 +124,7 @@ abstract class HtmlFormatter extends Formatter {
48
124
* @returns {string } the CSS string
49
125
*/
50
126
cssString ( scope = '' ) : string {
51
- return scopeCss ( this . defaultCss , scope ) ;
127
+ return scopeCss ( this . cssObject , scope ) ;
52
128
}
53
129
54
130
/**
0 commit comments