From ba0e53ee6a51c822ca3027f3403172d47c33eace Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Tue, 3 Aug 2021 00:05:22 -0700 Subject: [PATCH] Create a get_option_groups() method to return the groups, which are now built dynamically --- src/chordpro/renderers/html.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/chordpro/renderers/html.py b/src/chordpro/renderers/html.py index 873b1ce..35c2d26 100644 --- a/src/chordpro/renderers/html.py +++ b/src/chordpro/renderers/html.py @@ -345,7 +345,7 @@ HTML_OPTIONS = { 'group': 'chord' } } -OPTION_GROUPS = set([option['group'] for option in HTML_OPTIONS.values()]) +_OPTION_GROUPS = [] def get_options(group=None): @@ -356,9 +356,21 @@ def get_options(group=None): return {key: value for key, value in HTML_OPTIONS.items() if value['group'] == group} +def get_option_groups(): + if not _OPTION_GROUPS: + for option in HTML_OPTIONS.values(): + if option['group'] not in _OPTION_GROUPS: + _OPTION_GROUPS.append(option['group']) + return _OPTION_GROUPS + + def make_style(name, font=None, size=None, is_bold=None, is_centered=None, is_upper=None, indent=None): """Build a CSS style""" - styles = ['.{name} {{'.format(name=name)] + styles = [] + if name == 'default': + styles.append('html, body, * {') + else: + styles.append('.{name} {{'.format(name=name)) if font: styles.append(' font-family: \'{font}\';'.format(font=font)) if size: @@ -377,7 +389,7 @@ def make_style(name, font=None, size=None, is_bold=None, is_centered=None, is_up def generate_option_styles(options): styles = [] - for group in OPTION_GROUPS: + for group in get_option_groups(): kwargs = {} for key in STYLE_KEYS: name = '{group}_{key}'.format(group=group, key=key)