How to use the mkdocs.utils.is_markdown_file function in mkdocs

To help you get started, we’ve selected a few mkdocs 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 mkdocs / mkdocs / mkdocs / config.py View on Github external
raise ConfigurationError(
            "The 'site_dir' can't be within the 'docs_dir'.")

    # If not specified, then the 'pages' config simply includes all
    # markdown files in the docs dir, without generating any header items
    # for them.
    pages = []
    extra_css = []
    extra_javascript = []
    extra_templates = []
    for (dirpath, _, filenames) in os.walk(config['docs_dir']):
        for filename in sorted(filenames):
            fullpath = os.path.join(dirpath, filename)
            relpath = os.path.normpath(os.path.relpath(fullpath, config['docs_dir']))

            if utils.is_markdown_file(filename):
                # index pages should always be the first listed page.
                if os.path.splitext(relpath)[0] == 'index':
                    pages.insert(0, relpath)
                else:
                    pages.append(relpath)
            elif utils.is_css_file(filename):
                extra_css.append(relpath)
            elif utils.is_javascript_file(filename):
                extra_javascript.append(relpath)
            elif utils.is_template_file(filename):
                extra_templates.append(filename)

    if config['pages'] is None:
        config['pages'] = pages
    else:
        """
github mkdocs / mkdocs / mkdocs / relative_path_ext.py View on Github external
def path_to_url(url, nav, strict):

    scheme, netloc, path, params, query, fragment = (
        utils.urlparse(url))

    if scheme or netloc or not path or AMP_SUBSTITUTE in url:
        # Ignore URLs unless they are a relative link to a markdown file.
        # AMP_SUBSTITUTE is used internally by Markdown only for email,which is
        # not a relative link. As urlparse errors on them, skip explicitly
        return url

    if nav and not utils.is_markdown_file(path):
        path = utils.create_relative_media_url(nav, path)
    elif nav:
        # If the site navigation has been provided, then validate
        # the internal hyperlink, making sure the target actually exists.
        target_file = nav.file_context.make_absolute(path)

        if target_file.startswith(os.path.sep):
            target_file = target_file[1:]

        if target_file not in nav.source_files:
            source_file = nav.file_context.current_file
            msg = (
                'The page "%s" contained a hyperlink to "%s" which '
                'is not listed in the "pages" configuration.'
            ) % (source_file, target_file)
github timothycrosley / portray / portray / render.py View on Github external
def documentation_in_temp_folder(config: dict):
    """Build documentation within a temp folder, returning that folder name before it is deleted."""
    if config["append_directory_to_python_path"] and not config["directory"] in sys.path:
        sys.path.append(config["directory"])

    with tempfile.TemporaryDirectory() as input_dir:
        input_dir = os.path.join(input_dir, "input")
        os.mkdir(input_dir)
        with tempfile.TemporaryDirectory() as temp_output_dir:

            with yaspin(
                text="Copying source documentation to temporary compilation directory"
            ) as spinner:
                for root_file in os.listdir(config["directory"]):
                    root_file_absolute = os.path.join(config["directory"], root_file)
                    if os.path.isfile(root_file_absolute) and is_markdown_file(root_file_absolute):
                        shutil.copyfile(root_file_absolute, os.path.join(input_dir, root_file))

                for source_directory in [config["docs_dir"]] + config["extra_dirs"]:
                    directory_absolute = os.path.join(config["directory"], source_directory)
                    if os.path.isdir(directory_absolute):
                        shutil.copytree(
                            directory_absolute, os.path.join(input_dir, source_directory)
                        )

                spinner.ok("Done")

            if "docs_dir" not in config["mkdocs"]:
                config["mkdocs"]["docs_dir"] = input_dir
            if "site_dir" not in config["mkdocs"]:
                config["mkdocs"]["site_dir"] = temp_output_dir
            if "nav" not in config["mkdocs"]:
github mkdocs / mkdocs / mkdocs / config / config_options.py View on Github external
def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.file_match = utils.is_markdown_file