diff --git a/Dockerfile b/Dockerfile index 3447a62521bb87e5ce50486d3c308fdad5daa898..7e9cf596da2f966c695623996928daae813e7b8f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,5 +5,7 @@ COPY requirements.txt . RUN pip install -r requirements.txt COPY mkdocs_configuration /usr/local/bin/ RUN chmod 755 /usr/local/bin/mkdocs_configuration +COPY mkdocs_material_nested_lists_rendering_fix /usr/local/bin/ +RUN chmod 755 /usr/local/bin/mkdocs_material_nested_lists_rendering_fix COPY mkdocs_configuration_lib.py /usr/local/bin/ COPY mkdocs_configuration_tests.py /usr/local/bin/ diff --git a/mkdocs_material_nested_lists_rendering_fix b/mkdocs_material_nested_lists_rendering_fix new file mode 100755 index 0000000000000000000000000000000000000000..95cc984dfc98f7320cd15537b8d8486118690cf3 --- /dev/null +++ b/mkdocs_material_nested_lists_rendering_fix @@ -0,0 +1,88 @@ +#!/usr/local/bin/python +# -*- coding: utf-8 -*- +""" +MkDocs Material theme fix for nested lists rendering. +<https://github.com/squidfunk/mkdocs-material/issues/508> +""" + +import click +import os +import sys + +import mkdocs_configuration_lib as lib + + +@click.command() +def main( +): + """MkDocs Material theme fix for nested lists rendering.""" + + # Read the existing configuration from `mkdocs.yml`. + configuration = lib.read_configuration() + + # If no configuration was found do nothing and exit successfully + # and silently. + if not configuration: + sys.exit(0) + + # Make sure the configuration includes the `theme`, otherise exit + # successfully and silently. + theme = configuration.get('theme') + if theme is None: + sys.exit(0) + + # Make sure the theme configuration includes the `name` and the name is + # `material`, otherise exit successfully and silently. + theme_name = theme.get('name') + if theme_name is None or theme_name != 'material': + sys.exit(0) + + # Create the `stylesheets` directory in the documentation directory if it + # doesn't already exist. + try: + os.mkdir(os.path.join(lib.DOCUMENTATION_DIRECTORY, 'stylesheets')) + except FileExistsError: + # Since the `stylesheets` directory already existed, check if a + # `material_nested_lists_rendering.css` file also existed already. + # If yes, exit successfully and silently. + if os.path.isfile(os.path.join( + lib.DOCUMENTATION_DIRECTORY, + 'stylesheets', + 'material_nested_lists_rendering.css' + )): + sys.exit(0) + + # Create the appropriate stylesheet file. + with open(os.path.join( + lib.DOCUMENTATION_DIRECTORY, + 'stylesheets', + 'material_nested_lists_rendering.css' + ), 'w') as file_object: + file_object.write('\n'.join([ + 'article ul ul {', + ' list-style-type: circle !important;', + '}', + '', + 'article ul ul ul {', + ' list-style-type: square !important;', + '}', + ])) + + # Get the `extra_css` from the configuration. If it's not there get it as + # an empty list. + extra_css = configuration.get('extra_css', []) + # Append the recently created file `material_nested_lists_rendering.css` + # to the `extra_css` list. + extra_css.append(os.path.join( + 'stylesheets', + 'material_nested_lists_rendering.css' + )) + # Update the configuration with the updated `extra_css` list. + configuration.update({'extra_css': extra_css}) + + # Write the updated configuration to `mkdocs.yml`. + lib.write_configuration(configuration) + + +if __name__ == '__main__': + main()