How to use the nikola.utils.slugify function in Nikola

To help you get started, we’ve selected a few Nikola examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github diegosarmentero / documentor / docdump.py View on Github external
def _add_function(self, symbol, htmlpath, docpath):
        """Add the function with the function content and style."""
        content = ''
        name_to_slugy = os.path.splitext(htmlpath)[0]
        slugy = utils.slugify(name_to_slugy.decode('utf-8'))
        function_name = templates.FUNCTION % {
            'name': "%s [at ln:%d]" % (symbol['name'], symbol['lineno']),
            'link': '%s#%s-%s' % (htmlpath, slugy, symbol['lineno'])
        }
        content += function_name + ('~' * len(function_name)) + '\n'

        content += templates.CODE % {
            'code': "def %s:" % symbol['name']
        }

        docstring = symbol['docstring']
        if docstring:
            docstring = '| %s' % docstring.replace(
                '*', '\\*').replace('`', '\\`').replace('_', '\_')
            doc = '| '.join([line + '\n'
                             for line in docstring.split('\n')]) + '\n'
github diegosarmentero / documentor / docdump.py View on Github external
def _add_classes(self, symbols, htmlpath, docpath):
        """Add the class with the class content and style."""
        content = ''
        clazzes = symbols.get('classes', [])
        name_to_slugy = os.path.splitext(htmlpath)[0]
        slugy = utils.slugify(name_to_slugy.decode('utf-8'))
        for clazz in clazzes:
            clazz_name = templates.CLASS % {
                'name': clazz,
                'link': '%s#%s-%s' % (htmlpath, slugy, clazzes[clazz]['lineno'])
            }
            content += clazz_name + ('-' * len(clazz_name)) + '\n'

            content += templates.CODE % {
                'code': "class %s:" % clazz
            }

            docstring = clazzes[clazz]['docstring']
            if docstring:
                docstring = '| %s' % docstring.replace(
                '*', '\\*').replace('`', '\\`').replace('_', '\_')
                doc = '| '.join([line + '\n'
github diegosarmentero / documentor / docdump.py View on Github external
def _add_imports(self, symbols, htmlpath):
        """Add the imports to the Module Documentation."""
        content = ''
        results = symbols['imports']
        imports = results['imports']
        fromImports = results['fromImports']

        if imports or fromImports:
            content += templates.IMPORTS + (
                        '-' * len(templates.IMPORTS)) + '\n'

        imports_key = sorted(imports.keys())
        name_to_slugy = os.path.splitext(htmlpath)[0]
        slugy = utils.slugify(name_to_slugy.decode('utf-8'))
        for imp in imports_key:
            content += templates.LIST_LINK_ITEM % {
                'name': imp,
                'link': '%s#%s-%s' % (htmlpath, slugy, imports[imp]['lineno'])
            } + '\n'

        fromImports_key = sorted(fromImports.keys())
        for imp in fromImports_key:
            content += templates.LIST_LINK_ITEM % {
                'name': fromImports[imp]['module'] + ".%s" % imp,
                'link': '%s#%s' % (htmlpath, fromImports[imp]['lineno'])
            } + '\n'

        return content
github diegosarmentero / documentor / docdump.py View on Github external
def _add_global_attributes(self, symbols, htmlpath):
        """Add the global attributes to the Module Documentation."""
        content = ''
        attrs = symbols.get('attributes')
        if attrs:
            content += templates.GLOBAL_ATTRIBUTES + (
                        '-' * len(templates.GLOBAL_ATTRIBUTES)) + '\n'

            attrs_key = sorted(attrs.keys())
            name_to_slugy = os.path.splitext(htmlpath)[0]
            slugy = utils.slugify(name_to_slugy.decode('utf-8'))
            for attr in attrs_key:
                content += templates.LIST_LINK_ITEM % {
                    'name': "%s [at ln:%d]" % (attr, attrs[attr]),
                    'link': '%s#%s-%s' % (htmlpath, slugy, attrs[attr])
                } + '\n'

            content += '\n----\n'

        return content
github diegosarmentero / documentor / docdump.py View on Github external
'year': str(datetime.date.today().year),
            'projectname': self.projectname
        }

        path = os.path.join(self.files_folder, 'documentor_modules.html')
        with open(path, 'w') as f:
            f.write(html)

        # Classes
        html = templates.HTML_FILES_HEADER % {
            'projectname': self.projectname,
            'type': 'Classes'
        }
        for cla in sorted(self.__classes, key=lambda x: x[0]):
            name_to_slugy = os.path.splitext(cla[1])[0]
            slugy = utils.slugify(name_to_slugy.decode('utf-8'))
            html += templates.HTML_FILES_BODY % {
                'link': "%s#%s-%d" % (cla[1], slugy, cla[2]),
                'name': cla[0]
            }
        html += templates.HTML_FILES_FOOTER % {
            'year': str(datetime.date.today().year),
            'projectname': self.projectname
        }

        path = os.path.join(self.files_folder, 'documentor_classes.html')
        with open(path, 'w') as f:
            f.write(html)

        # Functions
        html = templates.HTML_FILES_HEADER % {
            'projectname': self.projectname,