How to use the mkdocs.utils.warning_filter 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 / commands / build.py View on Github external
files.copy_static_files(dirty=dirty)

    for template in config['theme'].static_templates:
        _build_theme_template(template, env, files, config, nav)

    for template in config['extra_templates']:
        _build_extra_template(template, files, config, nav)

    log.debug("Building markdown pages.")
    for file in files.documentation_pages():
        _build_page(file.page, config, files, nav, env, dirty)

    # Run `post_build` plugin events.
    config['plugins'].run_event('post_build', config=config)

    if config['strict'] and utils.warning_filter.count:
        raise SystemExit('\nExited with {} warnings in strict mode.'.format(utils.warning_filter.count))

    log.info('Documentation built in %.2f seconds', time() - start)
github mkdocs / mkdocs / mkdocs / commands / build.py View on Github external
class DuplicateFilter:
    ''' Avoid logging duplicate messages. '''
    def __init__(self):
        self.msgs = set()

    def filter(self, record):
        rv = record.msg not in self.msgs
        self.msgs.add(record.msg)
        return rv


log = logging.getLogger(__name__)
log.addFilter(DuplicateFilter())
log.addFilter(utils.warning_filter)


def get_context(nav, files, config, page=None, base_url=''):
    """
    Return the template context for a given page or template.
    """

    if page is not None:
        base_url = utils.get_relative_url('.', page.url)

    extra_javascript = utils.create_media_urls(config['extra_javascript'], page, base_url)

    extra_css = utils.create_media_urls(config['extra_css'], page, base_url)

    # Support SOURCE_DATE_EPOCH environment variable for "reproducible" builds.
    # See https://reproducible-builds.org/specs/source-date-epoch/
github rosscdh / mkdocs-markdownextradata-plugin / markdownextradata / plugin.py View on Github external
import os
import sys
import json
import yaml
import mkdocs
import logging
from mkdocs.plugins import BasePlugin
from mkdocs.utils import warning_filter

from jinja2 import Template
from pathlib import Path
from itertools import chain

log = logging.getLogger(__name__)
log.addFilter(warning_filter)

CONFIG_KEYS = ["site_name", "site_author", "site_url", "repo_url", "repo_name"]

if sys.version_info[0] >= 3:
    str_type = str
else:
    str_type = mkdocs.utils.string_types


class MarkdownExtraDataPlugin(BasePlugin):
    """
    Inject certain config variables into the markdown
    """

    config_scheme = (
        ("data", mkdocs.config.config_options.Type(str_type, default=None)),
github spotify / mkdocs-monorepo-plugin / mkdocs_monorepo_plugin / merger.py View on Github external
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from tempfile import TemporaryDirectory
from distutils.dir_util import copy_tree

import logging
import os
from os.path import join
from pathlib import Path

from mkdocs.utils import warning_filter

log = logging.getLogger(__name__)
log.addFilter(warning_filter)

# This collects the multiple docs/ folders and merges them together.


class Merger:
    def __init__(self, config):
        self.config = config
        self.root_docs_dir = config['docs_dir']
        self.docs_dirs = list()
        self.append('', self.root_docs_dir)
        self.files_source_dir = dict()

    def append(self, alias, docs_dir):
        self.docs_dirs.append([alias, docs_dir])

    def merge(self):
github mkdocs / mkdocs / mkdocs / theme.py View on Github external
import os
import jinja2
import logging

from mkdocs import utils
from mkdocs.utils import filters
from mkdocs.config.base import ValidationError

log = logging.getLogger(__name__)
log.addFilter(utils.warning_filter)


class Theme:
    """
    A Theme object.

    Keywords:

        name: The name of the theme as defined by its entrypoint.

        custom_dir: User defined directory for custom templates.

        static_templates: A list of templates to render as static pages.

    All other keywords are passed as-is and made available as a key/value mapping.
github mkdocs / mkdocs / mkdocs / structure / files.py View on Github external
import fnmatch
import os
import logging
from functools import cmp_to_key
from urllib.parse import quote as urlquote

from mkdocs import utils


log = logging.getLogger(__name__)
log.addFilter(utils.warning_filter)


class Files:
    """ A collection of File objects. """
    def __init__(self, files):
        self._files = files
        self.src_paths = {file.src_path: file for file in files}

    def __iter__(self):
        return iter(self._files)

    def __len__(self):
        return len(self._files)

    def __contains__(self, path):
        return path in self.src_paths
github mkdocs / mkdocs / mkdocs / structure / nav.py View on Github external
import logging
from urllib.parse import urlparse

from mkdocs.structure.pages import Page
from mkdocs.utils import nest_paths, warning_filter

log = logging.getLogger(__name__)
log.addFilter(warning_filter)


class Navigation:
    def __init__(self, items, pages):
        self.items = items  # Nested List with full navigation of Sections, Pages, and Links.
        self.pages = pages  # Flat List of subset of Pages in nav, in order.

        self.homepage = None
        for page in pages:
            if page.is_homepage:
                self.homepage = page
                break

    def __repr__(self):
        return '\n'.join([item._indent_print() for item in self])
github mkdocs / mkdocs / mkdocs / structure / pages.py View on Github external
import os
import datetime
import logging
from urllib.parse import urlparse, urlunparse, urljoin
from urllib.parse import unquote as urlunquote

import markdown
from markdown.extensions import Extension
from markdown.treeprocessors import Treeprocessor
from markdown.util import AMP_SUBSTITUTE

from mkdocs.structure.toc import get_toc
from mkdocs.utils import meta, get_markdown_title, warning_filter

log = logging.getLogger(__name__)
log.addFilter(warning_filter)


class Page:
    def __init__(self, title, file, config):
        file.page = self
        self.file = file
        self.title = title

        # Navigation attributes
        self.parent = None
        self.children = None
        self.previous_page = None
        self.next_page = None
        self.active = False

        self.is_section = False
github spotify / mkdocs-monorepo-plugin / mkdocs_monorepo_plugin / parser.py View on Github external
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import logging
import os
import copy
import re

from mkdocs.utils import yaml_load, warning_filter

log = logging.getLogger(__name__)
log.addFilter(warning_filter)

INCLUDE_STATEMENT = "!include "


class Parser:
    def __init__(self, config):
        self.initialNav = config['nav']
        self.config = config

    def __loadAliasesAndResolvedPaths(self, nav=None):
        if nav is None:
            nav = copy.deepcopy(self.initialNav)

        paths = []

        for index, item in enumerate(nav):